Jennifer Cooper wrote:
Hi everyone!
I've just started using antlr and come upon a problem. T try to make lexer recognize two different operators: OP and OP NOT. I want to treat both of them as binary operators and not to treat NOT as unary operator.  My current solution is:

op_expr
    :    expr (OP^ not_expr)*
    ;
not_expr
    :    expr
    |       NOT^ expr 
    ;

but this one obviously doesn't treat NOT as part of the binary OP NOT operator.

Any clues?
You have not really explained anything about what you want to achieve, but at a guess you want this:


tokens {
 OP_NOT;
}

op_expr
    : expr (op_or_not^ expr)*
    ;

op_or_not
    : OP
       (  NOT -> OP_NOT[OP]
         |    -> OP
       )
    ;



However, it is just as easy to deal with the optional presence of NOT I would think, unless there is some definite difference between operators
with trailing NOT. Hence perhaps you are looking at the problem incorrectly? I don't know of any language where what you are ding makes sense.

Perhaps your operators are not specified correctly in the lexer?

OP : '+';
OP_NOT: '+!' ;

Hope that helps but you really need to supply comprehensive information for anyone to give you a definitive answer on this one.

Jim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

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

Reply via email to