ANTLRWorks调试 - 不同颜色的含义? [英] ANTLRWorks debugging - the meaning of the different colors?

查看:227
本文介绍了ANTLRWorks调试 - 不同颜色的含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the debugging mode of ANTLRWorks to test my c-grammar. Debugging in ANTLRWorks is really great for better understanding but I have a problem in understanding the different colors of the output tree. I'm using backtrack=true in my grammar. I thought that the red color means that the debugger goes the wrong way while green tells me that it is has gone the right way. But what about dark red and dark green?

我添加了一个小树的图片,它只匹配以下输入:

I added a picture of a "small tree" which only match the following input:

int test;

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

If it's necessary to answer the question, here are the 4 most important rules which are used.

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为嵌套级别的回溯提供视觉反馈 - 颜色越深越深。

It's not so much about "right" and "wrong" as it as about the parser trying to figure out which rule will match the input. When ANTLR has to backtrack, ANTLRWorks uses red for branches of the parse tree that it considered as possible matches. Green is used for branches the parser actually explored and black for the branch that successfully matched the input. The darker and lighter colors is ANTLRWorks providing visual feedback for nested levels of backtracking - the deeper the level the darker the color.

这个答案的主要来源是从

The primary source of this answer is from ANTLRWorks: An ANTLR Grammar Development Environment Unpublished Draft written by Bovet (created ANTLRWorks) and Parr (created ANTLR).

从第8页: p>

From page 8:


解析器采用的路径显示为绿色

the path taken by the parser is shown in green

从第15页起:


当ANTLR必须回溯到区分替代生产时,通常很难
调试解析器,因为开发人员必须跟踪分析器在猜测时的时间,而
不是。 ANTLRWorks通过以红色显示解析树中的所有推测式解析分支来明确区分两种模式。 ...第二个子树[以黑色显示]是规则 s 中成功匹配的第二个选项的解析树。在ANTLR必须嵌套回溯的情况下,ANTLRWorks会通过一系列渐变来改变颜色,每个渐变是每个回溯嵌套级别。

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.

这篇关于ANTLRWorks调试 - 不同颜色的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆