I am creating a DSL using antlr. Lexer and Parser are written in one grammar file(say layout.g). Tree grammar is written in another grammar file (say layoutTree.g). Now Tree parser is not properly parsing. I printed the AST output from parser, and its correct. I walked through the generated tree parser code, and found that token value declarations assign different values in tree parser and parser.Below is the sample output from parser and tree parser.
Parser output
public static final int ARRAY_MEMBER_TOKEN=4;
public static final int ARRAY_TOKEN=5;
public static final int DECLARATION_TOKEN=6;
Tree Parser Output
public static final int EOF=-1;
public static final int DECLARATION_TOKEN=4;
public static final int IDENTIFIER=5;
As you can see DECLARATION_TOKEN has different value in parser output and tree parser output. Because of this tree parser is not working as expected.How can I correct this problem?
Is it a problem with generated token file(say layout.token)? This file is empty in my project.How can I generate this file?
.tokens
file is generated automatically while generating your lexer/parser(s). The fact that your.tokens
file is empty, is not good. How are you generating your lexer/parser(s)? (command line, IDE, ANTLRWorks, other?) – Bart Kiersjava -cp antlr-3.2.jar org.antlr.Tool layout.g
and thenjava -cp antlr-3.2.jar org.antlr.Tool layoutTree.g
– Bart Kiers