[antlr-interest] Whats wrong with this?

John B. Brodie jbb at acm.org
Wed Jun 3 16:46:21 PDT 2009


Greetings!
On Wednesday 03 June 2009 06:14:26 pm Mats Ekberg wrote:
> I cant figure out why this grammar dont work (I have left out some
> not relevant stuff).
> This expression works:    [ LOOKUP( A1234567890, 9TN ) ] 93
> This dont:    [ LOOKUP( A1234567890, ATN ) ] 93
> Why?

Your lexer rules for TABLEID and UNIT overlap so I believe that the
lexer considers the "ATN" string in the second, non-working,
sentence to be a 3 letter TABLEID rather than a UNIT.

And of course your parser gets confused by seeing another TABLEID
after the first on in a LOOKUP construct.


> TABLEID	:	UCLETTER (ALPHANUM)* ;

> fragment DIGIT:		'0'..'9';
> fragment UCLETTER:	'A'..'Z';
> fragment LCLETTER:	'a'..'z';
> fragment USCORE:	'_';
> fragment CHAR:	UCLETTER | LCLETTER | DIGIT;
> fragment ALPHANUM:	DIGIT | UCLETTER;
> UNIT	: ALPHANUM ALPHANUM ALPHANUM


Remember that you lexer operates independently from the parser.

Your lexer has no knowledge of what your parser is trying to recognize.

maybe you could remove your lexer rule for UNIT, using TABLEID in
your parser instead and then add a semantic error checking actions
to ensure that those TABLEIDs (which are supposed to be UNITs)
are exactly 3 characters long.

Hope this helps.
------
  -jbb



More information about the antlr-interest mailing list