mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 00:03:03 +00:00
In Bison 1.875's yacc.c, YYLLOC_DEFAULT was called regardless
whether the reducion was empty or not. This leaves room to improve the use of YYLLOC_DEFAULT in such a case. lalr1.cc is still experimental, so changing this is acceptable. And finally, there are probably not many users who changed the handling of locations in GLR, so changing is admissible too. * data/glr.c, data/lalr1.cc, data/yacc.c (YYLLOC_DEFAULT): On an empty reduction, set @$ to an empty location ending the previously stacked symbol. Adjust uses to make sure the code is triggered on empty reductions. * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Adjust the expected output: empty reductions have empty locations.
This commit is contained in:
17
ChangeLog
17
ChangeLog
@@ -1,3 +1,20 @@
|
|||||||
|
2004-10-05 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
In Bison 1.875's yacc.c, YYLLOC_DEFAULT was called regardless
|
||||||
|
whether the reducion was empty or not. This leaves room to
|
||||||
|
improve the use of YYLLOC_DEFAULT in such a case.
|
||||||
|
lalr1.cc is still experimental, so changing this is acceptable.
|
||||||
|
And finally, there are probably not many users who changed the
|
||||||
|
handling of locations in GLR, so changing is admissible too.
|
||||||
|
|
||||||
|
* data/glr.c, data/lalr1.cc, data/yacc.c (YYLLOC_DEFAULT): On an
|
||||||
|
empty reduction, set @$ to an empty location ending the previously
|
||||||
|
stacked symbol.
|
||||||
|
Adjust uses to make sure the code is triggered on empty
|
||||||
|
reductions.
|
||||||
|
* tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): Adjust the
|
||||||
|
expected output: empty reductions have empty locations.
|
||||||
|
|
||||||
2004-09-29 Akim Demaille <akim@epita.fr>
|
2004-09-29 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* data/lalr1.cc: Move towards a more standard C++ coding style
|
* data/lalr1.cc: Move towards a more standard C++ coding style
|
||||||
|
|||||||
37
data/glr.c
37
data/glr.c
@@ -420,17 +420,31 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] =
|
|||||||
/* Error token number */
|
/* Error token number */
|
||||||
#define YYTERROR 1
|
#define YYTERROR 1
|
||||||
|
|
||||||
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. */
|
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
|
||||||
|
If N is 0, then set CURRENT to the empty location which ends
|
||||||
|
the previous symbol: RHS[0] (always defined). */
|
||||||
|
|
||||||
]b4_location_if([[
|
]b4_location_if([[
|
||||||
#define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK].yystate.yyloc)
|
#define YYRHSLOC(yyRhs,YYK) ((yyRhs)[YYK].yystate.yyloc)
|
||||||
|
|
||||||
#ifndef YYLLOC_DEFAULT
|
#ifndef YYLLOC_DEFAULT
|
||||||
# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
|
# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
|
||||||
((yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line, \
|
do { \
|
||||||
(yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column, \
|
if (YYN) \
|
||||||
(yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line, \
|
{ \
|
||||||
(yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column)
|
(yyCurrent).first_line = YYRHSLOC(yyRhs, 1).first_line; \
|
||||||
|
(yyCurrent).first_column = YYRHSLOC(yyRhs, 1).first_column; \
|
||||||
|
(yyCurrent).last_line = YYRHSLOC(yyRhs, YYN).last_line; \
|
||||||
|
(yyCurrent).last_column = YYRHSLOC(yyRhs, YYN).last_column; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
(yyCurrent).first_line = YYRHSLOC(yyRhs, 0).last_line; \
|
||||||
|
(yyCurrent).first_column = YYRHSLOC(yyRhs, 0).last_column; \
|
||||||
|
(yyCurrent).last_line = YYRHSLOC(yyRhs, 0).last_line; \
|
||||||
|
(yyCurrent).last_column = YYRHSLOC(yyRhs, 0).last_column; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
/* YY_LOCATION_PRINT -- Print the location on the stream.
|
/* YY_LOCATION_PRINT -- Print the location on the stream.
|
||||||
This macro was not mandated originally: define only if we know
|
This macro was not mandated originally: define only if we know
|
||||||
@@ -718,15 +732,10 @@ yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
|
|||||||
|
|
||||||
yylow = 1;
|
yylow = 1;
|
||||||
if (yyrhslen == 0)
|
if (yyrhslen == 0)
|
||||||
{
|
*yyvalp = yyval_default;
|
||||||
*yyvalp = yyval_default;
|
|
||||||
*yylocp = yyvsp[0].yystate.yyloc;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
|
||||||
*yyvalp = yyvsp[YYFILL (1-yyrhslen)].yystate.yysemantics.yysval;
|
YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen);
|
||||||
YYLLOC_DEFAULT (*yylocp, yyvsp - yyrhslen, yyrhslen);
|
|
||||||
}
|
|
||||||
|
|
||||||
]
|
]
|
||||||
switch (yyn)
|
switch (yyn)
|
||||||
|
|||||||
@@ -181,13 +181,22 @@ b4_syncline([@oline@], [@ofile@])],
|
|||||||
|
|
||||||
]/* Line __line__ of lalr1.cc. */
|
]/* Line __line__ of lalr1.cc. */
|
||||||
b4_syncline([@oline@], [@ofile@])[
|
b4_syncline([@oline@], [@ofile@])[
|
||||||
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. */
|
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
|
||||||
|
If N is 0, then set CURRENT to the empty location which ends
|
||||||
|
the previous symbol: RHS[0] (always defined). */
|
||||||
|
|
||||||
#ifndef YYLLOC_DEFAULT
|
#ifndef YYLLOC_DEFAULT
|
||||||
# define YYLLOC_DEFAULT(Current, Rhs, N) \
|
# define YYLLOC_DEFAULT(Current, Rhs, N) \
|
||||||
do { \
|
do { \
|
||||||
((Current).begin = (Rhs)[1].begin); \
|
if (N) \
|
||||||
((Current).end = (Rhs)[N].end); \
|
{ \
|
||||||
|
(Current).begin = (Rhs)[1].begin; \
|
||||||
|
(Current).end = (Rhs)[N].end; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
(Current).begin = (Current).end = (Rhs)[0].end; \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -583,21 +592,14 @@ yyreduce:
|
|||||||
This behavior is undocumented and Bison
|
This behavior is undocumented and Bison
|
||||||
users should not rely upon it. */
|
users should not rely upon it. */
|
||||||
if (len_)
|
if (len_)
|
||||||
{
|
yyval = semantic_stack_[len_ - 1];
|
||||||
yyval = semantic_stack_[len_ - 1];
|
|
||||||
yyloc = location_stack_[len_ - 1];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
yyval = semantic_stack_[0];
|
||||||
yyval = semantic_stack_[0];
|
|
||||||
yyloc = location_stack_[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len_)
|
{
|
||||||
{
|
Slice<LocationType, LocationStack> slice (location_stack_, len_);
|
||||||
Slice<LocationType, LocationStack> slice (location_stack_, len_);
|
YYLLOC_DEFAULT (yyloc, slice, len_);
|
||||||
YYLLOC_DEFAULT (yyloc, slice, len_);
|
}
|
||||||
}
|
|
||||||
YY_REDUCE_PRINT (n_);
|
YY_REDUCE_PRINT (n_);
|
||||||
switch (n_)
|
switch (n_)
|
||||||
{
|
{
|
||||||
|
|||||||
29
data/yacc.c
29
data/yacc.c
@@ -506,14 +506,26 @@ while (0)
|
|||||||
#define YYERRCODE 256
|
#define YYERRCODE 256
|
||||||
|
|
||||||
|
|
||||||
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. */
|
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
|
||||||
|
If N is 0, then set CURRENT to the empty location which ends
|
||||||
|
the previous symbol: RHS[0] (always defined). */
|
||||||
|
|
||||||
#ifndef YYLLOC_DEFAULT
|
#ifndef YYLLOC_DEFAULT
|
||||||
# define YYLLOC_DEFAULT(Current, Rhs, N) \
|
# define YYLLOC_DEFAULT(Current, Rhs, N) \
|
||||||
((Current).first_line = (Rhs)[1].first_line, \
|
do { \
|
||||||
(Current).first_column = (Rhs)[1].first_column, \
|
if (N) \
|
||||||
(Current).last_line = (Rhs)[N].last_line, \
|
{ \
|
||||||
(Current).last_column = (Rhs)[N].last_column)
|
(Current).first_line = (Rhs)[1].first_line; \
|
||||||
|
(Current).first_column = (Rhs)[1].first_column; \
|
||||||
|
(Current).last_line = (Rhs)[N].last_line; \
|
||||||
|
(Current).last_column = (Rhs)[N].last_column; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
(Current).first_line = (Current).last_line = (Rhs)[0].last_line; \
|
||||||
|
(Current).first_column = (Current).last_column = (Rhs)[0].last_column; \
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -1021,10 +1033,7 @@ yyreduce:
|
|||||||
|
|
||||||
]b4_location_if(
|
]b4_location_if(
|
||||||
[[ /* Default location. */
|
[[ /* Default location. */
|
||||||
if (yylen)
|
YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);]])[
|
||||||
YYLLOC_DEFAULT (yyloc, yylsp - yylen, yylen);
|
|
||||||
else
|
|
||||||
yyloc = yylsp[0];]])[
|
|
||||||
YY_REDUCE_PRINT (yyn);
|
YY_REDUCE_PRINT (yyn);
|
||||||
switch (yyn)
|
switch (yyn)
|
||||||
]{
|
]{
|
||||||
|
|||||||
@@ -372,8 +372,8 @@ thing (1@10-19): 'x' (1@10-19)
|
|||||||
sending: ')' (2@20-29)
|
sending: ')' (2@20-29)
|
||||||
line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
|
line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
|
||||||
sending: EOF (3@30-39)
|
sending: EOF (3@30-39)
|
||||||
input (0@0-29): /* Nothing */
|
input (0@29-29): /* Nothing */
|
||||||
input (2@0-29): line (0@0-29) input (0@0-29)
|
input (2@0-29): line (0@0-29) input (0@29-29)
|
||||||
Successful parse.
|
Successful parse.
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -390,8 +390,8 @@ Freeing token 'y' (1@10-19)
|
|||||||
sending: ')' (2@20-29)
|
sending: ')' (2@20-29)
|
||||||
line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
|
line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
|
||||||
sending: EOF (3@30-39)
|
sending: EOF (3@30-39)
|
||||||
input (0@0-29): /* Nothing */
|
input (0@29-29): /* Nothing */
|
||||||
input (2@0-29): line (-1@0-29) input (0@0-29)
|
input (2@0-29): line (-1@0-29) input (0@29-29)
|
||||||
Successful parse.
|
Successful parse.
|
||||||
]])
|
]])
|
||||||
|
|
||||||
@@ -438,8 +438,8 @@ thing (11@110-119): 'x' (11@110-119)
|
|||||||
sending: ')' (12@120-129)
|
sending: ')' (12@120-129)
|
||||||
line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
|
line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
|
||||||
sending: 'y' (13@130-139)
|
sending: 'y' (13@130-139)
|
||||||
input (0@100-129): /* Nothing */
|
input (0@129-129): /* Nothing */
|
||||||
input (2@100-129): line (10@100-129) input (0@100-129)
|
input (2@100-129): line (10@100-129) input (0@129-129)
|
||||||
input (2@70-129): line (7@70-99) input (2@100-129)
|
input (2@70-129): line (7@70-99) input (2@100-129)
|
||||||
input (2@0-129): line (-1@0-69) input (2@70-129)
|
input (2@0-129): line (-1@0-69) input (2@70-129)
|
||||||
130-139: syntax error, unexpected 'y', expecting $end
|
130-139: syntax error, unexpected 'y', expecting $end
|
||||||
|
|||||||
Reference in New Issue
Block a user