Hi Imre,
please keep the mailing list in the loop.
As the documentation says, "%option bison-locations instruct flex that
GNU bison %locations are being used. This means yylex will be passed an
additional parameter, yylloc. This option implies %option bison-bridge".
On page 123 of the documentation you can see that yylex is added an
additional function parameter of type pointer to YYLTYPE. By default
bison hands over a pointer to a struct which is filled by the
YY_USER_ACTION() macro I sent you.
Good point about the location tracking. I guess, in this case you need
to reset it manually. Alternatively you can make flex generate a
reentrant scanner which generates the code to declare and reset yycolumn
for you. But this is slightly more complex, I guess.
Cheers, Martin
On 05/14/2010 09:48 PM, Imre Péntek wrote:
> Hello,
>
> What's the point in %option bison-locations then if I have to track the
> location anyways? I believe there should be built-in support for this.
>
> If I do this what will reset yycolumn to 1 on the beginning of a new line?
>
> %péntek 14 május 2010 18:51:35 dátummal Ön az alábbiakat írta:
>> Hi Imre,
>>
>> you need to extend your flex file to get location tracking going. My
>> suggestion:
>>
>> 1) Add "%option yylineno" to your flex file which ``directs flex to
>> generate a scanner that maintains the number of the current
>> line read from its input in the global variable yylineno''. (Details in
>> the flex manual)
>>
>> 2) Add something like this to your flex file:
>>
>> %{
>> int yycolumn = 1;
>>
>> #define YY_USER_ACTION { \
>> yylloc->first_line = yylineno; \
>> yylloc->last_line = yylineno; \
>> yylloc->first_column = yycolumn; \
>> yylloc->last_column = yycolumn + yyleng - 1; \
>> yycolumn += yyleng; }
>> %}
>>
>> This will update flex's line and columns counts in the location tracking
>> struct whenever bison reduces a production. Besides updating the struct,
>> the code also counts your columns.
>>
>>
>> Cheers, Martin
>>
>> On 05/14/2010 02:11 PM, Péntek Imre wrote:
>>> Hello, my first letter contained an ltcalc.tar.bz2 containing the code
>>> needed to compile both tests. Yes, my first test was fine but it
>>> contained a custom yylex, written by hand. The second test however
>>> contained a flex generated lexical parser and didn't worked as I
>>> expected it to work. So, I need further help, I attach again the codes.
>>> My question is what else should I do to make the second test
>>> ("ltcalc/with flex" dir) to work similar to the first one? Thank you for
>>> your help in advance.
>>>
>>> md5sums and file list:
>>> 99e9ba0f39d6ea5e52da422ca87ad229 ltcalc/orig/ltcalc.y
>>> dc454d644c14cba90b34a96e88334156 ltcalc/orig/Makefile
>>> 16a0505c1db86c8c04290dd52623dc3f ltcalc/with flex/ltcalc.y
>>> b752d70903b0aab32bc9be3dc43c42e3 ltcalc/with flex/Makefile
>>> 69474bf7f34c302a24f596e7a8eb04d1 ltcalc/with flex/ltcalc.l
>>>
>>> %péntek 14 május 2010 10:52:31 dátummal Ön az alábbiakat írta:
>>>> Hi Imre,
>>>>
>>>> I think your first test looks quite fine, doesn't it? Please attach your
>>>> source code in case you need further help.
>>>>
>>>> Cheers, Martin
>
|