Hi Everyone,

This is the first time I use sableCC, but is failing on me with something
basic.
It has to be me!! :)

I am using sablecc 3.2

Please see the two examples below. One works, the other one doesn't
The input in both cases is a string equal to "45" (without the quotes).
is really that simple, just two chars. And the grammar file has two token
definitions and only one production.

Good: The method parseFileA() works as expected, as it prints
     [java] ...starting..
     [java] [45 ]
     [java] no more tokens

Bad: The method parseFileB() throws this Exception:
     [java] org.sablecc.sablecc.parser.ParserException: [1,1] expecting: EOF
     [java]     at org.sablecc.sablecc.parser.Parser.parse(Parser.java:1792)
     [java]     at
com.cariden.parseconfig.GrammarOne.parseFileB(GrammarOne.java:61)

The portion in Parser.java that throws the exception is this one:

      case ERROR:
        throw new ParserException(last_token,
                                  "[" + last_line + "," + last_pos + "] " +
                                  errorMessages[errors[action[1]]]);

Please, please help me !!. I really want to use this tool !!

Claudio


*
grammar
**--------------------------------------**
--------------------------------------*

Package com.cariden.parseconfig.generated.AluGrammar;

Tokens
    number = ['0' .. '9']+;
    blank = (' ' | 13 | 10)+;

Ignored Tokens
    blank;

Productions
    term = {number} number;


*java code
**--------------------------------------**
--------------------------------------*
*    // this example works*
    public static void parseFileA( File aInFile )
    {
        try
        {
            Reader lReader = new FileReader( aInFile );
            Lexer lexer =  new Lexer( new PushbackReader( lReader ) );
            System.out.println( "starting.." );
            while ( true )
            {
                org.sablecc.sablecc.node.Token next = lexer.peek();
                if ( next instanceof org.sablecc.sablecc.node.EOF )
                {
                    System.out.println( "no more tokens" );
                    break;
                }
                else
                {
                    next = lexer.next();
                    System.out.println( "[" + next.toString() + "]" );
                }
            }
        }
        catch ( Throwable t )
        {
            t.printStackTrace();
        }
    }

*    // this example gives an unexpected exception inside call to p.parse()
*
    public static void parseFileB( File aInFile )
    {
        try
        {
            Reader lReader = new FileReader( aInFile );
            Lexer lexer =  new Lexer( new PushbackReader( lReader ) );
            Parser p = new Parser( lexer );
            Start tree = p.parse();
        }
        catch ( Throwable t )
        {
            t.printStackTrace();
        }
    }
_______________________________________________
SableCC-Discussion mailing list
[email protected]
http://lists.sablecc.org/listinfo/sablecc-discussion

Reply via email to