help-bison
[Top][All Lists]
Advanced

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

location tracking for the empty rule without prior symbol


From: Bill Allombert
Subject: location tracking for the empty rule without prior symbol
Date: Fri, 26 Jun 2009 19:34:30 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Hello GNU Bison people,

I am using location tracking. While it works great in general, there
is a corner case where I am unsure about the intended behaviour of
bison and how the program should handle it.

The issue is related to the value of @$ for the first reduction when the rule
involved has no components.

For example if the grammar is
%%
seq: /* empty */ {printf("empty: (%d, %d)\n",@$.first_line,@$.first_column);}
   | seq item
;
item: '(' seq ')'
;
%%
and the text to parse is "()", then the first reduction will involve the
rule {seq : /* empty */} for which N=0, but there is no symbol prior to
the reduction. 

What is the output of this program according to the specification ?

Is it different for a custom YYLTYPE and/or a custom YYLLOC_DEFAULT ?

Looking at the parser code I see:
#if YYLTYPE_IS_TRIVIAL
  /* Initialize the default location before parsing starts.  */
  yylloc.first_line   = yylloc.last_line   = 1;
  yylloc.first_column = yylloc.last_column = 0;
#endif
which imply that the default YYLTYPE is handled specially.

Is there a way I can initialize a custom YYLTYPE ?

The parser involved is used by PARI/GP version 2.4.2 and up. The relevant
grammar file is available at
http://pari.math.u-bordeaux.fr/cgi-bin/viewcvs.cgi/trunk/src/language/parse.y?root=pari&view=markup

Cheers,
Bill.  (Please CC me)




reply via email to

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