debugging - ANTLRWorks 调试 - 不同颜色的含义?

标签 debugging antlr grammar antlrworks ebnf

我正在使用 ANTLRWorks 的 Debug模式来测试我的 C 语法。在 ANTLRWorks 中进行调试确实非常有助于更好地理解,但我在理解输出树的不同颜色方面遇到了问题。我在语法中使用 backtrack=true 。我认为红色意味着调试器走错了路,而绿色则告诉我它走的是正确的路。但是深红色和深绿色呢?

我添加了一张“小树”的图片,它仅与以下输入匹配:

int test;

enter image description here

如果有必要回答这个问题,这里有 4 个最重要的规则。

start
: declaration*
;

declaration
: functionDefinition
| dataDeclaration //also used for Function Declaration
| assemblerDefinition
;


functionDefinition 
: declarationSpecifier* declarator Equals Default Semi
| declarationSpecifier* declarator Equals Delete Semi
| declarationSpecifier* declarator functionBody
;

dataDeclaration
:declarationSpecifier* declarator initializer? (Comma declarator initializer?)* Semi
;

最佳答案

与其说是“对”和“错”,不如说是解析器试图找出哪个规则将与输入相匹配。当 ANTLR 必须回溯时,ANTLRWorks 使用红色作为它认为可能匹配的解析树的分支。绿色用于解析器实际探索的分支,黑色用于成功匹配输入的分支。更深和更浅的颜色是 ANTLRWorks 为回溯的嵌套级别提供视觉反馈 - 级别越深,颜色越深。

此答案的主要来源来自 ANTLRWorks: An ANTLR Grammar Development Environment Unpublished Draft由 Bovet(创建 ANTLRWorks)和 Parr(创建 ANTLR)编写。

从第 8 页开始:

the path taken by the parser is shown in green

从第 15 页开始:

When ANTLR must backtrack to distinguish between alternative productions, it is usually difficult to debug the parser because developers must track when the parser is speculating and when it is not. ANTLRWorks clearly distinguishes between the two modes by showing all speculative parsing branches in the parse tree in red. ... The second subtree [shown in black] is the parse tree for the second alternative in rule s that matches successfully. In situations where ANTLR must nest the backtrack, ANTLRWorks changes the color through a series of gradations, one for each backtracking nesting level.

关于debugging - ANTLRWorks 调试 - 不同颜色的含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23653894/

相关文章:

python - 希腊语上下文无关语法

debugging - Eclipse Scala 解释器 (REPL) - 正确使用和调试

Java Socket 连接仅在 Debug模式下有效

delphi - 如何使用 ANTLR 生成 Delphi 输出?

java - 如何使用 ANTLR4 创建 AST?

c++ - 从文件中读取/解析带有 C++ 标签的 ABNF 语法

compiler-construction - 如何从形式语法生成句子?

IE 的 CSS 调试

wpf 调试错误输出 System.WIndows.Data 错误 25

javascript - 使用 ANTLR 解析 JavaDoc 注释