[plt-scheme] Grammar abstractions in parser-tools collection?

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Fri Apr 21 10:05:29 EDT 2006

Is it possible to write grammar abstractions for use with the
parser-tools collection?

I'm writing a parser for a grammar that has several productions of the

    Xs ::= X Xs
         | <empty>

for various values of X.  Conveniently enough, the actions associated
with these productions are the same.  I'd like to try to abstract this
out, but I don't know how to do that.

I tried

  (define-syntax seq-of-production
    (syntax-rules ()
      [(_ <seq> <elt>)
       (<seq> [(<elt> <seq>) (sequence-cons $1 $2)]
              [() (sequence-empty)])]))

and then

    (seq-of-production <fdefns> <fdefn>)
    (seq-of-production <mdefns> <mdefn>)
    (seq-of-production <sdefns> <sdefn>)
    (seq-of-production <cdefns> <cdefn>)
    (<fdefn> ...)
    (<mdefn> ...)
    (<sdefn> ...)
    (<cdefn> ...)

but that doesn't work; the parser generator complains that I'm defining
the non-terminal "seq-of-production" multiple times.

So it looks like the grammar rules in a parser are not in a macro
expansion context.

Is there another way to go about this, or am I out of luck?



Posted on the users mailing list.