如何从antlr中的语法文件创建令牌文件
我正在使用 antlr 创建 DSL。 Lexer 和 Parser 编写在一个语法文件中(例如layout.g)。树语法是在另一个语法文件(例如layoutTree.g)中编写的。现在树解析器无法正确解析。我打印了解析器的 AST 输出,它是正确的。我浏览了生成的树解析器代码,发现标记值声明在树解析器和解析器中分配了不同的值。下面是解析器和树解析器的示例输出。
解析器输出
public static final int ARRAY_MEMBER_TOKEN=4;
public static final int ARRAY_TOKEN=5;
public static final int DECLARATION_TOKEN=6;
树解析器输出
public static final int EOF=-1;
public static final int DECLARATION_TOKEN=4;
public static final int IDENTIFIER=5;
如您所见,DECLARATION_TOKEN 在解析器输出和树解析器输出中具有不同的值。因为这个树解析器没有按预期工作。我该如何纠正这个问题?
生成的令牌文件(例如layout.token)是否有问题?我的项目中该文件为空。如何生成该文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的树语法中有类似的东西吗?
Do you have something like this in your tree grammar?