[antlr-interest] need some advice

Dietmar Schaefer dietmar-s at online.de
Fri Apr 9 04:23:45 PDT 2010


On 04/09/2010 11:50 AM, Bart Kiers wrote:
> On Fri, Apr 9, 2010 at 10:56 AM, Dietmar Schaefer<dietmar-s at online.de>wrote:
>
>    

Well - that  explains everything.

I moved - at a first solution - the VALUE rule before the ID rule - it 
works.



Thank you and Chris for your help.


regards


Dietmar
> When stumbling upon the 'A' from 'A1200', the lexer tries to complete an
> ID-rule. Try moving the VALUE-rule before the ID-rule:
>
> grammar Test;
>
> scenario
>    :  statement
>    ;
>
>
> statement
>    :  sequenceStatement
>    ;
>
> sequenceStatement
>     :  'DefSequence' ID '{' VALUE '}' ';'?
>     ;
>
> VALUE
>    :  ('A' | 'B' | 'C') DIGIT DIGIT DIGIT DIGIT
>    |  ('-')*
>    ;
>
> ID
>    :  LETTER (LETTER | DIGIT | '_')*
>    ;
>
> fragment
> DIGIT
>    :  '0'..'9'
>    ;
>
> fragment
> LETTER
>    :  'a'..'z' | 'A'..'Z'
>    ;
>
> WHITESPACE
>    :  ('\t' | ' ' | '\n' | '\r')+ {$channel = HIDDEN;}
>    ;
>
> But note that your ID's can then not start with 'A', 'B' or 'C'! If you want
> that, look into semantic predicates:
> http://www.antlr.org/doc/glossary.html#Predicate,_semantic
>
> Regards,
>
> Bart.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>    



More information about the antlr-interest mailing list