Related articles |
---|
Error reporting with YACC (or Bison) etetz@my-deja.com (2000-09-21) |
Re: Error reporting with YACC (or Bison) timur@lantel.ru (Timur Safin) (2000-09-23) |
Re: Error reporting with YACC (or Bison) Joachim.Pimiskern@de.bosch.com (Joachim Pimiskern) (2000-09-28) |
From: | Joachim Pimiskern <Joachim.Pimiskern@de.bosch.com> |
Newsgroups: | comp.compilers |
Date: | 28 Sep 2000 22:15:17 -0400 |
Organization: | Robert Bosch GmbH |
References: | 00-09-157 |
Keywords: | yacc, errors |
Hi Eric,
etetz@my-deja.com schrieb:
> When Bison encounters a syntax error it spits out "parse
> error". I want to give more descriptive error messages, such
> as "expecting semicolon after line 3". How would I go about this?
void yyerror(s)
char * s;
{
fprintf(stderr,"In file %s:\n",parsedFile);
fprintf(stderr,"%s, ",s);
fprintf(stderr,"Tokentext = <%s>\n",yytext);
}
parsedFile is a global variable. This solution does only work if there
is only one running instance of the parser and the lexer.
I haven't found/tried a way to provide line numbers yet but it seems
it is necessary to count the newlines in the lexer explicitly and to
store this info in yyloc with YYLTYPE .
Greetings,
Joachim
Return to the
comp.compilers page.
Search the
comp.compilers archives again.