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

thoth2487 thoth2487 at libero.it
Wed Nov 3 23:30:33 PST 2004



--- In antlr-interest at yahoogroups.com, "John D. Mitchell"
<johnm-antlr at n...> wrote:
> Stop trying to do that in the lexer.  
> Let the lexer return the ID for both and then have your
> parsing rules distinguish between ID ":" being a label
> or the ID is just an ID.

I've tried your suggested parser way with:

ident:  IDENT;

label:  IDENT
        COLON
	;

but in this way a LABEL could be either:

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

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

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

Now parser work fine with 'ident' & 'label'
but new WS behaviour make more complex parsers
rules which must check always also presence of WS. Eg:

conditional:
  IF
  (WS)?
  expression
  (WS)?
  goto
  ........ and so on

What I've mistaked ? What do you suggest about ?

Thank you very much
Silverio Diquigiovanni





 
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