[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
31-fyi-verbose-verbose.patch
From: |
Akim Demaille |
Subject: |
31-fyi-verbose-verbose.patch |
Date: |
Wed, 05 Dec 2001 08:26:37 +0100 |
Yahoo!
This patch was at the origin of my diving into the core of Bison:
understanding why the .output contains only a part of the items for
each state. It turns out to be a very useful optimization, and trying
to complete the set of items in the engine would probably have a
significant impact on efficiency. But it can be performed later.
As a demonstration, run on one of the calc.y of the test suite, here
is a portion of the diff of without/with --trace in addition to
--verbose:
| --- /tmp/calc.old Mon Dec 3 21:33:56 2001
| +++ /tmp/calc.output Mon Dec 3 21:55:51 2001
| @@ -95,6 +95,9 @@
|
| state 0
|
| + input -> . (rule 1)
| + input -> . input line (rule 2)
| +
| $default reduce using rule 1 (input)
|
| input go to state 1
| @@ -104,6 +107,17 @@
| state 1
|
| input -> input . line (rule 2)
| + line -> . '\n' (rule 3)
| + line -> . exp '\n' (rule 4)
| + exp -> . NUM (rule 5)
| + exp -> . exp '=' exp (rule 6)
| + exp -> . exp '+' exp (rule 7)
| + exp -> . exp '-' exp (rule 8)
| + exp -> . exp '*' exp (rule 9)
| + exp -> . exp '/' exp (rule 10)
| + exp -> . '-' exp (rule 11)
| + exp -> . exp '^' exp (rule 12)
| + exp -> . '(' exp ')' (rule 13)
|
| $ go to state 24
| NUM shift, and go to state 2
My point was making it easier for novices to understand what the
states are. My sole regret is with the last weirdo states:
| @@ -416,11 +502,17 @@
|
| state 24
|
| + input -> . (rule 1)
| + input -> . input line (rule 2)
| +
| $ go to state 25
|
|
|
| state 25
| +
| + input -> . (rule 1)
| + input -> . input line (rule 2)
|
| $default accept
Index: ChangeLog
from Akim Demaille <address@hidden>
New experimental feature: if --verbose --trace output all the
items of a state, not only its kernel.
* src/print.c (print_core): If `trace_flag', then invoke closure
before outputting the items of the state (print_core is no longer
a correct name them).
(print_results): Invoke new_closure/free_closure if needed.
Index: src/print.c
--- src/print.c Sat, 01 Dec 2001 20:18:59 +0100 akim
+++ src/print.c Mon, 03 Dec 2001 21:49:31 +0100 akim
@@ -30,6 +30,7 @@
#include "reader.h"
#include "print.h"
#include "reduce.h"
+#include "closure.h"
#if 0
static void
@@ -48,38 +49,48 @@
print_core (FILE *out, int state)
{
int i;
- core *statep = state_table[state].state;
+ short *sitems = state_table[state].state->items;
+ int snitems = state_table[state].state->nitems;
- if (!statep->nitems)
- return;
+ /* New experimental feature: if TRACE_FLAGS output all the items of
+ a state, not only its kernel. */
+ if (trace_flag)
+ {
+ closure (sitems, snitems);
+ sitems = itemset;
+ snitems = nitemset;
+ }
- for (i = 0; i < statep->nitems; i++)
+ if (snitems)
{
- short *sp;
- short *sp1;
- int rule;
+ for (i = 0; i < snitems; i++)
+ {
+ short *sp;
+ short *sp1;
+ int rule;
- sp1 = sp = ritem + statep->items[i];
+ sp1 = sp = ritem + sitems[i];
- while (*sp > 0)
- sp++;
+ while (*sp > 0)
+ sp++;
- rule = -(*sp);
- fprintf (out, " %s -> ", tags[rule_table[rule].lhs]);
+ rule = -(*sp);
+ fprintf (out, " %s -> ", tags[rule_table[rule].lhs]);
- for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
- fprintf (out, "%s ", tags[*sp]);
+ for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
+ fprintf (out, "%s ", tags[*sp]);
- fputc ('.', out);
+ fputc ('.', out);
- for (/* Nothing */; *sp > 0; ++sp)
- fprintf (out, " %s", tags[*sp]);
+ for (/* Nothing */; *sp > 0; ++sp)
+ fprintf (out, " %s", tags[*sp]);
+
+ fprintf (out, _(" (rule %d)"), rule);
+ fputc ('\n', out);
+ }
- fprintf (out, _(" (rule %d)"), rule);
fputc ('\n', out);
}
-
- fputc ('\n', out);
}
static void
@@ -321,8 +332,15 @@
print_grammar (out);
+ /* New experimental feature: output all the items of a state,
+ not only its kernel. Requires to run closure, which need
+ memory allocation/deallocation. */
+ if (trace_flag)
+ new_closure (nitems);
for (i = 0; i < nstates; i++)
print_state (out, i);
+ if (trace_flag)
+ free_closure ();
xfclose (out);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 31-fyi-verbose-verbose.patch,
Akim Demaille <=