Compiling generated lexer class with errors
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Miguel_Pinheiro
Posted On:   Monday, February 18, 2002 02:09 AM

When I tried to compile the generated Lexer part of the Java parser example boundled with AntLr I get errors about NUM_FLOAT. Why is this happening? I pick the java.g example file boundled with the Antlr. I cut the Parser definition and I saved as a new name (j.g) with just the Lexer part definition. Then I used the AntLr Tool in the j.g file and it generated JavaLexer.java and JavaTokenTypes.java. I tried to compile that and I get the following errors: JavaLexer.java:1433: cannot resolve symbol symbol : variable DOT location: class JavaLexer _ttype = DOT; ^ JavaLexer.java:1466: cannot resolve symbol symbol : variable NUM_FLOAT location: class JavaLexer    More>>

When I tried to compile the generated Lexer part of the Java parser example boundled with AntLr I get errors about NUM_FLOAT. Why is this happening?



I pick the java.g example file boundled with the Antlr. I cut the Parser definition and I saved as a new name (j.g) with just the Lexer part definition. Then I used the AntLr Tool in the j.g file and it generated JavaLexer.java and JavaTokenTypes.java. I tried to compile that and I get the following errors:

JavaLexer.java:1433: cannot resolve symbol
symbol : variable DOT
location: class JavaLexer
_ttype = DOT;
^
JavaLexer.java:1466: cannot resolve symbol
symbol : variable NUM_FLOAT
location: class JavaLexer
_ttype = NUM_FLOAT;

JavaLexer.java:1657: cannot resolve symbol
symbol : variable NUM_FLOAT
location: class JavaLexer
_ttype = NUM_FLOAT;

Do you know why?
If I try the samething with java.g example it works just fine...
Yhank you,

Miguelv

   <<Less

Re: Compiling generated lexer class with errors

Posted By:   Monty_Zukowski  
Posted On:   Tuesday, February 19, 2002 08:06 AM

Tokens used in the parser are implicitly defined for the lexer. Take away the parser and you loose those definitions. The solution is to add a ""tokens {}"" section to your lexer that defines those tokens. See http://www.antlr.org/doc/metalang.html#TokensSection. Then you will be fine.
About | Sitemap | Contact