[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: <reductions>
From: |
Joel E. Denny |
Subject: |
Re: <reductions> |
Date: |
Sat, 1 Dec 2007 18:18:25 -0500 (EST) |
On Sun, 30 Sep 2007, Joel E. Denny wrote:
> <grammar>
> ...
> <nonterminals>
> <nonterminal type="9" symbol="$accept">
> <left>
> <rule>0</rule>
> </left>
> </nonterminal>
> <nonterminal type="10" symbol="exp">
> <left>
> <rule>1</rule>
> <rule>2</rule>
> <rule>3</rule>
> <rule>4</rule>
> <rule>5</rule>
> </left>
> <right>
> <rule>0</rule>
> <rule>1</rule>
> <rule>2</rule>
> <rule>3</rule>
> <rule>4</rule>
> </right>
> </nonterminal>
> <useless>
> <nonterminal symbol="useless1" />
> <nonterminal symbol="useless2" />
> </useless>
> </nonterminals>
> </grammar>
>
> I have a few other issues here.
>
> Do you think we need to summarize where nonterminals and terminals appear
> as shown above? The XSLT can compute that from the grammar.
Implemented as follows, not yet committed.
Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1760
diff -p -u -r1.1760 ChangeLog
--- ChangeLog 1 Dec 2007 19:44:35 -0000 1.1760
+++ ChangeLog 1 Dec 2007 23:00:16 -0000
@@ -1,5 +1,37 @@
2007-12-01 Joel E. Denny <address@hidden>
+ * data/xslt/bison.xsl (bison:ruleNumber): Rename to...
+ (bison:ruleByNumber): ... this for clarity.
+ * data/xslt/xml2dot.xsl (xsl:template match="item"): Update.
+ * data/xslt/xml2text.xsl (xsl:template match="item"): Update.
+ (xsl:template match="reduction"): Update.
+ (xsl:template match="item"): Update.
+ (xsl:template match="reduction"): Update.
+
+ In the XML output, don't print the list of rules where symbols appear.
+ Compute it in XSLT instead. Discussed at
+ <http://lists.gnu.org/archive/html/bison-patches/2007-09/msg00024.html>.
+ * data/xslt/bison.xsl (bison:ruleByLhs): New.
+ (bison:ruleByRhs): New.
+ * data/xslt/xml2text.xsl (xsl:template match="terminal"): Use
+ bison:ruleByRhs.
+ (xsl:template match="terminal/rule"): Remove.
+ (xsl:template match="nonterminal"): Use bison:ruleByLhs and
+ bison:ruleByRhs.
+ (xsl:template match="nonterminal/left/rule|nonterminal/right/rule"):
+ Remove.
+ * data/xslt/xml2xhtml.xsl (xsl:template match="terminal"): Use
+ bison:ruleByRhs.
+ (xsl:template match="terminal/rule"): Remove.
+ (xsl:template match="nonterminal"): Use bison:ruleByLhs and
+ bison:ruleByRhs and mode="number-link" for rule template.
+ (xsl:template match="nonterminal/left/rule|nonterminal/right/rule"):
+ Rewrite as...
+ (xsl:template match="rule" mode="number-link"): ... this.
+ * src/print-xml.c (print_grammar): Don't print the list of rules.
+
+2007-12-01 Joel E. Denny <address@hidden>
+
Don't let --report affect XML output; always print all information.
Discussed at
<http://lists.gnu.org/archive/html/bison-patches/2007-09/msg00020.html>.
Index: data/xslt/bison.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/bison.xsl,v
retrieving revision 1.2
diff -p -u -r1.2 bison.xsl
--- data/xslt/bison.xsl 11 Oct 2007 16:37:38 -0000 1.2
+++ data/xslt/bison.xsl 1 Dec 2007 23:00:16 -0000
@@ -26,9 +26,23 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:bison="http://www.gnu.org/software/bison/">
-<xsl:key name="bison:ruleNumber"
- match="/bison-xml-report/grammar/rules/rule"
- use="@number"/>
+<xsl:key
+ name="bison:ruleByNumber"
+ match="/bison-xml-report/grammar/rules/rule"
+ use="@number"
+/>
+<xsl:key
+ name="bison:ruleByLhs"
+ match="/bison-xml-report/grammar/rules/rule[
+ @usefulness != 'useless-in-grammar']"
+ use="lhs"
+/>
+<xsl:key
+ name="bison:ruleByRhs"
+ match="/bison-xml-report/grammar/rules/rule[
+ @usefulness != 'useless-in-grammar']"
+ use="rhs/symbol"
+/>
<!-- For the specified state, output: #sr-conflicts,#rr-conflicts -->
<xsl:template match="state" mode="bison:count-conflicts">
Index: data/xslt/xml2dot.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2dot.xsl,v
retrieving revision 1.4
diff -p -u -r1.4 xml2dot.xsl
--- data/xslt/xml2dot.xsl 21 Oct 2007 15:34:08 -0000 1.4
+++ data/xslt/xml2dot.xsl 1 Dec 2007 23:00:16 -0000
@@ -61,7 +61,7 @@
</xsl:template>
<xsl:template match="item">
- <xsl:apply-templates select="key('bison:ruleNumber', @rule-number)">
+ <xsl:apply-templates select="key('bison:ruleByNumber', @rule-number)">
<xsl:with-param name="point" select="@point"/>
</xsl:apply-templates>
<xsl:apply-templates select="lookaheads"/>
Index: data/xslt/xml2text.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2text.xsl,v
retrieving revision 1.8
diff -p -u -r1.8 xml2text.xsl
--- data/xslt/xml2text.xsl 24 Nov 2007 19:41:24 -0000 1.8
+++ data/xslt/xml2text.xsl 1 Dec 2007 23:00:16 -0000
@@ -150,16 +150,13 @@
<xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text">
<xsl:value-of select="concat(' (', @token-number, ')')"/>
- <xsl:apply-templates select="rule" />
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
-<xsl:template match="terminal/rule">
- <xsl:text> </xsl:text>
- <xsl:value-of select="."/>
-</xsl:template>
-
<xsl:template match="nonterminal">
<xsl:value-of select="@name"/>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
@@ -169,28 +166,27 @@
<xsl:with-param name="line-length" select="66" />
<xsl:with-param name="text">
<xsl:text> </xsl:text>
- <xsl:if test="left/rule">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>address@hidden:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByLhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
</xsl:if>
- <xsl:apply-templates select="left/rule"/>
- <xsl:if test="left/rule and right/rule">
- <xsl:text>, </xsl:text>
- </xsl:if>
- <xsl:if test="right/rule">
+ <xsl:if test="key('bison:ruleByRhs', @name)">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
+ <xsl:text>, </xsl:text>
+ </xsl:if>
<xsl:text>address@hidden:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:value-of select="concat(' ', @number)"/>
+ </xsl:for-each>
</xsl:if>
- <xsl:apply-templates select="right/rule"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="translate($output, '@', ' ')" />
</xsl:template>
-<xsl:template match="nonterminal/left/rule|nonterminal/right/rule">
- <xsl:text> </xsl:text>
- <xsl:value-of select="."/>
-</xsl:template>
-
<xsl:template match="automaton" mode="conflicts">
<xsl:variable name="conflict-report">
<xsl:apply-templates select="state" mode="conflicts"/>
@@ -296,11 +292,15 @@
<xsl:param name="pad"/>
<xsl:param name="prev-rule-number"
select="preceding-sibling::item[1]/@rule-number"/>
- <xsl:apply-templates select="key('bison:ruleNumber',
current()/@rule-number)">
+ <xsl:apply-templates
+ select="key('bison:ruleByNumber', current()/@rule-number)"
+ >
<xsl:with-param name="itemset" select="'true'"/>
<xsl:with-param name="pad" select="$pad"/>
- <xsl:with-param name="prev-lhs"
- select="key('bison:ruleNumber',
$prev-rule-number)/lhs[text()]"/>
+ <xsl:with-param
+ name="prev-lhs"
+ select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
+ />
<xsl:with-param name="point" select="@point"/>
<xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/>
@@ -443,7 +443,7 @@
<xsl:value-of select="@rule"/>
<xsl:text> (</xsl:text>
<xsl:value-of
- select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
+ select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"/>
<xsl:text>)</xsl:text>
</xsl:otherwise>
</xsl:choose>
Index: data/xslt/xml2xhtml.xsl
===================================================================
RCS file: /sources/bison/bison/data/xslt/xml2xhtml.xsl,v
retrieving revision 1.7
diff -p -u -r1.7 xml2xhtml.xsl
--- data/xslt/xml2xhtml.xsl 24 Nov 2007 19:41:24 -0000 1.7
+++ data/xslt/xml2xhtml.xsl 1 Dec 2007 23:00:16 -0000
@@ -326,45 +326,47 @@
<xsl:template match="terminal">
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="concat(' (', @token-number, ')')"/>
- <xsl:apply-templates select="rule"/>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:text> </xsl:text>
+ <a>
+ <xsl:attribute name="href">
+ <xsl:value-of select="concat('#rule_', @number)"/>
+ </xsl:attribute>
+ <xsl:value-of select="@number"/>
+ </a>
+ </xsl:for-each>
<xsl:text> </xsl:text>
</xsl:template>
-<xsl:template match="terminal/rule">
- <xsl:text> </xsl:text>
- <a>
- <xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', .)"/>
- </xsl:attribute>
- <xsl:value-of select="."/>
- </a>
-</xsl:template>
-
<xsl:template match="nonterminal">
<b><xsl:value-of select="@name"/></b>
<xsl:value-of select="concat(' (', @symbol-number, ')')"/>
<xsl:text> </xsl:text>
- <xsl:if test="left/rule">
+ <xsl:if test="key('bison:ruleByLhs', @name)">
<xsl:text>on left:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByLhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
+ <xsl:if test="key('bison:ruleByRhs', @name)">
+ <xsl:text> </xsl:text>
+ </xsl:if>
</xsl:if>
- <xsl:apply-templates select="left/rule"/>
- <xsl:if test="left/rule and right/rule">
- <xsl:text> </xsl:text>
- </xsl:if>
- <xsl:if test="right/rule">
+ <xsl:if test="key('bison:ruleByRhs', @name)">
<xsl:text>on right:</xsl:text>
+ <xsl:for-each select="key('bison:ruleByRhs', @name)">
+ <xsl:apply-templates select="." mode="number-link"/>
+ </xsl:for-each>
</xsl:if>
- <xsl:apply-templates select="right/rule"/>
<xsl:text> </xsl:text>
</xsl:template>
-<xsl:template match="nonterminal/left/rule|nonterminal/right/rule">
+<xsl:template match="rule" mode="number-link">
<xsl:text> </xsl:text>
<a>
<xsl:attribute name="href">
- <xsl:value-of select="concat('#rule_', .)"/>
+ <xsl:value-of select="concat('#rule_', @number)"/>
</xsl:attribute>
- <xsl:value-of select="."/>
+ <xsl:value-of select="@number"/>
</a>
</xsl:template>
@@ -451,11 +453,14 @@
<xsl:param name="pad"/>
<xsl:param name="prev-rule-number"
select="preceding-sibling::item[1]/@rule-number"/>
- <xsl:apply-templates select="key('bison:ruleNumber',
current()/@rule-number)">
+ <xsl:apply-templates
+ select="key('bison:ruleByNumber', current()/@rule-number)"
+ >
<xsl:with-param name="itemset" select="'true'"/>
<xsl:with-param name="pad" select="$pad"/>
<xsl:with-param name="prev-lhs"
- select="key('bison:ruleNumber',
$prev-rule-number)/lhs[text()]"/>
+ select="key('bison:ruleByNumber', $prev-rule-number)/lhs[text()]"
+ />
<xsl:with-param name="point" select="@point"/>
<xsl:with-param name="lookaheads">
<xsl:apply-templates select="lookaheads"/>
@@ -644,7 +649,8 @@
</a>
<xsl:text> (</xsl:text>
<xsl:value-of
- select="key('bison:ruleNumber', current()/@rule)/lhs[text()]"/>
+ select="key('bison:ruleByNumber', current()/@rule)/lhs[text()]"
+ />
<xsl:text>)</xsl:text>
</xsl:otherwise>
</xsl:choose>
Index: src/print-xml.c
===================================================================
RCS file: /sources/bison/bison/src/print-xml.c,v
retrieving revision 1.12
diff -p -u -r1.12 print-xml.c
--- src/print-xml.c 1 Dec 2007 19:44:36 -0000 1.12
+++ src/print-xml.c 1 Dec 2007 23:00:18 -0000
@@ -392,24 +392,12 @@ print_grammar (FILE *out, int level)
if (token_translations[i] != undeftoken->number)
{
char const *tag = symbols[token_translations[i]]->tag;
- rule_number r;
- item_number *rhsp;
-
xml_printf (out, level + 2,
"<terminal symbol-number=\"%d\" token-number=\"%d\""
- " name=\"%s\" usefulness=\"%s\">",
+ " name=\"%s\" usefulness=\"%s\"/>",
token_translations[i], i, xml_escape (tag),
reduce_token_unused_in_grammar (token_translations[i])
? "unused-in-grammar" : "useful");
-
- for (r = 0; r < nrules; r++)
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == token_translations[i])
- {
- xml_printf (out, level + 3, "<rule>%d</rule>", r);
- break;
- }
- xml_puts (out, level + 2, "</terminal>");
}
xml_puts (out, level + 1, "</terminals>");
@@ -417,58 +405,13 @@ print_grammar (FILE *out, int level)
xml_puts (out, level + 1, "<nonterminals>");
for (i = ntokens; i < nsyms + nuseless_nonterminals; i++)
{
- int left_count = 0, right_count = 0;
- rule_number r;
char const *tag = symbols[i]->tag;
-
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- if (rules[r].lhs->number == i)
- left_count++;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- right_count++;
- break;
- }
- }
-
xml_printf (out, level + 2,
"<nonterminal symbol-number=\"%d\" name=\"%s\""
- " usefulness=\"%s\">",
+ " usefulness=\"%s\"/>",
i, xml_escape (tag),
reduce_nonterminal_useless_in_grammar (i)
? "useless-in-grammar" : "useful");
-
- if (left_count > 0)
- {
- xml_puts (out, level + 3, "<left>");
- for (r = 0; r < nrules; r++)
- {
- if (rules[r].lhs->number == i)
- xml_printf (out, level + 4, "<rule>%d</rule>", r);
- }
- xml_puts (out, level + 3, "</left>");
- }
-
- if (right_count > 0)
- {
- xml_puts (out, level + 3, "<right>");
- for (r = 0; r < nrules; r++)
- {
- item_number *rhsp;
- for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++)
- if (item_number_as_symbol_number (*rhsp) == i)
- {
- xml_printf (out, level + 4, "<rule>%d</rule>", r);
- break;
- }
- }
- xml_puts (out, level + 3, "</right>");
- }
-
- xml_puts (out, level + 2, "</nonterminal>");
}
xml_puts (out, level + 1, "</nonterminals>");
xml_puts (out, level, "</grammar>");
- Re: <reductions>,
Joel E. Denny <=