The first thing the parser does when it performs the Error action is to call a function named yyerror() . This happens before the parser begins going down the state stack in search of a state that can handle the error symbol. yyerror() is a lex and yacc library function that simply displays a text string argument to stderr using fprintf , and returns the integer value received from fprintf . The user may choose to supply their own version. See The lex library routines for information about creating a user-defined yyerror() .

The simplest yyerror() functions either abort the parsing job or just return so that the parser can perform its standard error handling.

The yacc passes one argument to yyerror() : a character string describing the type of error that just took place. This string is almost always:
Syntax error
The only other argument strings that might be passed are:
Not enough space for parser stacks
Parser stack overflow
which are used when the parser runs out of memory for the state stack.

Once yyerror() returns to yyparse() , the parser proceeds popping down the stack in search of a state that can handle errors.

If another error is encountered soon after the first, yyerror() is not called again. The parser considers itself to be in a potential error situation until it finds three correct tokens in a row. This avoids the torrents of error messages that often occur as the parser wades through input in search of some recognizable sequence.

After the parser has found three correct tokens in a row, it leaves the potential error situation. If a new error is found later on, yyerror() is called again.