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: Fri, 4 Jan 2002 02:14:41 +0100

At 12:22 -0800 2002/01/03, John W. Millaway wrote:
>> 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.
>
>That will fail when yyin == stdin. Why not just record the column number
>instead?

Why will this fail? Using ftell also on stdin will give a position number.
Is \n zipped out or something?

The idea was otherwise just that if the file C/C++ file structure already
keeps track of the position, one can use that, and compute the column
number from that. This might be faster than trying to keep track of the
column number.

But if the Flex generated lexer is already keeping track of character count
internally, perhaps there is no point in doing that.

But if one wants the position number of a stream, then one must use ftell,
because otherwise the error location will not be correct. In a IDE GUI
error message display, the wrong section will be highlighted.

>> 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 generalize on this a bit, we need a macro that executes just before a
>return
>from a user action. But this is a big of a fish to fry (detecting a return
>statement in actions). Instead, I usually define YY_RETURN, and use that
>instead of a normal 'return' statement.

I thought this also at first, but does it not suffice that the
YY_LOCATION_END macro executes just _before_ the user action starts: One
has then finished scanning, and the macro is only intended for use with
recording the location. Also, then one has access to whatever
YY_LOCATION_END executes which might be used for further processing in the
action if needed.

  Hans Aberg





reply via email to

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