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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With