[antlr-interest] Re: generated code not compilable.

mzukowski at yci.com mzukowski at yci.com
Tue Oct 29 10:12:08 PST 2002


You need a newer version of antlr.  I recommend downloading the latest.

Monty

> -----Original Message-----
> From: praveen_c [mailto:praveen_c at yahoo.com]
> Sent: Tuesday, October 29, 2002 9:55 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Re: generated code not compilable.
> 
> 
> Here is the nextToken() method that's generated. I numbered each 
> line. Line 14 is invalid, the word "true" must be surrounded by (). 
> Also line 23 gets an illegal start of the expression. Let me know if 
> you need more info. There are a couple more identical things.
> 
> 1 public Token nextToken() throws TokenStreamException {
> 2	Token theRetToken=null;
> 3 tryAgain:
> 4	for (;;) {
> 5		Token _token = null;
> 6		int _ttype = Token.INVALID_TYPE;
> 7		resetText();
> 8		try {   // for char stream error handling
> 9			try {   // for lexical error handling
> 10				if ((LA(1)=='<') && (LA(2)=='@')) {
> 11					mTAG(true);
> 12					theRetToken=_returnToken;
> 13				}
> 14				else if true {
> 15					mTEXT(true);
> 16					theRetToken=_returnToken;
> 17				}
> 18				else {
> 19					if (LA(1)==EOF_CHAR) {uponEOF
> (); _returnToken = makeToken(Token.EOF_TYPE);}
> 20				else {throw new 
> NoViableAltForCharException((char)LA(1), getFilename(), getLine());}
> 21				}
> 22				
> 23				if ( _returnToken==null ) continue 
> tryAgain; // found SKIP token
> 24				_ttype = _returnToken.getType();
> 25				_returnToken.setType(_ttype);
> 26				return _returnToken;
> 27			}
> 28			catch (RecognitionException e) {
> 29				throw new 
> TokenStreamRecognitionException(e);
> 30			}
> 31		}
> 32		catch (CharStreamException cse) {
> 33			if ( cse instanceof CharStreamIOException ) {
> 34				throw new TokenStreamIOException
> (((CharStreamIOException)cse).io);
> 35			}
> 36			else {
> 37				throw new TokenStreamException
> (cse.getMessage());
> 38			}
> 39		}
> 40	}
> 41 }
> 
> 
> --- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
> > What is the compilation error and where?
> > 
> > Terence
> > 
> > On Tuesday, October 29, 2002, at 08:36  AM, praveen_c wrote:
> > 
> > > For some reason when I use the charVocabulary option in the 
> following
> > > grammar, I get code that CANNOT be compiled. When I remove it, I 
> get
> > > compilable code. Is there something wrong in the grammar?
> > >
> > > Any help would be greatly appreciated. Comments on the grammar are
> > > welcome.
> > >
> > > ---------------------------GRAMMAR FILE---------------------------
> ----
> > > header { package tom; }
> > >
> > > class SimpleParser extends Parser;
> > >
> > > template: (TEXT | TAG)+;
> > >
> > > class SimpleLexer extends Lexer;
> > > options {
> > >     k=2;
> > >     testLiterals=false;
> > >     charVocabulary = '\3'..'\377' | '\u1000'..'\u1fff';
> > > }
> > >
> > > {
> > >     public boolean isEndOfText() throws antlr.CharStreamException 
> {
> > >         char char1 = LA(1);
> > >         if (char1 == '<') {
> > >             char char2 = LA(2);
> > >             if (char2 == '@') { // "<@"
> > >                 return true;
> > >             } else if (char2 == '/') { // "</"
> > >                 //ignore any white space
> > >                 int i = forwardToNonWhiteSpace(3);
> > >
> > >                 if (
> > >                     (LA(i++) == 'l') &&
> > >                     (LA(i++) == 'o') &&
> > >                     (LA(i++) == 'o') &&
> > >                     (LA(i++) == 'p')
> > >                    ) {
> > >
> > >                    //match whitespace.
> > >                    i = forwardToNonWhiteSpace(i);
> > >
> > >                    if (LA(i++) == '>') { // "</loop>"
> > >                         return true;
> > >                    } else {
> > >                         return false;
> > >                    }
> > >                } else {
> > >                     return false;
> > >                }
> > >             } else { // it began with '<' but doesn't have 
> anything
> > > meaningful after that.
> > >                 return false;
> > >             }
> > >         } else if (char1 == EOF_CHAR) { //End-of-file reached, 
> can't
> > > proceed further.
> > >             return true;
> > >         } else { //doesn't begin with '<', so it's a normal char, 
> not
> > > a special one.
> > >             return false;
> > >         }
> > >     }
> > >
> > >     public int forwardToNonWhiteSpace(int i) throws
> > > antlr.CharStreamException {
> > >         char c = LA(i);
> > >         while ( (c==' ') || (c == '\t') || (c == '\n') ) {
> > >             i++;
> > >             c = LA(i);
> > >         }
> > >         return i;
> > >     }
> > > }
> > >
> > > protected
> > > WS : ( ' ' | '\t' | '\n' )* ;
> > >
> > > TAG:     (options
> > >             {
> > >                 generateAmbigWarnings=false;
> > >             }:
> > >                 "<@"
> > >                 (
> > >                     ("include") => INCLUDE { $setType(INCLUDE); } 
> |
> > >                     ("loop")    => LOOP { $setType(LOOP); } |
> > >                     TEXT
> > >                 )
> > >                 '>'
> > >         );
> > >
> > > protected
> > > INCLUDE: "include" ;
> > >
> > > protected
> > > LOOP: "loop" ;
> > >
> > > protected
> > > END_LOOP: "</" LOOP '>';
> > >
> > > TEXT:   (END_LOOP) => END_LOOP { $setType(END_LOOP); } |
> > >         (
> > >         options
> > >             {
> > >                 generateAmbigWarnings=false;
> > >             }:
> > >             ( { !isEndOfText() }? . )*
> > >         );
> > >
> > >
> > >
> > >
> > > Your use of Yahoo! Groups is subject to 
> > > http://docs.yahoo.com/info/terms/
> > >
> > >
> > --
> > Co-founder, http://www.jguru.com
> > Creator, ANTLR Parser Generator: http://www.antlr.org
> > Lecturer in Comp. Sci., University of San Francisco
> 
> 
>  
> 
> 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