[antlr-interest] Re: problem with syntactic predicates

lgcraymer lgc at mail1.jpl.nasa.gov
Thu Oct 28 02:32:02 PDT 2004



--- In antlr-interest at yahoogroups.com, "whaefelinger"
<ora.et.labora at w...> wrote:
> 
> Hello,
> 
> antlr's 2.7.4 documentation states: 
> 
> "Syntactic  predicates  are a form of selective back-
> tracking and, therefore, actions are turned off while
> evaluating a  syntactic  predicate so that actions do 
> not have to be undone." 
> 
> 1st issue:
> 
> Having a look into generated code I can see that actions
> to create tree nodes are still done while "guessing". Is
> there a specific reason for creating them?

There used to be conditional guards so that ASTs were not created when
in guessing mode, but they were removed in 2.7.2.

> 2nd (more important) issue:
> 
> Assume  one   of  my actions is to switch to a different
> lexer  (as in the javadoc example).  This  lexer  switch 
> would then  not  be  executed and consequently "guessing"
> would fail, right?
> 
> Perhaps I miss the point but shouldn't there be something
> that let me tell antlr to executed this action regardless
> of guessing or not?

If you are really going to do this sort of thing, then it probably
makes more sense to switch lexers after you recognize the javadoc
comment so that the second lexer parses a string instead of the input
stream--then "nextToken" in the string lexer can switch lexers when
the string is exhausted.  That also lets you can skip the javadoc
comment in guessing mode, but process it when not guessing.

> Here's a proposal:
> 
> JAVADOC_OPEN
>     :    "/**" {! selector.push("doclexer"); }  ;
> ================^

You really want to avoid driving the recognition phase with
actions--mixing paradigms (procedural and syntax-oriented processing)
leads to fragile and difficult to maintain language processors.  Take
a look at <http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf>
for a discussion of the general principle.

--Loring

> The operator  "{!" shall indicate execution of action in
> any case (the action is assumed to be "idempotent").
> 
> 
> But perhaps I missed the point. Is there another way of
> doing this?
> 
> Wolfgang.





 
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