[antlr-interest] predicate question

Terence Parr parrt at cs.usfca.edu
Mon May 5 22:41:25 PDT 2008


On May 5, 2008, at 8:09 PM, Gerald Rosenberg wrote:

> At 07:27 PM 5/5/2008, Terence Parr wrote:
>
>> On May 5, 2008, at 7:17 PM, Gerald Rosenberg wrote:
>>
>>> Is the question whether
>>>
>>> a : {p1}? {action();} {p2}? A | A ;
>>>
>>> should perform differently from
>>>
>>> a : {p1}? {action(); return true;}? {p2}? A | A ;
>>>
>>> From a high level the-grammar-as-a-language point of view, seems
>>> like those two rules should match equivalently.
>>
>> p1 / p2 are evaluated out of order of normal flow, which is the
>> issue.  Predicates can be hoisted into parsing decision, which
>> different than the matching. the matching works...prediction won't :)
>>
>> Ter
>
> I was imprecise:  "seems like those two rules should both predict  
> and match equivalently."
>
> I know there is a historical basis for treating actions as first  
> class elements, but is there a language-level reason why an action  
> is not logically just an unchecked validating predicate (or a  
> predicate just a checked action with a bunch of nifty turbo- 
> performance accelerators under the hood)?

Well, matching ID could be just an action by that argument...then  
everything is an predicate. ;)  Predicates are not hoisted over rule  
or token refs and should not be hoisted over actions.  I cannot  
execute the action therefore preds after a action cannot be tested.   
The action likely has sideeffects.  Prediction of alts must be side- 
effect free, the whole reason actions are gated with the "if ! 
backtracking" thing.

Ter


More information about the antlr-interest mailing list