[antlr-interest] Re: Help with grammar file

mzukowski at yci.com mzukowski at yci.com
Tue Sep 2 08:37:48 PDT 2003


startRule
 : ( equation NEWLINE )+ EOF
 ;

Also try stepping through with a debugger or using the -trace option to
antlr.Tool to get a trace of your lexer and parser printed out when you run
it.

Monty

-----Original Message-----
From: solmalik [mailto:boy_wonder48 at hotmail.com] 
Sent: Monday, September 01, 2003 10:56 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: Help with grammar file


hi the exact error msg I am getting is "line 1:1: unexpected token: 
null".  Any ideas? and what exactly do you mean placing EOF in the 
start rule? I am totally new to this, so don't really have a clue, 
any help much aprreciated thanks.
--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> Try putting EOF in your start rule.  What exactly is the error
message?
> Does it say what rule it was in.
> 
> Monty
> 
> -----Original Message-----
> From: solmalik [mailto:boy_wonder48 at h...]
> Sent: Saturday, August 23, 2003 6:10 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Help with grammar file
> 
> 
> Hi have greated a grammar file, which is to be used to parse any
> expressions entered bya user.  The expressions are of process 
> algebra and a typical expression looks like:
> a[0,2];b[0,1], meaning that (a) is to be executed befroe (b) and 
(a) 
> can be executed by no later than of time 2 units.  Below is the
file 
> I haved used to try and accept an eqxpression of this form, but
When 
> I come to running it, I get the error message unexpected
token:null  
> any help is much appreciated. Thanks.
> 
> class P extends Parser;
> 
> //rule one or more equations forllowed by newline
> startRule
> : ( equation NEWLINE )+
> ;
> 
> //a mineqn followed by zero or more operations and mineqns
> equation: mineqn (operation mineqn)*
> ;
> 
> //mineqn is eith ID or an eqn in brackets
> mineqn : ID TIME
> | OPEN equation CLOSE
> ;
> 
> //operations
> operation
> : SEMICOLN
> | BAR_BAR
> | CARET
> | ASTERISK
> | SY_OP
> | RS_OP
> ;
> 
> class L extends Lexer;
> 
> options {
> testLiterals = true;
> }
> 
> // tokens required for synchronisation and restriction
> tokens {
> SY_OP = "sy";
> RS_OP = "rs";
> }
> 
> TIME: '[' ('0' .. '9') ',' ('0' .. '9') ']';
> 
> OPEN: '(' ;
> 
> CLOSE: ')' ;
> 
> SEMICOLN: ';' ;
> BAR_BAR : "|";
> CARET : '^' ;
> ASTERISK: '*' ;
> 
> 
> //ID any letter from a to z
> ID : ('a' .. 'z' | 'A' .. 'Z');
> 
> NEWLINE : ('\r''\n')=> '\r''\n' //DOS
> | '\r' //MAC
> | '\n' //UNIX
> { newline(); }
> ;
> 
> WS : (' '|'\t') { $setType(Token.SKIP); } ;
> 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list