[antlr-interest] DOT missing in java.g example
John D. Mitchell
johnm-antlr at non.net
Tue Apr 27 10:02:49 PDT 2004
>>>>> "ronald" == ronald petty <ronald.petty at milliman.com> writes:
[...]
> Hi, I was looking some more over the java.g grammar and noticed that
> DOT=. is commented out in the Lexer.
That's because a dot/period is an overloaded lexeme. I.e., it's used in a
number of different contexts -- in terms of the lexer, it's not only used
between things but also as an integral part of a decimal number.
[...]
> How does this work for class.method if you have never seen a NUM_INT yet
> to add a '.' or DOT="." to the literals?
Remember that the lexer is more reactive and less predictive than a parser
or tree walker. That is, the non-protected rules are "active" (check out
the generated code for a lexer for the gory details) whenever the lexer
returns to the top-level. I.e., just because we're in the "NUM_INT" rule
doesn't mean that we're saying that we must predict "NUM_INT". In fact, as
you can see, NUM_INT is merely the default return type of the rule.
The NUM_INT rule *is* a bit funny looking because of how the various
allowable number formats work. For example, a lead dot on floating point
types -- that's why having a top-level DOT rule in the lexer won't work for
this particular language.
Hope this helps,
John
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