[antlr-interest] Building a tree grammar expression to recognize arithmetic expressions

Junkman j at junkwallah.org
Sat Aug 7 11:19:31 PDT 2010


Hi Alex,

Alex Storkey wrote:
> Hi, it's my first time posting in a mailing list like this so go easy on me
> if I'm breaking some etiquette or anything :)
> 
> I'm trying to construct an expression in my tree grammar to recognize an AST
> of simple mathematical expressions like 1+(-(a-b)) in tree format of (+ 1 (-
> (- a b))) that is generated by my parser grammar.
> 
> I've tried a couple of different approaches and I can't figure out where I'm
> going wrong. Could someone explain what's wrong with the following two
> expressions:
> expression
>     :    (MINUS^)? term;

If I understand you correctly, you are asking about writing tree parser
grammar.

Does Antlr even compile the grammar (i.e., generate a tree parser) with
the above rule?  I think the rule must be of the form of rewrite rules.

J




More information about the antlr-interest mailing list