[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: glr & locations
From: |
Claudia Hermann |
Subject: |
Re: glr & locations |
Date: |
Sat, 29 Oct 2005 17:30:17 +0200 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
Paul Hilfinger wrote:
On Fri, 28 Oct 2005, Claudia Hermann wrote:
i have a parser with glr activated and use the location tracking
function. every things works fine as long as i don't use
ambiguous rules where i have to choose between with '%dprec'.
additionally i have an optional nonterminal at the beginning of
the rule. in this special case i get undefined values for the
optional nonterminal as well as for the whole rule.
...
It's a bug in bison still in the latest CVS sources.
YYLLOC_DEFAULT is supposed to copy the location for an empty non-terminal
from the location of the previous symbol, but the current implementation
loses that location during a split GLR parse.
The following patch works for me, and passes make check. However, I
haven't really had time to properly test it.
this patch works fine as long as i do not call yyparse() twice and only
use the default YYLTYPE declaration. but once i redeclare YYLTYPE and
YYLLOC_DEFAULT and activate glr-parser, as first value of the first node
i get the last value of the last node of the previous parsed file.
see also attached file
regards,
claudia hermann
%{
#if ! defined (YYLTYPE)
typedef struct yyltype {
long int first_pos;
long int last_pos;
} yyltype;
#define YYLTYPE yyltype
#endif
#ifndef YYLLOC_DEFAULT
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) { \
(Current).first_pos = YYRHSLOC (Rhs, 1).first_pos; \
(Current).last_pos = YYRHSLOC (Rhs, N).last_pos; \
} \
else { \
(Current).first_pos = (Current).last_pos = \
YYRHSLOC (Rhs, 0).last_pos; \
} \
while (0)
#endif
static void yyerror(const char *msg);
int i = 0;
%}
%token T_PORT
%token T_SIGNAL
%glr-parser
%%
DesignUnit : ContextClause LibraryUnit
{ printf("%d/%d, %d/%d\n", @1.first_pos, @1.last_pos,
@2.first_pos, @2.last_pos); }
;
LibraryUnit : T_PORT
;
ContextClause : /* empty */
| ContextClause ContextItem
;
ContextItem : T_SIGNAL
;
%%
static void yyerror(const char *msg) {
printf ("error\n");
}
int yylex() {
if (i == 0) {
yylloc.first_pos = 0;
yylloc.last_pos = 8;
i++;
return T_SIGNAL;
}
if (i == 1) {
yylloc.first_pos = 10;
yylloc.last_pos = 14;
i++;
return T_PORT;
}
return 0;
}
int main (int argc, const char *argv[]) {
yyparse();
i = 0;
yyparse();
return 0;
}