I have an error I can't figure out...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kevin_Szerszen
Posted On:   Thursday, April 12, 2001 07:56 PM

I get the following error: error: Token stream error reading grammar(s):antlr.TokenStreamRecognitionException: unexpected char: ( TokenStreamException: unexpected char: ( Using the following *.g file: class KevsParser extends Parser; prog: PROGRAM i:ID BEGIN stmtlist END ; stmtlist: stmt ( SEMI stmt )* ; exp: term ( ( ADD | MINUS ) term )* ; term: factor ( ( TIMES | DIV ) factor )* ; factor: DIGIT | ID | &quo   More>>

I get the following error:



error: Token stream error reading grammar(s):antlr.TokenStreamRecognitionException: unexpected char: (

TokenStreamException: unexpected char: (





Using the following *.g file:



class KevsParser extends Parser;


prog:

PROGRAM i:ID

BEGIN

stmtlist

END

;



stmtlist:

stmt ( SEMI stmt )*

;



exp:

term ( ( ADD | MINUS ) term )* ;



term:

factor ( ( TIMES | DIV ) factor )* ;



factor:

DIGIT

| ID

| "(" exp ")"

;



for

:

FOR indexexp DO body

;

indexexp

:

ID BECOMES exp to exp

;





body

:

(stmt | BEGIN stmtlist END)

;









class KevsLexer extends Lexer;



// Keywords

PROGRAM : "program";

BEGIN : "begin";

FOR : "for";

DO : "do";

TO : "to";

END : "end";





// Comments





//Skip Whitespace

WS : ( ' ' | ' ' | '
' | ' { newline(); } | '
' )+

{ $setType(Token.SKIP)}; }

;





//Identifiers

ID : ( 'a'..'z' | 'A'..'Z' ) ( 'a'..'z' | 'A'..'Z' | '0'..'9' )* ;



DIGIT : '0'..'9' ;





//Operators

BECOMES : ":=";

PLUS : "+";

MINUS: "-";

TIMES : "*";

DIV : "/";

SEMI : ";";



Anyone have a clue what is causing it. Everything looks okay to me. Thanks in advance.

   <<Less

Re: I have an error I can't figure out...

Posted By:   Terence_Parr  
Posted On:   Friday, April 13, 2001 12:08 PM

Yep. Your


| "(" exp ")"


is looking for two chars followed by (. Try just "(" and the world is yours! :)


Remember that strings are just strings not regular expressions so you don't need to escape the parens.

About | Sitemap | Contact