in reply to Macros in a RecDescent grammar

You can think of a macro as a procedure in which the body of the procedure is substituted whenever invoked. Thus invoking macros entails changing the source code as it is being parsed. Expanding macros at the same time you parse code is a tricky proposition; look at Tex or Tcl to see some of the issues involved. Generally it is easier to make your compiler two-pass, one for macro expansion and one for parsing the resulting code.

-Mark

Replies are listed 'Best First'.
Re: Re: Macros in a RecDescent grammar
by mush4brains (Acolyte) on Jun 21, 2002 at 21:12 UTC
    Thanks, Mark.
    I suspect two passes is somehow necessary, one way or the other, but I thought maybe I was missing one of the deeper features of the amazing P::RD.
    - Jim