mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
* src/files.c, src/files.h (guard_obstack): Remove.
* src/output.c (output): Adjust. * src/reader.c (parse_braces): New, factoring... (copy_action, copy_guard): these two which are renamed as... (parse_action, parse_guard): these. As a voluntary consequence, using braces around guards is now mandatory.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
|||||||
|
2001-12-27 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/files.c, src/files.h (guard_obstack): Remove.
|
||||||
|
* src/output.c (output): Adjust.
|
||||||
|
* src/reader.c (parse_braces): New, factoring...
|
||||||
|
(copy_action, copy_guard): these two which are renamed as...
|
||||||
|
(parse_action, parse_guard): these.
|
||||||
|
As a voluntary consequence, using braces around guards is now
|
||||||
|
mandatory.
|
||||||
|
|
||||||
|
|
||||||
2001-12-27 Akim Demaille <akim@epita.fr>
|
2001-12-27 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/gram.h (rule_t): `guard' and `guard_line' are new members.
|
* src/gram.h (rule_t): `guard' and `guard_line' are new members.
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ FILE *finput = NULL;
|
|||||||
|
|
||||||
struct obstack action_obstack;
|
struct obstack action_obstack;
|
||||||
struct obstack attrs_obstack;
|
struct obstack attrs_obstack;
|
||||||
struct obstack guard_obstack;
|
|
||||||
struct obstack output_obstack;
|
struct obstack output_obstack;
|
||||||
|
|
||||||
char *spec_outfile = NULL; /* for -o. */
|
char *spec_outfile = NULL; /* for -o. */
|
||||||
|
|||||||
@@ -52,9 +52,6 @@ extern struct obstack action_obstack;
|
|||||||
/* If semantic parser, output a .h file that defines YYSTYPE... */
|
/* If semantic parser, output a .h file that defines YYSTYPE... */
|
||||||
extern struct obstack attrs_obstack;
|
extern struct obstack attrs_obstack;
|
||||||
|
|
||||||
/* ... and output yyguard, containing all the guard code. */
|
|
||||||
extern struct obstack guard_obstack;
|
|
||||||
|
|
||||||
/* The verbose output. */
|
/* The verbose output. */
|
||||||
extern struct obstack output_obstack;
|
extern struct obstack output_obstack;
|
||||||
|
|
||||||
|
|||||||
@@ -1128,6 +1128,5 @@ output (void)
|
|||||||
obstack_free (&muscle_obstack, NULL);
|
obstack_free (&muscle_obstack, NULL);
|
||||||
obstack_free (&format_obstack, NULL);
|
obstack_free (&format_obstack, NULL);
|
||||||
obstack_free (&action_obstack, NULL);
|
obstack_free (&action_obstack, NULL);
|
||||||
obstack_free (&guard_obstack, NULL);
|
|
||||||
obstack_free (&attrs_obstack, NULL);
|
obstack_free (&attrs_obstack, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
184
src/reader.c
184
src/reader.c
@@ -1080,10 +1080,14 @@ read_declarations (void)
|
|||||||
| matching `}' into the actions file. STACK_OFFSET is the number of |
|
| matching `}' into the actions file. STACK_OFFSET 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 the |
|
||||||
|
| actions_obstack is used, but this is fine, since we use only |
|
||||||
|
| pointers to relevant portions inside this obstack. |
|
||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
copy_action (symbol_list *rule, int stack_offset)
|
parse_braces (symbol_list *rule, int stack_offset)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
int count;
|
int count;
|
||||||
@@ -1093,57 +1097,48 @@ copy_action (symbol_list *rule, int stack_offset)
|
|||||||
stack_offset = 0;
|
stack_offset = 0;
|
||||||
|
|
||||||
count = 1;
|
count = 1;
|
||||||
c = getc (finput);
|
|
||||||
|
|
||||||
rule->action_line = lineno;
|
|
||||||
|
|
||||||
while (count > 0)
|
while (count > 0)
|
||||||
{
|
{
|
||||||
while (c != '}')
|
while ((c = getc (finput)) != '}')
|
||||||
{
|
switch (c)
|
||||||
switch (c)
|
{
|
||||||
{
|
case '\n':
|
||||||
case '\n':
|
obstack_1grow (&action_obstack, c);
|
||||||
obstack_1grow (&action_obstack, c);
|
lineno++;
|
||||||
lineno++;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
obstack_1grow (&action_obstack, c);
|
obstack_1grow (&action_obstack, c);
|
||||||
count++;
|
count++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
case '"':
|
case '"':
|
||||||
copy_string (finput, &action_obstack, c);
|
copy_string (finput, &action_obstack, c);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '/':
|
case '/':
|
||||||
copy_comment (finput, &action_obstack);
|
copy_comment (finput, &action_obstack);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '$':
|
case '$':
|
||||||
copy_dollar (finput, &action_obstack,
|
copy_dollar (finput, &action_obstack,
|
||||||
rule, stack_offset);
|
rule, stack_offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '@':
|
case '@':
|
||||||
copy_at (finput, &action_obstack,
|
copy_at (finput, &action_obstack,
|
||||||
stack_offset);
|
stack_offset);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EOF:
|
case EOF:
|
||||||
fatal (_("unmatched %s"), "`{'");
|
fatal (_("unmatched %s"), "`{'");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
obstack_1grow (&action_obstack, c);
|
obstack_1grow (&action_obstack, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
c = getc (finput);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* above loop exits when c is '}' */
|
|
||||||
|
|
||||||
|
/* Above loop exits when C is '}'. */
|
||||||
if (--count)
|
if (--count)
|
||||||
{
|
{
|
||||||
obstack_1grow (&action_obstack, c);
|
obstack_1grow (&action_obstack, c);
|
||||||
@@ -1152,91 +1147,29 @@ copy_action (symbol_list *rule, int stack_offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
obstack_1grow (&action_obstack, '\0');
|
obstack_1grow (&action_obstack, '\0');
|
||||||
rule->action = obstack_finish (&action_obstack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------.
|
|
||||||
| After `%guard' is seen in the input file, copy the actual guard |
|
|
||||||
| into the guards file. If the guard is followed by an action, copy |
|
|
||||||
| that into the actions file. STACK_OFFSET is the number of values |
|
|
||||||
| in the current rule so far, which says where to find `$0' with |
|
|
||||||
| respect to the top of the stack, for the simple parser in which |
|
|
||||||
| the stack is not popped until after the guard is run. |
|
|
||||||
`-------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
copy_guard (symbol_list *rule, int stack_offset)
|
parse_action (symbol_list *rule, int stack_offset)
|
||||||
{
|
{
|
||||||
int c;
|
rule->action_line = lineno;
|
||||||
int count;
|
parse_braces (rule, stack_offset);
|
||||||
int brace_flag = 0;
|
rule->action = obstack_finish (&action_obstack);
|
||||||
|
|
||||||
/* offset is always 0 if parser has already popped the stack pointer */
|
|
||||||
if (semantic_parser)
|
|
||||||
stack_offset = 0;
|
|
||||||
|
|
||||||
rule->guard_line = lineno;
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
c = getc (finput);
|
|
||||||
|
|
||||||
while (brace_flag ? (count > 0) : (c != ';'))
|
|
||||||
{
|
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '\n':
|
|
||||||
obstack_1grow (&guard_obstack, c);
|
|
||||||
lineno++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '{':
|
|
||||||
obstack_1grow (&guard_obstack, c);
|
|
||||||
brace_flag = 1;
|
|
||||||
count++;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '}':
|
|
||||||
obstack_1grow (&guard_obstack, c);
|
|
||||||
if (count > 0)
|
|
||||||
count--;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
complain (_("unmatched %s"), "`}'");
|
|
||||||
c = getc (finput); /* skip it */
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\'':
|
|
||||||
case '"':
|
|
||||||
copy_string (finput, &guard_obstack, c);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '/':
|
|
||||||
copy_comment (finput, &guard_obstack);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '$':
|
|
||||||
copy_dollar (finput, &guard_obstack, rule, stack_offset);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '@':
|
|
||||||
copy_at (finput, &guard_obstack, stack_offset);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EOF:
|
|
||||||
fatal ("%s", _("unterminated %guard clause"));
|
|
||||||
|
|
||||||
default:
|
|
||||||
obstack_1grow (&guard_obstack, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c != '}' || count != 0)
|
|
||||||
c = getc (finput);
|
|
||||||
}
|
|
||||||
|
|
||||||
obstack_1grow (&guard_obstack, '\0');
|
|
||||||
rule->guard = obstack_finish (&guard_obstack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
parse_guard (symbol_list *rule, int stack_offset)
|
||||||
|
{
|
||||||
|
token_t t = lex ();
|
||||||
|
if (t != tok_left_curly)
|
||||||
|
complain (_("invalid %s declaration"), "%guard");
|
||||||
|
rule->guard_line = lineno;
|
||||||
|
parse_braces (rule, stack_offset);
|
||||||
|
rule->guard = obstack_finish (&action_obstack);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------.
|
/*-------------------------------------------------------------------.
|
||||||
@@ -1439,7 +1372,7 @@ readgram (void)
|
|||||||
}
|
}
|
||||||
else /* handle an action. */
|
else /* handle an action. */
|
||||||
{
|
{
|
||||||
copy_action (crule, rulelength);
|
parse_action (crule, rulelength);
|
||||||
action_flag = 1;
|
action_flag = 1;
|
||||||
xactions++; /* JF */
|
xactions++; /* JF */
|
||||||
}
|
}
|
||||||
@@ -1464,7 +1397,7 @@ readgram (void)
|
|||||||
if (!semantic_parser)
|
if (!semantic_parser)
|
||||||
complain (_("%%guard present but %%semantic_parser not specified"));
|
complain (_("%%guard present but %%semantic_parser not specified"));
|
||||||
|
|
||||||
copy_guard (crule, rulelength);
|
parse_guard (crule, rulelength);
|
||||||
t = lex ();
|
t = lex ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1473,7 +1406,7 @@ readgram (void)
|
|||||||
/* This case never occurs -wjh */
|
/* This case never occurs -wjh */
|
||||||
if (action_flag)
|
if (action_flag)
|
||||||
complain (_("two actions at end of one rule"));
|
complain (_("two actions at end of one rule"));
|
||||||
copy_action (crule, rulelength);
|
parse_action (crule, rulelength);
|
||||||
action_flag = 1;
|
action_flag = 1;
|
||||||
xactions++; /* -wjh */
|
xactions++; /* -wjh */
|
||||||
t = lex ();
|
t = lex ();
|
||||||
@@ -1865,7 +1798,6 @@ reader (void)
|
|||||||
/* Initialize the obstacks. */
|
/* Initialize the obstacks. */
|
||||||
obstack_init (&action_obstack);
|
obstack_init (&action_obstack);
|
||||||
obstack_init (&attrs_obstack);
|
obstack_init (&attrs_obstack);
|
||||||
obstack_init (&guard_obstack);
|
|
||||||
obstack_init (&output_obstack);
|
obstack_init (&output_obstack);
|
||||||
|
|
||||||
finput = xfopen (infile, "r");
|
finput = xfopen (infile, "r");
|
||||||
|
|||||||
Reference in New Issue
Block a user