On Fri, Apr 9, 2010 at 10:56 AM, Dietmar Schaefer <dietma...@online.de>wrote:

> ...
> DefSequence L { -- }   works
>
> DefSequence L { A1200}  gives me MismatchedTokenException: line 1:16
> mismatched input 'A1200' expecting '\u0006'
>

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

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to il-antlr-inter...@googlegroups.com.
To unsubscribe from this group, send email to 
il-antlr-interest+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to