[antlr-interest] unary Operators

John B. Brodie jbb at acm.org
Wed Nov 16 07:35:18 PST 2005


Sir :-

You asked:
>unary_exp
>	:primary_exp
>	| (LNOT^ | MINUS^ |PLUS^) primary_exp
>          ;
>	
>It works  OK with a single unary operator eg   !10 or -2.4
>But put them together and nogo e.g !!20 or -!0

You could try the following but I don't think you can keep the ^ tree
operator, you'll need to figure out some other way to build the tree:

unary_exp : ( LNOT | MINUS | PLUS )* primary_exp ;

or perhaps just use recursion (i think this produces the tree you
might intuitively expect):

unary_exp
	:primary_exp
	| (LNOT^ | MINUS^ |PLUS^) unary_exp
          ;

My tree building skills are rather weak, sorry...

Hope this helps.
   -jbb


More information about the antlr-interest mailing list