[antlr-interest] problem on the grammar of identifier

Jose Ventura jose.ventura.roda at gmail.com
Thu Oct 26 00:30:01 PDT 2006


I don't know how use predicates for this, but in the parser it could be so
(please test it, i'm writing directly, without test):

In Lexer:

{
DOT=".";
CURRENT="current";
}

ID options {testLiterals=true}:
('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;

In parser:

identifier : ID (DOT (ID|CURRENT {countCurrent++;} DOT ID ) )*
               { if (countCurrent>1) //error;}
               ;

Regards,

2006/10/25, Zhiyong Zhang <zhiyong_zhang5 at yahoo.ie>:

>  Hi Jose,
>
> Thanks for your suggestion.
>
> I am trying to move this identifier from lexer to parser, but have no idea
> how to do it with correct syntax in parser.
>
> Could you please help me on this?
>
> I also thinking if it's possible to use predicate in lexer to solve this
> problem, but still can not use correct syntax for this.
>
> Thanks
>
>
>  ----- Original Message ----
> From: Jose Ventura <jose.ventura.roda at gmail.com>
> To: Zhiyong Zhang <zhiyong_zhang5 at yahoo.ie>
> Sent: Wednesday, 25 October, 2006 4:51:42 PM
> Subject: Re: [antlr-interest] problem on the grammar of identifier
>
> Hi Zhiyoung,
>
> I can't test it, but I think the problem is (".current"|"."). This part of
> rule is ambiguous with the next part of rule ('a'..'z'), because the string
> ".current" is right with "." and 'a'..'z', and also with ".current".
>
> I think is better to you to do this test at parser. Maybe with a rule for
> the identifier and a tokens 'current' and '.'
>
> Regards
> José Ventura
>
>
>
> 2006/10/25, Zhiyong Zhang <zhiyong_zhang5 at yahoo.ie>:
> >
> >  Hi,
> >
> >
> > The identifier is supposed to in be the format of "abc.d6f" or "
> > abc.current.dg47". I got ambiguity problem with the lookahead =3 in the
> > lexical grammar, it also reported problem abc.currentAbcdE. Can anybody
> > give me some light?
> >
> >
> >
> > IDENTIFIER
> > options {testLiterals=true;} : ('a'.. 'z'|'A'..'Z'|'_')( 'a'..'z'|'A'..'Z'
> > |'0'..'9'|'_'| ':')*  ( (".current."| ".") ('a'..'z'|'A' ..'Z'|'0'..'9'|'_'
> > |':')+)?;
> >
> >
> >
> > Thanks in advance.
> >
> >
> >
> > Send instant messages to your online friends
> > http://uk.messenger.yahoo.com
> >
>
>
>
>
>
> Send instant messages to your online friends http://uk.messenger.yahoo.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061026/9932fb4a/attachment.html 


More information about the antlr-interest mailing list