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

Andy Hull andyh at sunrunhome.com
Mon May 17 17:25:01 PDT 2010


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

--



More information about the antlr-interest mailing list