Better error messages with yyerror()

"Frederick F. Dixon" <>
27 May 1997 23:42:29 -0400

          From comp.compilers

Related articles
Better error messages with yyerror() (Frederick F. Dixon) (1997-05-27)
Re: Better error messages with yyerror() (1997-05-30)
Re: Better error messages with yyerror() (Antonio Linares) (1997-05-30)
| List of all articles for this month |

From: "Frederick F. Dixon" <>
Newsgroups: comp.compilers
Date: 27 May 1997 23:42:29 -0400
Organization: InterNetivity, Inc.
Keywords: lex, yacc, errors, comment


I'm looking for a way to improve yyerror() so that my programs print out
the full line in which an error occurred.

Right now, I'm using yytext and yylineno in yyerror(), but they are not
very helpful for the user. When there is an error in the source file, I
would to print out the offending line with a carrot ^ pointing to where
Lex or Yacc detected an error. For example,

# MyParser input-file.txt
MyParser: Error - line 315 of "input-file.txt" :unterminated string

315: item="label" name="type

I could try to patch Lex to give me access to the full input line, but I
would like to know if anyone else has done the above.

Regards,... Fred


Frederick Dixon
President, InterNetivity, Inc.

  phone: 613-832-2423
[It's reasonably straightforward to do in the lexer. Probably the easiest
is to write your own YY_INPUT() that provides a line at a time, then have
each lex rule track how many characters it's processed so you know where
to put the caret. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.