[antlr-interest] more sem pred "correctness"

Terence Parr parrt at cs.usfca.edu
Tue Jun 8 13:18:59 PDT 2004


John,

Yeah, I will have to be careful when defining correctness.  For 
example, here is one of my more interesting tests:

     public void testIgnorePredFromLL2Alt() throws Exception {
         Grammar g = new Grammar(
             "grammar P;\n"+
             "a : {p1}? A B | A C | {p2}? A | {p3}? A | A ;\n");
         g.createLookaheadDFAs();
         // two situations of note:
         // 1. A B syntax is enough to predict that alt, so p1 is not 
used
         //    to distinguish it from alts 2..5
         // 2. Alts 3, 4, 5 are nondeterministic with upon A.  p2, p3 
and the
         //    complement of p2||p3 is sufficient to resolve the 
conflict. Do
         //    not include alt 1's p1 pred in the "complement of other 
alts"
         //    because it is not considered nondeterministic with alts 
3..5
         String expecting =
                 ".s0-A->.s1\n" +
                 ".s1-B->:s2=>1\n" +
                 ".s1-C->:s3=>2\n" +
                 ".s1-{p2}?->:s4=>3\n" +
                 ".s1-{p3}?->:s5=>4\n" +
                 ".s1-{!((p3||p2))}?->:s6=>5\n";
         checkDecision(g, 1, expecting, null);
     }

Semantic predicates are subtle!

Terence
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
Cofounder, http://www.knowspam.net enjoy email again!
Cofounder, http://www.peerscope.com pure link sharing





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list