Re: Better error messages with yyerror()

"Antonio Linares" <>
30 May 1997 23:12:27 -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: "Antonio Linares" <>
Newsgroups: comp.compilers
Date: 30 May 1997 23:12:27 -0400
Organization: Unisource Espana NEWS SERVER
References: 97-05-297
Keywords: lex


I recommend you to have a look at the book Lex & Yacc (O'Reilly publisher,
authors John R. Levine!!!, Tony Mason and Doug Brown). There you have a
clear explanation of how to do that without having to patch Lex.

Basically all you do is:

\n.* lineno++; strcpy( linebuf, yytext + 1 ); yyless( 1 );

so linebuf contains a entire copy of the source line. For each token you
read you increase a variable with the yyleng of the token, so when a error
ocurrs you know exactly where you are in the line and you can exactly
display the error position.

[Oh, right, that hack. I should read my own books now and then. -John]


Post a followup to this message

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