Skip to content

Commit

Permalink
xbgf:equate operator implemented; one test case is still failing
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@765 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 3, 2010
1 parent d2be3a0 commit 15eab7f
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 0 deletions.
8 changes: 8 additions & 0 deletions shared/prolog/readXbgf.pro
Expand Up @@ -373,6 +373,14 @@ xml2xbgf(T,unite(N1,N2))
content(Add,N1),
content(To,N2).

xml2xbgf(T,equate(N1,N2))
:-
self(name(xbgf:equate),T),
child(name(align),T,Align),
child(name(with),T,With),
content(Align,N1),
content(With,N2).

xml2xbgf(T,upgrade(P1,P2))
:-
self(name(xbgf:upgrade),T),
Expand Down
21 changes: 21 additions & 0 deletions shared/prolog/xbgf1.pro
Expand Up @@ -1448,6 +1448,27 @@ unite(N1,N2,G1,G2)
[N1,N2]),
transform(try(xbgf1:renameN_rules(N1,N2)),G1,G2).

%
% p([l(equate)], f, ','([n(n), n(n)]))
%
% Merging two identically defined nonterminals
%
equate(N1,N2,g(Rs1,Ps1),g(Rs2,Ps2))
:-
findN(Ps1,N1,N1Ps1),
findN(Ps1,N2,N2Ps),
xbgf1:renameN(N1,N2,g(Rs1,N1Ps1),g(_,N1Ps2)),
checkforidentity(N1Ps2,N2Ps),
xbgf1:unite(N1,N2,g(Rs1,Ps1),g(Rs2,Ps2)).

checkforidentity([],[]).
checkforidentity([P1|Ps1],Ps2)
:-
removeproduction(P1,Ps2,Ps3),
checkforidentity(Ps1,Ps3).

removeproduction(P1,[P2|Ps2],Ps2) :- eqP(P1,P2).
removeproduction(P1,[P2|Ps2],Ps3) :- [P2|removeproduction(P1,Ps2,Ps3)].

%
% p([l(verticalL)], f, n(l))
Expand Down
15 changes: 15 additions & 0 deletions shared/xsd/xbgf.xsd
Expand Up @@ -133,6 +133,7 @@
<xsd:element ref="xbgf:import"/>
<xsd:element ref="xbgf:vertical"/>
<xsd:element ref="xbgf:horizontal"/>
<xsd:element ref="xbgf:equate"/>
<!-- do we need them? -->
<xsd:element ref="xbgf:rassoc"/>
<xsd:element ref="xbgf:lassoc"/>
Expand Down Expand Up @@ -1138,6 +1139,20 @@
</xsd:complexType>
</xsd:element>

<xsd:element name="equate">
<xsd:annotation>
<xsd:documentation>
Two nonterminals, say x and y, are merged, if their definitions are identical.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="align" type="bgf:nonterminal"/>
<xsd:element name="with" type="bgf:nonterminal"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="abstractize">
<xsd:annotation>
<xsd:documentation>
Expand Down
10 changes: 10 additions & 0 deletions shared/xsl/xbgf2xbnf.xslt
Expand Up @@ -248,4 +248,14 @@
</xsl:text>
</xsl:template>

<xsl:template match="xbgf:equate">
<xsl:value-of select="local-name()" />
<xsl:text>(</xsl:text>
<xsl:apply-templates select="align/text()"/>
<xsl:text>, </xsl:text>
<xsl:apply-templates select="with/text()"/>
<xsl:text>);
</xsl:text>
</xsl:template>

</xsl:stylesheet>
9 changes: 9 additions & 0 deletions topics/transformation/xbgf/tests/equate1.baseline
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">
<bgf:production>
<nonterminal>bar</nonterminal>
<bgf:expression>
<nonterminal>wez</nonterminal>
</bgf:expression>
</bgf:production>
</bgf:grammar>
15 changes: 15 additions & 0 deletions topics/transformation/xbgf/tests/equate1.bgf
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">
<bgf:production>
<nonterminal>foo</nonterminal>
<bgf:expression>
<nonterminal>wez</nonterminal>
</bgf:expression>
</bgf:production>
<bgf:production>
<nonterminal>bar</nonterminal>
<bgf:expression>
<nonterminal>wez</nonterminal>
</bgf:expression>
</bgf:production>
</bgf:grammar>
7 changes: 7 additions & 0 deletions topics/transformation/xbgf/tests/equate1.xbgf
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<xbgf:sequence xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:equate>
<align>foo</align>
<with>bar</with>
</xbgf:equate>
</xbgf:sequence>
20 changes: 20 additions & 0 deletions topics/transformation/xbgf/tests/equate2.baseline
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">
<bgf:production>
<nonterminal>bar</nonterminal>
<bgf:expression>
<choice>
<bgf:expression>
<terminal>x</terminal>
</bgf:expression>
<bgf:expression>
<star>
<bgf:expression>
<nonterminal>wez</nonterminal>
</bgf:expression>
</star>
</bgf:expression>
</choice>
</bgf:expression>
</bgf:production>
</bgf:grammar>
37 changes: 37 additions & 0 deletions topics/transformation/xbgf/tests/equate2.bgf
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">
<bgf:production>
<nonterminal>foo</nonterminal>
<bgf:expression>
<choice>
<bgf:expression>
<star>
<bgf:expression>
<nonterminal>wez</nonterminal>
</bgf:expression>
</star>
</bgf:expression>
<bgf:expression>
<terminal>x</terminal>
</bgf:expression>
</choice>
</bgf:expression>
</bgf:production>
<bgf:production>
<nonterminal>bar</nonterminal>
<bgf:expression>
<choice>
<bgf:expression>
<terminal>x</terminal>
</bgf:expression>
<bgf:expression>
<star>
<bgf:expression>
<nonterminal>wez</nonterminal>
</bgf:expression>
</star>
</bgf:expression>
</choice>
</bgf:expression>
</bgf:production>
</bgf:grammar>
7 changes: 7 additions & 0 deletions topics/transformation/xbgf/tests/equate2.xbgf
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<xbgf:sequence xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:equate>
<align>foo</align>
<with>bar</with>
</xbgf:equate>
</xbgf:sequence>

0 comments on commit 15eab7f

Please sign in to comment.