[antlr-interest] ANTLR for a compiler

Monty Zukowski monty at codetransform.com
Fri Nov 5 09:38:56 PST 2004


On Nov 5, 2004, at 8:21 AM, Bryan Ewbank wrote:

>
> That's the plan, and is also the pain.  Each of those tree-parsers 
> requires
> a complete set of rules to describe the tree being passed from the 
> previous
> phase - the content of the tree changes as it flows down the pipeline, 
> so
> there isn't "just one tree type".
>
> For example, the tree before normalization might have "(= x (+ x 1))" 
> as
> well as "(++ x)",
> but after normalization there will be no "++" nodes.   Therefore, 
> passes
> after that
> normalization should report "++" nodes as errors.  Similarly, one pass 
> will
> remove all
> nodes of a certain type by normalizing the children - so passes after 
> that
> one will not
> see the same tree node types as those before it.
>
> Ah well, I'll read through the responses and see what the wisdom of the
> informed can tell me.  Sorry to share my bad day :-(
>

Well, you can still cram all the rules into one tree parser.  Just 
because you don't need the #(++ x) rule doesn't mean it can't be there. 
  When you normalize your children put 'em in a new node type and hence 
have a new tree rule.

For instance my AREV to VB parser had a tree grammar that was the 
combination of AREV and VB.  I had some rules like

expr: arevExpr | vbExpr;
stmt: arevStmt | vbStmt;

Then once I was totally VB I could override expr thusly

expr: vbExpr;

That may be a bit simplistic for your compiler, but hopefully you get 
the idea.

A simple way to error check might be to have a visitor that runs 
through the tree to detect unwanted nodes, so that after pass X you 
would run it and make sure you no longer have "++" nodes anywhere in 
your tree.

Monty

ANTLR & Java Consultant -- http://www.codetransform.com
ANSI C/GCC transformation toolkit -- 
http://www.codetransform.com/gcc.html
Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html




 
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