[antlr-interest] unary Operators

Terence Parr parrt at cs.usfca.edu
Wed Nov 16 07:55:40 PST 2005


On Nov 16, 2005, at 7:44 AM, Henry Butowsky wrote:

> Hi Guys,
>    Im using a C like grammer and am having trouble getting unary  
> operators to work
>
> I have in the parser
>
> 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 should make the ref to primary after the ops to unary :)  It  
would use recursion to loop and get the precedence right at the same  
time I think. :)

Ter


More information about the antlr-interest mailing list