EOF Error in YACC Parser

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

yacc: input error in input. Eof

And the lexer works just fine, so I think it is a parser. But I don’t understand this error, so I don’t even know where to look first to solve this problem.

Any ideas? Thank you very much!

+4
source share
1 answer

All parsers specified in PLY are expected to have one top-level rule, which will be reduced as a result of the analysis of the entire input text. For example, when parsing a program, a top-level rule might look something like this:

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

If you get an "EOF" error in the parser, it means that it has reached the end of the input without lowering the top-level grammar rule. That is, the syntax stack is not empty, and there are no more rules that can be reduced. Since the stack is not empty, the analyzer will try to shift more characters and crash due to EOF.

One of the potential causes of this error is an incorrect initial rule in your grammar. Make sure that the first p_rule (p) function in the file is the start rule.

+5
source

Source: https://habr.com/ru/post/1382405/


All Articles