[antlr-interest] Syntax problems ...

Lloyd Dupont lloyd at galador.net
Wed Apr 24 05:47:49 PDT 2002


I had a problem with the simple grammar at end.

if I type stupid things (I meannot recognised by the lexer) it go in a never
ending loop.
I read the generated code, the parser, when finding a null token presume a
whitespace and loop and in the lexer, when whitespace is called, if it found
no relevant character, it return null.

is it normal ? is it a bug ? what could I do ?

here is my simple grammar (the longuest part is the main function...)
# ----------------
header {
    import java.util.*;
    import java.io.*;
}

class TinyParser extends Parser;
options {
  k=2; // two characters of lookahead
}
{
    public static void main(String[] args)
     throws Exception
    {
        if(args.length == 0)
         parse(System.in);
        else for(int i=0; i<args.length; i++)
         parse(new FileInputStream(args[i]));
        System.out.println("... EOVT ...");
 }

    static void parse(InputStream is)
         throws Exception
    {
        TinyLexer lexer = new TeenyLexer(new DataInputStream(is));
        TokenBuffer buffer = new TokenBuffer(lexer);
        TinyParser parser = new TinyParser(buffer);
        parser.startProcessing();
 }
}

startProcessing :
(
   text:WORD { System.out.println("WORD: " + text.getText()); }
)+
;

// -- here the lexer
class TinyLexer extends Lexer;

options {
  k=2; // two characters of lookahead
  charVocabulary  = '\3'..'\377';
}


WORD : ('a'..'z'|'A'..'Z'|'0'..'9'|'$'|'.') +;

// whitespace
WS :
    ( ' '
    | '\t'
 | '\r' '\n' { newline(); }
 | '\n' { newline(); }
 ) *
 {$setType(Token.SKIP);} //ignore this token
 ;



 

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



More information about the antlr-interest mailing list