Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EOF error in parser YACC

I am trying to parse a string using the yacc parser provided in the PLY library for Python. The parser itself is very long, but the problem that i am having is that it always gives me the same error, no matter what kind of string i put. The error is this:

yacc: Parse error in input. EOF

And the lexer is running perfectly, so i think the parser is the problem. But i do not understand this error, so i do not even know where to look first to solve this problem

Any ideas? Thank you very much!

like image 799
camelCase Avatar asked Nov 22 '11 00:11

camelCase


1 Answers

All parsers specified in PLY are expected to have a single top-level rule that gets reduced as a result of parsing the entire input text. For example, if parsing a program, the top level rule might be something like this:

def p_program(p):
    '''
    program : declarations
    '''

def p_declarations(p):
    '''
    declarations : declarations declaration
                 | declaration
    '''
...

If you get a "EOF" error in the parser, it means that it reached the end of the input without reducing the top-level grammar rule. That is, the parsing stack is non-empty and there are no more rules that can be reduced. Since the stack is non-empty, the parser will try to shift more symbols and fail due to an EOF.

One potential cause of this error is to have an improperly specified starting rule in your grammar. Make sure the first p_rule(p) function in the file is the start rule.

like image 137
David Beazley Avatar answered Oct 23 '22 04:10

David Beazley