[antlr-interest] Recursive not supposed behaivor when finding EOF
Marwan Ajraoui
marwan.alephn at gmail.com
Fri May 8 06:34:34 PDT 2009
I did solve the problem, Indhu gave the idea to change my code testing
class with his Question. I had mistake in my testing class, here is
the new code that works. Many thanks for you help guys.
// I was invoking twice to the instance obejct of a parser in the previous code.
BTLParser.decl_codigo_return result=null;
try {
BTLLexer lex = new BTLLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lex);
BTLParser parser = new BTLParser(tokens);
result =parser.decl_codigo();
if (parser.numErrors == 0) {
CommonTree tree = (CommonTree) result.getTree();
System.out.println("El arbol AST:"+ tree.toStringTree());
}
} catch (RecognitionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace
}
cheers,
Marouane
2009/5/8 Marwan Ajraoui <marwan.alephn at gmail.com>:
> Thanks for your interest on the problem I 'm getting;
>
> The input I'm passing is a file without parsing errors; The code I'm
> using to test it is the one below:
>
>
> CharStream input = new ANTLRFileStream(pathfiletest);
> BTLLexer lex = new BTLLexer(input);
> CommonTokenStream tokens = new CommonTokenStream(lex);
> BTLParser parser = new BTLParser(tokens);
> parser.decl_codigo();
> if (parser.numErrors == 0) {
>
> parser.symbols_var.toString();
>
> try {
> CommonTree tree = (CommonTree) parser.decl_codigo().getTree();
> System.out.println("El arbol AST:"+ tree.toString());
> } catch (RecognitionException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> When i do pass i file with wrong statements, it does notify all the
> errors has to be notified, works properly. But in case of passing a
> correct file entry, for the grammar, i ' m getting the mentioned
> before error message.
>
> cheers and thanks,
>
> Marouane
>
>
>
> 2009/5/8 Indhu Bharathi <indhu.b at s7software.com>:
>> Looks like you are parsing with empty input. What is the input you gave to
>> the parser?
>>
>> Cheers, Indhu
>>
>> Marwan Ajraoui wrote:
>>>
>>> Hi there;
>>>
>>> I'm getting a strange error form a parser. I have defined a grammar,
>>> wich contains these rules;
>>>
>>>
>>> decl_codigo : decl_libreria decl_program
>>>
>>> decl_libreria : TAG_START_OPEN 'function_library' ':' FN_ID TAG_CLOSE
>>> decl_funciones TAG_END_OPEN 'function_library' TAG_CLOSE;
>>>
>>> decl_program : TAG_START_OPEN 'program' type_return '::' FN_ID ':'
>>> params_list TAG_CLOSE lista_instrucciones TAG_END_OPEN 'program'
>>> TAG_CLOSE ;
>>>
>>>
>>>
>>> So when i finish parsing the input tested, ANTLR notifies,
>>>
>>> line 0:-1 mismatched input '<EOF>' expecting TAG_START_OPEN
>>>
>>> To find out what could be the problem, i put the TAG_START_OPEN , so i
>>> got:
>>>
>>> line 0:-1 mismatched input '<EOF>' expecting 'function_library'
>>>
>>>
>>> I did check my .g, if i have some other reference to "decl_libreria",
>>> but No, the only reference is written is the one i mentioned before in
>>> the lines above. it is supposed to finish without errors and return an
>>> AST, as i set up the option.
>>>
>>> So why it does behave in recursive way? Any idea.
>>>
>>>
>>> thanks in advance
>>>
>>>
>>>
>>>
>>
>>
>
>
>
> --
> Marouane
>
--
Marouane
More information about the antlr-interest
mailing list