On 12/17/12, David A. Wheeler <dwhee...@dwheeler.com> wrote:
> Alan Manuel Gloria:
>> With all these complications in the formulation, I'm wondering if it
>> would be useful to also define (not necessarily as part of the SRFI)
>> some sort of formulation for translation of our extensions over BNF
>> into some kind of code.
>
> I think implementation hints belong in the SRFI, since they can help get it
> implemented, as long as it's clear that they are hints on how they can be
> implemented and not mandates.  I've already used some text from
> spec-almkglor.txt in the SRFI BNF that hints about how to implement the
> "head" production.
>
> Also, we'll include an implementation in the SRFI anyway.

What I mean is, a general "how to transform this extended BNF to
actual code".  I'd be more confident of the extensions if we can
indeed write some code that does this correctly, and can transform our
BNF into an actual parser.  Basically, not a hint, rather a formal
specifications.  I worry that we're starting to talk complete nonsense
parsing-wise, and I'd be more confident if we can somehow make an
automated transformation from the extended BNF to code.

Basically - I want a program as proof that our extended BNF can work.

Note that "preventative productions" is *fine*.  I think.  Basically
those can be implemented using (say) Parsec's "notFollwedBy", so there
is some transformation from preventative productions to actual working
code.  Something like:

sample ::=! bar nitz
sample ::=! foo quux
sample ::= nitz nitz
sample ::= foo foo

..can be implemented (?) as Parsec:

!sample = do
!  notFollowedBy ((do try bar; nitz) <|> (do try foo; quux))
!  (try (do nitz; nitz) <|> try (do foo; foo))

.. so at least for preventative productions I'm sure of our formal
specifications.  However, for INDENT, I'm not so certain.  You
mentioned passing in the current indent and passing it out, so I
suppose you might use a Parsec transformer on top of a State monad (or
a State transformer on top of the Parsec monad, I confuse them
sometimes), with the state being the started indentation level.  Still
- how does the "started" indentation get updated?  Currently it gets
updated only during the sweet-expression processing.

So extending that....

I *think* that INDENT/DEDENT/SAME can be implemented using some sort
of state transformer on top of Parsec: type (StateT String (Parsec
Char ()) SchemeDatum).

the n-expr production is NOT of this type, but rather just (Parsec
Char () SchemeDatum).  We use the standard monad-transformer "lift"
operator to lift the n-expr production into the extended t-expr parser
type.

Every production can only have at most one of INDENT DEDENT SAME.

the SAME "token" is actually the following production:

!tSAME = do
!  starting <- get
!  cur <- lift $ try $ do -- needs to be done in actual Parsec monad.
!    current <- indentation
!    if current == starting
!      then return current
!      else fail "not SAME indentation level" -- or a better error message
!  put cur -- replace new indent
!indentation = many $ (char ' ' <|> char '\t' <|> char '!')

With similar code for INDENT and DEDENT.

... or I dunno.  I'll try to see if I can hack something together in
Haskell.  If we can get some sort of consistent transformation from
our BNF into Haskell Parsec code, I'd be a lot more sure of the
"guard" concept.

Sincerely,
AmkG

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Readable-discuss mailing list
Readable-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/readable-discuss

Reply via email to