help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Locations suggest


From: Hans Aberg
Subject: Re: Locations suggest
Date: Thu, 3 Jan 2002 20:49:49 +0100

At 15:48 +0100 2002/01/03, Akim Demaille wrote:
>>>> One should perhaps equip Flex with better token location
>>>> recording, for use with error messages, etc:
>>> Good idea.
>
>Hans> Thank you. :-)
>
>I think it is not a good because there are too many different ways
>locations have to be computed.

So then there should probably be some macros covering up the more common
cases, but with the ability to change, just as in say Bison. Does the
adding of these features in any way prevent you to write your own code?

Also, there is the chance to tune Flex and Bison together now. So if there
is known a better location recording system, that could be added to Bison
as well.

>  And yet for the sole yylineno, flex is
>not satisfying.  Rather, you should depend on the various hooks to
>have your scanner compute what you need.  See the following.

If you think there is a bug in the Flex yylineno, or a way to speed it up,
then that should of course be implemented into Flex.

One way to implement the column number might be to every time a newline
'\n' is encountered, its file position number is recorded. From that file
position number and the current file position number, the column number can
be computed.

A generalization might be to merely have a macro YY_USER_NEWLINE that is
executed every time a newline is encountered.

>----------------------------------------------------------------------
>
>Advanced Use of Flex
>--------------------
...

The idea should though be that one does not have to litter the Flex .l code
with stuff you have written: It should be hidden away, so that the actions
can concentrate on their actual semantic values.

It seems me that Flex needs to provide:

- A macro that is executed at the beginning of each identified token sequence.
- A macro that is executed at the end of each identified token sequence.
- Optional ways to keep track of the location data: Line, column and file
position numbers.

It seems me that this should be possible to do:

It is already possible to have an action executed before any scanning takes
place, and YY_USER_ACTION can be used to record the location after the
scanning has been done. Perhaps one should add special YY_LOCATION_BEGIN
and YY_LOCATION_END macros.

To that add improved line/column/position number recording.

  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]