Loading ...
Sorry, an error occurred while loading the content.

9387Re: Help with grammar file

Expand Messages
  • solmalik
    Sep 4, 2003
    • 0 Attachment
      Hi i think the problem i am having is that the grammar file does not
      seem to recieve any input, I think the problem is i am trying to read
      data from a command line, whereas I want to psss the contents of s
      tring to the grammar file, what would be the best way of doing
      this?. The code used in the class is:

      try //parse eqn entered to see if it conforms to grammar
      {
      L lexer = new L(new DataInputStream
      (System.in));
      P parser = new P(lexer);
      parser.startRule();
      }
      catch(Exception e)
      {
      System.err.println("exception: "+e);
      }
      --- In antlr-interest@yahoogroups.com, mzukowski@y... wrote:
      > 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@h...]
      > Sent: Monday, September 01, 2003 10:56 AM
      > To: antlr-interest@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@yahoogroups.com, mzukowski@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@h...]
      > > Sent: Saturday, August 23, 2003 6:10 AM
      > > To: antlr-interest@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/
    • Show all 6 messages in this topic