DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(bison.info) Error Reporting

Info Catalog (bison.info) Lexical (bison.info) Interface (bison.info) Action Features
 
 The Error Reporting Function `yyerror'
 ======================================
 
    The Bison parser detects a "parse error" or "syntax error" whenever
 it reads a token which cannot satisfy any syntax rule.  A action in the
 grammar can also explicitly proclaim an error, using the macro
 `YYERROR' ( Special Features for Use in Actions Action Features.).
 
    The Bison parser expects to report the error by calling an error
 reporting function named `yyerror', which you must supply.  It is
 called by `yyparse' whenever a syntax error is found, and it receives
 one argument.  For a parse error, the string is normally
 `"parse error"'.
 
    If you define the macro `YYERROR_VERBOSE' in the Bison declarations
 section ( The Bison Declarations Section Bison Declarations.),
 then Bison provides a more verbose and specific error message string
 instead of just plain `"parse error"'.  It doesn't matter what
 definition you use for `YYERROR_VERBOSE', just whether you define it.
 
    The parser can detect one other kind of error: stack overflow.  This
 happens when the input contains constructions that are very deeply
 nested.  It isn't likely you will encounter this, since the Bison
 parser extends its stack automatically up to a very large limit.  But
 if overflow happens, `yyparse' calls `yyerror' in the usual fashion,
 except that the argument string is `"parser stack overflow"'.
 
    The following definition suffices in simple programs:
 
      yyerror (s)
           char *s;
      {
        fprintf (stderr, "%s\n", s);
      }
 
    After `yyerror' returns to `yyparse', the latter will attempt error
 recovery if you have written suitable error recovery grammar rules
 ( Error Recovery.).  If recovery is impossible, `yyparse' will
 immediately return 1.
 
    The variable `yynerrs' contains the number of syntax errors
 encountered so far.  Normally this variable is global; but if you
 request a pure parser ( A Pure (Reentrant) Parser Pure Decl.)
 then it is a local variable which only the actions can access.
 
Info Catalog (bison.info) Lexical (bison.info) Interface (bison.info) Action Features
automatically generated byinfo2html