|Source locations with Flex+Bison email@example.com (Bjarni Juliusson) (2005-03-31)|
|Re: Source locations with Flex+Bison firstname.lastname@example.org (Laurence Finston) (2005-04-02)|
|From:||Laurence Finston <email@example.com>|
|Date:||2 Apr 2005 19:32:51 -0500|
|Posted-Date:||02 Apr 2005 19:32:50 EST|
On Fri, 31 Mar 2005, Bjarni Juliusson wrote:
> The problem:
> I have a lexer, written for Flex, and a parser, written for Bison. Now I
> want the source code locations of the tokens to be propagated up to the
> parser to allow meaningful error messages.
> I have no reason to make the parser pure, by the way.
I recommend always generating a pure parser. Even if you don't want
to use multiple threads or processes now, you might want to in the
future. I find the extra effort of making functions (including
`yylex()' and `yyparse()') thread-safe and/or reentrant is minimal in
comparison to the potential benefits. In addition, with Bison, you
can pass a parameter to `yyparse()' when you generate a pure parser; a
feature I find extremely useful.
I don't remember the details of using locations, since I haven't been
working on this part of my package lately. However, if you want an
example, you may examine my code. It's available at:
I define `YYLTYPE' in the file
It's also used in the files `pfuncfin.w', `scan.web',
and `scanprsf.web' in the same directory.
You can find examples of using locations in parser rules in
the files `pcondit.w' and `pnumexpr.w'.
Return to the
Search the comp.compilers archives again.