[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pushing text back into the input stream

Etienne. I am trying to add a simple error recovery mechanism to sable's parser.
Since the lexer uses a pushback reader, I thought of a simple approach which 
involves pushing expected tokens into the input stream. So what I did was to 
add the following method to the lexer.

    public void unread(String str) throws IOException
        int length = str.length();

        for(int i = length - 1; i >= 0; i--)
            eof = false;


If this is a stupid idea, please tell me so. Otherwise, perhaps you
can tell me why the text I unread causes unrecognized token errors in
the lexer. Here's the error message I get.

[3,2] Unknown token: <
html.lexer.LexerException: [3,2] Unknown token: <
        at html.lexer.Lexer.getToken(Compiled Code)
        at html.lexer.Lexer.peek(Compiled Code)
        at html.parser.Parser.parse(Compiled Code)
        at html.Translator.main(Compiled Code)
Exception in thread "main" java.lang.ClassCastException: html.lexer.LexerException
        at html.Translator.main(Compiled Code)

and my .grammar file contains the token 
open = '<';