Re: Better error messages with yyerror()

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

Frederik,


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.


regards,
[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.