mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 16:53:02 +00:00
* src/reader.c (copy_at, copy_dollarm parse_braces, parse_action)
(parse_guard): Rename the formal argument `stack_offset' as `rule_length', which is more readable. Adjust callers. (copy_at, copy_dollar): Instead of outputting the hard coded values of $$, $n and so forth, output invocation to b4_lhs_value, b4_lhs_location, b4_rhs_value, and b4_rhs_location. * data/bison.simple, data/bison.c++ (b4_lhs_value) (b4_lhs_location, b4_rhs_value, and b4_rhs_location: New.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
2002-05-02 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/reader.c (copy_at, copy_dollarm parse_braces, parse_action)
|
||||||
|
(parse_guard): Rename the formal argument `stack_offset' as
|
||||||
|
`rule_length', which is more readable.
|
||||||
|
Adjust callers.
|
||||||
|
(copy_at, copy_dollar): Instead of outputting the hard coded
|
||||||
|
values of $$, $n and so forth, output invocation to b4_lhs_value,
|
||||||
|
b4_lhs_location, b4_rhs_value, and b4_rhs_location.
|
||||||
|
* data/bison.simple, data/bison.c++ (b4_lhs_value)
|
||||||
|
(b4_lhs_location, b4_rhs_value, and b4_rhs_location: New.
|
||||||
|
|
||||||
2002-05-02 Akim Demaille <akim@epita.fr>
|
2002-05-02 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* configure.in (AC_INIT): Bump to 1.49b.
|
* configure.in (AC_INIT): Bump to 1.49b.
|
||||||
|
|||||||
1
TODO
1
TODO
@@ -1,6 +1,5 @@
|
|||||||
-*- outline -*-
|
-*- outline -*-
|
||||||
|
|
||||||
|
|
||||||
* Several %unions
|
* Several %unions
|
||||||
I think this is a pleasant (but useless currently) feature, but in the
|
I think this is a pleasant (but useless currently) feature, but in the
|
||||||
future, I want a means to %include other bits of grammars, and _then_
|
future, I want a means to %include other bits of grammars, and _then_
|
||||||
|
|||||||
@@ -20,6 +20,36 @@ m4_define([b4_uint_type],
|
|||||||
[m4_fatal([no unsigned int type for $1])])])
|
[m4_fatal([no unsigned int type for $1])])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_lhs_value([TYPE])
|
||||||
|
# --------------------
|
||||||
|
# Expansion of $<TYPE>$.
|
||||||
|
m4_define([b4_lhs_value],
|
||||||
|
[yyval[]m4_ifval([$1], [.$1])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
|
||||||
|
# --------------------------------------
|
||||||
|
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
|
||||||
|
# symbols on RHS.
|
||||||
|
m4_define([b4_rhs_value],
|
||||||
|
[yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_lhs_location()
|
||||||
|
# -----------------
|
||||||
|
# Expansion of @$.
|
||||||
|
m4_define([b4_lhs_location],
|
||||||
|
[yyloc])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_rhs_location(RULE-LENGTH, NUM)
|
||||||
|
# ---------------------------------
|
||||||
|
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
|
||||||
|
# on RHS.
|
||||||
|
m4_define([b4_rhs_location],
|
||||||
|
[yylsp@<:@m4_eval([$2 - $1])@:>@])
|
||||||
|
|
||||||
|
|
||||||
# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
|
# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER)
|
||||||
# ------------------------------------------
|
# ------------------------------------------
|
||||||
# Output the definition of this token as #define.
|
# Output the definition of this token as #define.
|
||||||
|
|||||||
@@ -20,6 +20,36 @@ m4_define([b4_uint_type],
|
|||||||
[m4_fatal([no unsigned int type for $1])])])
|
[m4_fatal([no unsigned int type for $1])])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_lhs_value([TYPE])
|
||||||
|
# --------------------
|
||||||
|
# Expansion of $<TYPE>$.
|
||||||
|
m4_define([b4_lhs_value],
|
||||||
|
[yyval[]m4_ifval([$1], [.$1])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
|
||||||
|
# --------------------------------------
|
||||||
|
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
|
||||||
|
# symbols on RHS.
|
||||||
|
m4_define([b4_rhs_value],
|
||||||
|
[yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_lhs_location()
|
||||||
|
# -----------------
|
||||||
|
# Expansion of @$.
|
||||||
|
m4_define([b4_lhs_location],
|
||||||
|
[yyloc])
|
||||||
|
|
||||||
|
|
||||||
|
# b4_rhs_location(RULE-LENGTH, NUM)
|
||||||
|
# ---------------------------------
|
||||||
|
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
|
||||||
|
# on RHS.
|
||||||
|
m4_define([b4_rhs_location],
|
||||||
|
[yylsp@<:@m4_eval([$2 - $1])@:>@])
|
||||||
|
|
||||||
|
|
||||||
m4_define_default([b4_input_suffix], [.y])
|
m4_define_default([b4_input_suffix], [.y])
|
||||||
|
|
||||||
m4_define_default([b4_output_parser_suffix],
|
m4_define_default([b4_output_parser_suffix],
|
||||||
|
|||||||
110
src/reader.c
110
src/reader.c
@@ -492,23 +492,22 @@ copy_comment (FILE *fin, struct obstack *oout)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------.
|
/*-------------------------------------------------------------------.
|
||||||
| FIN is pointing to a location (i.e., a `@'). Output to OOUT a |
|
| FIN is pointing to a location (i.e., a `@'). Output to OOUT a |
|
||||||
| reference to this location. STACK_OFFSET is the number of values |
|
| reference to this location. RULE_LENGTH is the number of values in |
|
||||||
| in the current rule so far, which says where to find `$0' with |
|
| the current rule so far, which says where to find `$0' with |
|
||||||
| respect to the top of the stack. |
|
| respect to the top of the stack. |
|
||||||
`-----------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
copy_at (FILE *fin, struct obstack *oout, int stack_offset)
|
copy_at (FILE *fin, struct obstack *oout, int rule_length)
|
||||||
{
|
{
|
||||||
int c;
|
int c = getc (fin);
|
||||||
|
locations_flag = 1;
|
||||||
|
|
||||||
c = getc (fin);
|
|
||||||
if (c == '$')
|
if (c == '$')
|
||||||
{
|
{
|
||||||
obstack_sgrow (oout, "yyloc");
|
obstack_sgrow (oout, "]b4_lhs_location[");
|
||||||
locations_flag = 1;
|
|
||||||
}
|
}
|
||||||
else if (isdigit (c) || c == '-')
|
else if (isdigit (c) || c == '-')
|
||||||
{
|
{
|
||||||
@@ -516,16 +515,11 @@ copy_at (FILE *fin, struct obstack *oout, int stack_offset)
|
|||||||
|
|
||||||
ungetc (c, fin);
|
ungetc (c, fin);
|
||||||
n = read_signed_integer (fin);
|
n = read_signed_integer (fin);
|
||||||
if (n > stack_offset)
|
if (n > rule_length)
|
||||||
complain (_("invalid value: %s%d"), "@", n);
|
complain (_("invalid value: %s%d"), "@", n);
|
||||||
else
|
else
|
||||||
{
|
obstack_fgrow2 (oout, "]b4_rhs_location([%d], [%d])[",
|
||||||
/* Offset is always 0 if parser has already popped the stack
|
rule_length, n);
|
||||||
pointer. */
|
|
||||||
obstack_fgrow1 (oout, "yylsp[%d]",
|
|
||||||
n - (semantic_parser ? 0 : stack_offset));
|
|
||||||
locations_flag = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -536,19 +530,19 @@ copy_at (FILE *fin, struct obstack *oout, int stack_offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| FIN is pointing to a wannabee semantic value (i.e., a `$'). |
|
| FIN is pointing to a wannabee semantic value (i.e., a `$'). |
|
||||||
| |
|
| |
|
||||||
| Possible inputs: $[<TYPENAME>]($|integer) |
|
| Possible inputs: $[<TYPENAME>]($|integer) |
|
||||||
| |
|
| |
|
||||||
| Output to OOUT a reference to this semantic value. STACK_OFFSET is |
|
| Output to OOUT a reference to this semantic value. RULE_LENGTH is |
|
||||||
| the number of values in the current rule so far, which says where |
|
| the number of values in the current rule so far, which says where |
|
||||||
| to find `$0' with respect to the top of the stack. |
|
| to find `$0' with respect to the top of the stack. |
|
||||||
`-------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
copy_dollar (FILE *fin, struct obstack *oout,
|
copy_dollar (FILE *fin, struct obstack *oout,
|
||||||
symbol_list *rule, int stack_offset)
|
symbol_list *rule, int rule_length)
|
||||||
{
|
{
|
||||||
int c = getc (fin);
|
int c = getc (fin);
|
||||||
const char *type_name = NULL;
|
const char *type_name = NULL;
|
||||||
@@ -564,15 +558,15 @@ copy_dollar (FILE *fin, struct obstack *oout,
|
|||||||
|
|
||||||
if (c == '$')
|
if (c == '$')
|
||||||
{
|
{
|
||||||
obstack_sgrow (oout, "yyval");
|
|
||||||
|
|
||||||
if (!type_name)
|
if (!type_name)
|
||||||
type_name = get_type_name (0, rule);
|
type_name = get_type_name (0, rule);
|
||||||
if (type_name)
|
|
||||||
obstack_fgrow1 (oout, ".%s", type_name);
|
|
||||||
if (!type_name && typed)
|
if (!type_name && typed)
|
||||||
complain (_("$$ of `%s' has no declared type"),
|
complain (_("$$ of `%s' has no declared type"),
|
||||||
rule->sym->tag);
|
rule->sym->tag);
|
||||||
|
if (!type_name)
|
||||||
|
type_name = "";
|
||||||
|
obstack_fgrow1 (oout,
|
||||||
|
"]b4_lhs_value([%s])[", type_name);
|
||||||
}
|
}
|
||||||
else if (isdigit (c) || c == '-')
|
else if (isdigit (c) || c == '-')
|
||||||
{
|
{
|
||||||
@@ -580,23 +574,19 @@ copy_dollar (FILE *fin, struct obstack *oout,
|
|||||||
ungetc (c, fin);
|
ungetc (c, fin);
|
||||||
n = read_signed_integer (fin);
|
n = read_signed_integer (fin);
|
||||||
|
|
||||||
if (n > stack_offset)
|
if (n > rule_length)
|
||||||
complain (_("invalid value: %s%d"), "$", n);
|
complain (_("invalid value: %s%d"), "$", n);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!type_name && n > 0)
|
if (!type_name && n > 0)
|
||||||
type_name = get_type_name (n, rule);
|
type_name = get_type_name (n, rule);
|
||||||
|
|
||||||
/* Offset is always 0 if parser has already popped the stack
|
|
||||||
pointer. */
|
|
||||||
obstack_fgrow1 (oout, "yyvsp[%d]",
|
|
||||||
n - (semantic_parser ? 0 : stack_offset));
|
|
||||||
|
|
||||||
if (type_name)
|
|
||||||
obstack_fgrow1 (oout, ".%s", type_name);
|
|
||||||
if (!type_name && typed)
|
if (!type_name && typed)
|
||||||
complain (_("$%d of `%s' has no declared type"),
|
complain (_("$%d of `%s' has no declared type"),
|
||||||
n, rule->sym->tag);
|
n, rule->sym->tag);
|
||||||
|
if (!type_name)
|
||||||
|
type_name = "";
|
||||||
|
obstack_fgrow3 (oout, "]b4_rhs_value([%d], [%d], [%s])[",
|
||||||
|
rule_length, n, type_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1277,19 +1267,19 @@ read_declarations (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Assuming that a `{' has just been seen, copy everything up to the |
|
| Assuming that a `{' has just been seen, copy everything up to the |
|
||||||
| matching `}' into the actions file. STACK_OFFSET is the number of |
|
| matching `}' into the actions file. RULE_LENGTH is the number of |
|
||||||
| values in the current rule so far, which says where to find `$0' |
|
| values in the current rule so far, which says where to find `$0' |
|
||||||
| with respect to the top of the stack. |
|
| with respect to the top of the stack. |
|
||||||
| |
|
| |
|
||||||
| This routine is used both for actions and guards. Only |
|
| This routine is used both for actions and guards. Only |
|
||||||
| ACTION_OBSTACK is used, but this is fine, since we use only |
|
| ACTION_OBSTACK is used, but this is fine, since we use only |
|
||||||
| pointers to relevant portions inside this obstack. |
|
| pointers to relevant portions inside this obstack. |
|
||||||
`-------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_braces (symbol_list *rule, int stack_offset)
|
parse_braces (symbol_list *rule, int rule_length)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
int count;
|
int count;
|
||||||
@@ -1320,13 +1310,11 @@ parse_braces (symbol_list *rule, int stack_offset)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '$':
|
case '$':
|
||||||
copy_dollar (finput, &action_obstack,
|
copy_dollar (finput, &action_obstack, rule, rule_length);
|
||||||
rule, stack_offset);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '@':
|
case '@':
|
||||||
copy_at (finput, &action_obstack,
|
copy_at (finput, &action_obstack, rule_length);
|
||||||
stack_offset);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EOF:
|
case EOF:
|
||||||
@@ -1346,22 +1334,22 @@ parse_braces (symbol_list *rule, int stack_offset)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_action (symbol_list *rule, int stack_offset)
|
parse_action (symbol_list *rule, int rule_length)
|
||||||
{
|
{
|
||||||
rule->action_line = lineno;
|
rule->action_line = lineno;
|
||||||
parse_braces (rule, stack_offset);
|
parse_braces (rule, rule_length);
|
||||||
rule->action = obstack_finish (&action_obstack);
|
rule->action = obstack_finish (&action_obstack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_guard (symbol_list *rule, int stack_offset)
|
parse_guard (symbol_list *rule, int rule_length)
|
||||||
{
|
{
|
||||||
token_t t = lex ();
|
token_t t = lex ();
|
||||||
if (t != tok_left_curly)
|
if (t != tok_left_curly)
|
||||||
complain (_("invalid %s declaration"), "%guard");
|
complain (_("invalid %s declaration"), "%guard");
|
||||||
rule->guard_line = lineno;
|
rule->guard_line = lineno;
|
||||||
parse_braces (rule, stack_offset);
|
parse_braces (rule, rule_length);
|
||||||
rule->guard = obstack_finish (&action_obstack);
|
rule->guard = obstack_finish (&action_obstack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user