Better error messages with yyerror()

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

          From comp.compilers

Related articles
Better error messages with yyerror() ffdixon@InterNetivity.com (Frederick F. Dixon) (1997-05-27)
Re: Better error messages with yyerror() fjh@murlibobo.cs.mu.OZ.AU (1997-05-30)
Re: Better error messages with yyerror() alinares@sp-editores.es (Antonio Linares) (1997-05-30)
| List of all articles for this month |
From: "Frederick F. Dixon" <ffdixon@InterNetivity.com>
Newsgroups: comp.compilers
Date: 27 May 1997 23:42:29 -0400
Organization: InterNetivity, Inc.
Keywords: lex, yacc, errors, comment

Hi,


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. http://www.InterNetivity.com/


e-mail: ffdixon@InterNetivity.com
  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.