[antlr-interest] ANTLR for a compiler
Terence Parr
parrt at cs.usfca.edu
Thu Nov 4 13:23:09 PST 2004
Hi Bryan,
You want JBurg or something similar: a tree walker that is explicitly
designed to generate code. You can have ambiguous patterns with
associated costs so that x+1 can be matched either as add one or
increment. here is a lab from my grad course where we generate machine
code from an AST:
http://www.cs.usfca.edu/~parrt/course/652/labs/jburg.html
For example, I say:
JBurg descriptions looks like ANTLR tree grammars except that the
parentheses are in a different spot (prefix vs postfix notation):
reg : #(ADD r1:reg r2:reg) {...emit instruction(s)...}
and burg and friends use
reg : ADD(reg r1, reg r2) : 1 {...emit instruction(s)...}
where : 1 implies cost 1. Costs usually are just relative numbers but
can mean "how many instructions were required?"
ANTLR tree walkers are not designed specifically for instruction
selection; rather the opposite. :) Building actual compilers has never
been my focus (unless you count bytecode compilers, which are much
easier).
Terence
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list