[antlr-interest] Looking for reference to how ANTLR performs ... special example will not work???

Sylvain, Gregory [USA] sylvain_gregory at bah.com
Fri Sep 11 07:20:05 PDT 2009


Great replies thank you, I was assumed the longest-match wins rules applied, but I wasn't sure - thanks.

Here is an example of the sort of problems I am trying to figure out.


r            : 'BEGIN/' f1=(number 'T') f2=field EOT EOL
number : INT | FLOAT ;
field      : ALPHANUM_CHAR+;

ALPHANUM_CHAR : ( ALPHA_CHAR  | DIGIT | SPECIAL_CHAR | ' ')+;
INT : DIGIT+ ;
FLOAT : DIGIT+ '.' DIGIT+;
fragment DIGIT : '0' .. '9' ;
fragment ALPHA_CHAR : 'A' .. 'Z' ;
SPECIAL_CHAR: ( ',' | '(' | ')' | '\\' );  // more special chars can be added here....
EOT : '//'
EOL : '\n';


The following will work:

BEGIN/1231T/P//

However, the following will NOT :

BEGIN/1231T/T//

some lexer tests lead me to believe this should work:

'T' is a ALPHA_CHAR
'T' is also an ALPHANUM_CHAR

HOWEVER,
'T' is NOT a field???

Again, I can fix this by making f1 match a field instead of a number followed by a T.  But I would like to understand what is going on here...

Basically, if a field is supposed to have a certain suffix, I would like to put that in the grammar.  Of course, I still want to be able to accept those suffixes as a part of a more general field as well.


Thanks in advance.
Greg

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090911/b53a7c8f/attachment.html 


More information about the antlr-interest mailing list