help-bison
[Top][All Lists]
Advanced

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

Re: how to work with Bison locations?


From: Kynn Jones
Subject: Re: how to work with Bison locations?
Date: Wed, 3 Jun 2009 12:12:33 -0400

On Wed, Jun 3, 2009 at 1:28 AM, Luca <address@hidden> wrote:
> Location are created by lexer and "reduced" by the parser, so you have to
> create them using the lexer:
>
> #define YY_USER_ACTION {yylloc.first_line = yylineno; yylloc.first_column =
> colnum; colnum=colnum+yyleng; yylloc.last_column=colnum; yylloc.last_line =
> yylineno;}
>
> this macro is executed at each token recognized by lex. Insert it in bug.l
> inside %{}%; you have to define and manage colnum, yylineno is automatically
> defined by flex.
> You can access to location using @ from parser actions, or using yylloc from
> flex.
>
>
> You can also redefine, if you need, YYLTYPE (user custom locations, for
> example to add a field to the struct to track also file location),
> YYLLOC_DEFAULT (to merge locations) and YY_LOCATION_PRINT (to print
> locations) without any trouble.
> You have to redefine those macro BEFORE to include y.tab.h  otherwise the
> compiler will complain.

Thanks!  These tips helped a great deal!

Kynn




reply via email to

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