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;
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
;
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).
From page 8:
From page 15: