Re: Source locations with Flex+Bison

Laurence Finston <>
2 Apr 2005 19:32:51 -0500

          From comp.compilers

Related articles
Source locations with Flex+Bison (Bjarni Juliusson) (2005-03-31)
Re: Source locations with Flex+Bison (Laurence Finston) (2005-04-02)
| List of all articles for this month |

From: Laurence Finston <>
Newsgroups: comp.compilers
Date: 2 Apr 2005 19:32:51 -0500
Organization: GWDG, Goettingen
References: 05-03-132
Keywords: errors, lex
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'.

Laurence Finston

Post a followup to this message

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