|Better error messages with yyerror() ffdixon@InterNetivity.com (Frederick F. Dixon) (1997-05-27)|
|Re: Better error messages with yyerror() firstname.lastname@example.org.OZ.AU (1997-05-30)|
|Re: Better error messages with yyerror() email@example.com (Antonio Linares) (1997-05-30)|
|From:||"Frederick F. Dixon" <ffdixon@InterNetivity.com>|
|Date:||27 May 1997 23:42:29 -0400|
|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.
President, InterNetivity, Inc. http://www.InterNetivity.com/
[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]
Return to the
Search the comp.compilers archives again.