[antlr-interest] I can't understand lexer behaivour. Lexers are LL(*)?

Joan Pujol joanpujol at gmail.com
Mon Oct 12 14:19:59 PDT 2009


Hi,

I've a problem with the lexer. Given that grammar:


TEXT	:	(~'$' | '$' ~'{')+;
OTHER	:	 .;
program	:	(TEXT|OTHER)+;

If I try with input     'Hola ${ ' it does'nt works. And I can't understand why.
If I look at generated code of rule TEXT it doesn't use a lookahead of
 2. In fact when it finds a '$' it enters in the subrule '$' ~'{
without using LA(2) to see that the next caracter is a { and that then
it can't enter the subrule.
In fact as it only compares LA(1)='$' it enters the subrule but then
when it founds the{ it fails with a lexical error.

And I can't understand why the lexer isn't capable to generate code to
compare with LA(1)='$' and LA(2)!='{' to enter the subrule.

Is that the correct behaivour? Why de lexer can aproximate the K=2?
Someone can explain why?

A lot of thanks in advance,




-- 
Joan Jesús Pujol Espinar
http://www.joanpujol.cat
http://lujop.deviantart.com


More information about the antlr-interest mailing list