[antlr-interest] wow. marathon debug session

Terence Parr parrt at cs.usfca.edu
Wed May 7 13:19:11 PDT 2008


In process of fixing a bug, I realized that some decisions did not  
properly detect all insufficiently covered predicates. Here is an  
interesting case for you.

parser grammar U;
a : (A B)? ;
b : X a {p1}? A B | Y a {a1} {p2}? A B | Z a ;

To create the prediction DFA for the optional sub rule in 'a', ANTLR  
must find all references to 'a' to determine what can follow. A B can  
follow 'a' in the first two alts rule 'b'.   To resolve the conflict  
between matching A B immediately in the sub rule and exiting rule 'a'  
to match it in 'b', ANTLR looks for predicates. In this case, there  
are two predicates that indicate the semantic context in which the  
surrounding alternatives are valid. The problem is that one of the  
predicates is hidden by an action. It took me 1.5 days, but I've  
finally have gotten ANTLR to properly track the insufficiently covered  
alternatives. Further, I have gotten it to tell you precisely where  
the uncovered predicates are even if they are simply hidden by  
actions. I have also updated all of the nondeterminism warnings so  
that it tells you if there was a predicate but one hidden by an action  
(this could be a separate condition from insufficiently covered  
predicates). here are your messages from ANTLR:

ANTLR Parser Generator  Version 3.1b1 (??)  1989-2007
warning(203): U.g:2:5: Input such as "A B" is insufficiently covered  
with predicates at locations: alt 2: line 3:38 at B
Semantic predicates were present but were hidden by actions.
warning(200): U.g:2:5: Decision can match input such as "A B" using  
multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.

Whew... added a bunch of unit tests and now can get back to the few  
bugs remaining (yes, people reminded me of some important bugs to  
fix). first, I have to teach my last class of the semester for the  
grad programming languages class.

Ter
PS	I am definitely not looking for predicates after actions.  
prediction must occur before any action with side effects which  
includes arbitrary user actions as well as tokens. Hoisting depth must  
be zero.



More information about the antlr-interest mailing list