Re: YACC: syntax errors

snicol@apk.net (Scott Nicol)
17 Jan 1997 23:27:41 -0500

          From comp.compilers

Related articles
YACC: syntax errors gclind01@starbase.spd.louisville.edu (1997-01-16)
Re: YACC: syntax errors snicol@apk.net (1997-01-17)
Re: YACC: syntax errors zeller@fh-heilbronn.de (Henner Zeller) (1997-01-19)
| List of all articles for this month |
From: snicol@apk.net (Scott Nicol)
Newsgroups: comp.compilers
Date: 17 Jan 1997 23:27:41 -0500
Organization: APK Net, Ltd.
References: 97-01-132
Keywords: yacc, errors

gclind01@starbase.spd.louisville.edu says...
>Is there any way of getting detailed error information out of YACC...
>so I can get more specific about syntax errors than just putting out
>a 'syntax error' message? I've tried using the 'error' keyword
>but even using it sparsely comes up with a lot of reduce/reduce conflicts.
>
>David
>[Not without hacking the generated parser, which many people have done.
-John]


Yes, you can hack the parser to look at the debug information
(i.e. the stuff generated to y.output) so that it can report what
tokens would have been acceptable in the current state, but that could
be a long list and might not be too useful. If you suggest what the
error might be, you could end up confusing the programmer even more if
the suggestion isn't correct.


I prefer error messages that just say:


foo.c line 50: Syntax error near "flub"


Nothing too suggestive or direct, unless you know for sure what the
error is.


The easiest way to do this is to write your own yyerror(). In your
yyerror(), print the current filename (you should know this, set a
variable whenever you open yyin) and line number (undocumented but
available from most lex implementations as yylineno), and the last
text read in (yytext).
--
Scott Nicol
snicol@apk.net
http://junior.apk.net/~snicol/
--


Post a followup to this message

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