Quantcast

A little trouble with parsing unary operators

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

A little trouble with parsing unary operators

Andy Hull-2
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: A little trouble with parsing unary operators

Andy Hull-2
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’


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