Hi, I have two rules as follows:
firstOrderVariable returns [FirstOrderVariable result]
: IDENTIFIER { $result = getFirstOrderVariable($IDENTIFIER.text); }
;
secondOrderVariable returns [SecondOrderVariable result]
: IDENTIFIER { $result = getSecondOrderVariable($IDENTIFIER.text); }
;
with
IDENTIFIER
: ( ~( CLOSE | OPEN | WS ) )+
;
OPEN : '(' ;
CLOSE : ')' ;
fragment WS : ( ' ' | '\t' ) ;
Most of the times, it is no problem they are identical, since the rest
of the surrounding rule will do the disambiguation. Unfortunately, in
some cases, it won’t. I would like to separate them in that first-order
variables should start with a lowercase letter, but second-order
variables with an uppercase letter. So I’d like to insert some semantic
predicate which checks the case of the first letter and fails as
appropriate. Is this possible, and if yes, how?
If it isn’t I can make sure the surrounding rules do the disambiguation,
but this solution would be nicer.
Originally, I had a lexer rule FIRST_ORDER_VARIABLE: LOWER ( LOWER |
UPPER )* and similar for SECOND_ORDER_VARIABLE, but that didn’t work
properly since that way it was not possible to match other kind of stuff
with the IDENTIFIER rule. (It would have been lexed as FOV, but an ID
was expected, so the lexer would barf. It might be that I interpret the
problem incorrectly, but at least now it works.) Also just allowing
letters is too simple, I want to allow (almost) every possible Unicode
token.
TIA, H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
signature.asc
Description: OpenPGP digital signature
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address
