[antlr-interest] Re: lexical nondeterminism between IDENT & LABEL

John D. Mitchell johnm-antlr at non.net
Thu Nov 4 09:00:39 PST 2004


>>>>> "thoth2487" == thoth2487  <thoth2487 at libero.it> writes:
[...]

> MAIN: // right LABEL or MAIN : // wrong LABEL due space(s)

Well, I don't know what language you're trying to build so it's hard to
give you specific advice.

If your label construct is truly syntactic then using the fixed version of
Monty's example of doing it in the lexer is a reasonable approach.

However, if the colon is is overloaded (like '.' in the C language) but the
ambiguities are all purely syntactic in nature then doing the more
complicated factoring as exemplified by the Number rule in the StdC lexer
is a reasonable approach.

However, if the ambiguities related to ':' in your language require
semantic context then how you should resolve it in the parser depends on
the semantics of the language.  For an example of this, check out the
StdCParser.g and look for the rules using COLON.


> so I need to change WS rule from: WS: (' '|'\t'|'\f')
> {$setType(Token.SKIP);};

> to WS: (' '|'\t'|'\f')*;

That's pretty much never a good idea for exactly the reason that you
discovered.

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