lex/yacc: Macro expansion

janovetz@eehpx3.cen.uiuc.edu (Jacob W Janovetz)
Tue, 26 Sep 1995 22:58:57 GMT

          From comp.compilers

Related articles
lex/yacc: Macro expansion janovetz@eehpx3.cen.uiuc.edu (1995-09-26)
| List of all articles for this month |

Newsgroups: comp.compilers
From: janovetz@eehpx3.cen.uiuc.edu (Jacob W Janovetz)
Keywords: lex, yacc, question, macros
Organization: University of Illinois at Urbana
Date: Tue, 26 Sep 1995 22:58:57 GMT

Hello,


      Can someone give me a recommendation as to how to implement good
macro expansion in lex/yacc? I'm writing an assembler and would like
to implement compile-time variables and equates, but I'm not sure of
an acceptable way to do things like substitutions. The O'Reilley
book doesn't go into this much (that I can see).


      Jake


--


janovetz@coewl.cen.uiuc.edu
      University of Illinois
[It's true, we didn't talk about that at all. There's two approaches. Either
you can do lexical macros, in which you stuff the macro text into the
lexer, interpolating arguments when you see a code in the text that calls
for one, or you can do parser macros, in which you splice a piece of parse
tree into the tree the parser is creating, replacing dummy argument nodes in
the parse tree with the trees for the actual arguments. Most assemblers
don't even create a parse tree, so I'd take the lexical route. -John]




--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.