[antlr-interest] A little trouble with parsing unary operators

Andy Hull andyh at sunrunhome.com
Mon May 17 17:43:33 PDT 2010


I've been looking at this for several hours... and then I am grated inspiration just after I send the email to the group...

unary
:
(NOT | NEGATE)^ unary
|
term
;



On May 17, 2010, at 5:25 PM, Andy Hull wrote:

Hi everyone,

I really need my parser to emit something like this for unary values:

 unary: ^(NOT unary) | ^(NEGATE unary);

because I need to deal with recursive unary constructs like !!17

but I'm having difficulty with the parser. Currently I have a parser rule like:

unary:   ((NOT | NEGATE)^)? term;

but clearly this won't handled nested unary operators. Given that for the input:

!!17

I need to produce

^(NOT ^(NOT INTEGER))

Can someone point me in the correct direction?

Thanks in advance!

Andy

--


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--
Andy Hull | Senior Software Engineer
SunRun Inc.<http://www.sunrunhome.com/>
direct  415.684.9851

Review SunRun on Yelp<http://www.yelp.com/biz/sunrun-san-francisco>
click on the link above and then on ‘write a review’



More information about the antlr-interest mailing list