greenoldman
greenoldman

Reputation: 21082

What are the requirements/limitations of the error recovery productions in YACC/Bison?

Let's say I would like to add error recovery production into my grammar -- I know what it is, I saw examples.

However I didn't find anything more formal, i.e. how such production should really look like, what is possible and what is forbidden?

Bison error recovery documentation

For now I could only check by trial & error, if such productions are valid:

A := error B 
B := num

or

A := ( error ; error )

Of course trial & error is inefficient, so I would like to read the rules for error recovery productions.

Upvotes: 0

Views: 212

Answers (1)

akim
akim

Reputation: 8779

The documentation you point to is oldish, the "real" one is here: http://www.gnu.org/software/bison/manual/html_node/Error-Recovery.html. But there are little differences on these regards.

I don't think you'll find anything more about this topic. Except maybe in the part of the documentation where an example is provided: http://www.gnu.org/software/bison/manual/html_node/Simple-Error-Recovery.html.

The only thing to keep in mind is that it should be "not too hard" for Bison to find when to stop popping the stack, and when to stop discard input. Having a "terminator", such as ";" for some rules, or even braces ("(" and ")" in your example) is usually the best choice. Otherwise you might introduce new conflicts.

HTH.

Upvotes: 1

Related Questions