[antlr-interest] Re: problem with syntactic predicates

whaefelinger ora.et.labora at web.de
Fri Oct 29 01:28:40 PDT 2004



--- In antlr-interest at yahoogroups.com, "lgcraymer" <lgc at m...> wrote:

> > 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.

The javadoc comment was meant as an example. Here it's rather easy 
to detect the end of the comment  and  the lexer will skip it (ie. 
will save it for later usage) anyway. I could think of cases where 
the end is more difficult to detect, especially by the lexer.

Another problem  is probably this when I need to know whether it's 
a "javadoc comment" or not to get the proper result for my calling 
syntax predicate. Sure, comments can always be evaluated later but
how about "non comment" situations?

For example, in my grammar "]]" is a token but in a certain 
production, "]]" is not a token but rather "]" "]". 

Luckily I'm sure that my  rule accepting  this production is not 
used while  guessing -- but this not easy to see. (Btw, is there
a tool that allows me  to  ask such questions whether  a rule is
reachable  starting  with  a  second rule? Or kind of rule cross
referencer?? )

> > Here's a proposal:
> > 
> > JAVADOC_OPEN
> >     :    "/**" {! selector.push("doclexer"); }  ;
> > ================^
> 
> You really want to avoid driving the recognition phase with
> actions [..]

But  isn't  that exactly the case when switching the lexer by
an action??

> mixing paradigms (procedural  and  syntax-oriented
> processing) leads to fragile and difficult to maintain 
> language processors.

True in most cases but I wouldn't say that it  is necessarily 
the case. 

Cheers,
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