[antlr-interest] predicate question

Magnus Danielson magnus at rubidium.dyndns.org
Mon May 5 19:12:15 PDT 2008


From: Terence Parr <parrt at cs.usfca.edu>
Subject: [antlr-interest] predicate question
Date: Mon, 5 May 2008 18:20:28 -0700
Message-ID: <B7537D4F-5349-48C9-B0DB-0AC0FCC12ADD at cs.usfca.edu>

> Consider:
> 
> parser grammar T;
> 
> a : {p1}? {action} {p2}? A
>    | A
>    ;
> 
> Someone pointed out that p2 should not be tested out of context (i.e., before action executes).  ANTLR v2 (PCCTS) correctly ignored preds after actions.  v3 definitely walks right over actions looking for preds.   I propose to prevent p2 from being hoisted into the decision for rule 'a'.  Right now it generates enclosed DFA.  After fix, it would only see p1.  Not sure how to fix just yet, but i'll figure it out.
> 
> Contrary opinions?

What if p2 depends on content of action? It could be argues that p2 may not
depend on action, and thus can be hoisted along with p1. This would be a limit,
as you may wish to use such a construct.
As long as you can roll back or fail misserably I think not hoisting p2 is
reasnoble in this case. On the other hand, if p2 does not depend on action,
p2 could be merged with p1 without changing the meaning.
If you pass p1 but not p2... bail out appropriatly.

My conclusion is that p2 should not be hoisted, since for it to be usefull, it
need to use information not yeat ready at the time of p1.

Cheers,
Magnus


More information about the antlr-interest mailing list