[antlr-interest] unexpected char exception

Loring Craymer Loring.G.Craymer at jpl.nasa.gov
Sat Feb 26 13:17:04 PST 2005


You need at least a lexer rule which recognizes text; "abc" is a special
case for that rule.  Also look at the testLiterals option.

--Loring

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of jean.morissette666 at videotron.ca
> Sent: Saturday, February 26, 2005 1:01 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] unexpected char exception
> 
> Hi,
> I'm an Antlr newbie.  Could you tell me why I have this error and how to
> resolve it:
> 
> exception: line 1:1: unexpected char: 'a'
> 
> Here is my grammar:
> 
> class P extends Parser;
> 
> startRule
>     :   "abc"
>     ;
> 
> class L extends Lexer;
> 
> NEWLINE
>     :	'\n'
>     ;
> 
> And my test case:
> 
> import java.io.*;
> 
> class AntlrTest {
>   public static void main(String[] args) {
> 	try {
> 	  String s = "abc";
> 
> 	  L lexer = new L(new StringReader(s));
> 	  P parser = new P(lexer);
> 	  parser.startRule();
> 	} catch(Exception e) {
> 	  System.err.println("exception: "+e);
> 	}
>   }
> 
> Thank for your help
> -Jean
> 



More information about the antlr-interest mailing list