开发者

how to create token file from grammar file in antlr

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开发者_如何学Python can I generate this file?


Do you have something like this in your tree grammar?

options
{
  tokenVocab=layout; //NOT layout.g or layout.tokens
  ASTLabelType=pANTLR3_BASE_TREE;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜