Bison
The Bison parser expects to report the error by calling an error reporting function named "yyerror", which you must supply. It is called by "yyparse" whenever a syntax error is found, and it receives one argument. For a syntax error, the string is normally "syntax error".
If you invoke the directive "%error-verbose" in the Bison declarations section, then Bison provides a more verbose and specific error message string instead of just plain "syntax error".
Sounds good, right?
Well, no, not entirely.
syntax error, unexpected $undefined
Well, goody. Now I know what's going on.
note: yes, I do know that there are other ways to debug a Bison parser than just to use the parser error string. It's just that this could have been more useful, like, say, provide the line on which the error is found? The file I'm trying to parse here is pretty large, thank you very much.
The problem with that is that Bison doesn't know about lines -- all it gets to see is the stream of tokens that the scanner hands it, which usually does not deal in lines.
The way to fix this is to write the scanner such that it remembers where it is in terms of lines/columns of the input file, and to make that information available to the yyerror() function. This is of course less than optimal (depending on the language you're dealing with) but not something that Bison concerns itself with.
Anselm
It's been ages since I used bison, but IIRC you can get the line from flex (not from bison, which only sees a stream of tokens and has no clue where those came from). If not, then it's rather easy to add a flex rule to increment a line number counter on '\n'.
I gather that one of the advantages of a simple recursive-descent parser over yacc/bison is that it's easier (or should that be "possible") to provide sane error messages.
Line numbers are your problem. Yacc (bison) doesn't know of lines.
There are a number of ways to thread line number information through a Yacc parser. The simplest is just to have yyerror to acquire the line number information from the scanner (this may be off a bit due to lookahead).