Skip to content

Commit

Permalink
+xbgf:unterminalize (works)
Browse files Browse the repository at this point in the history
+xbgf:yaccify (doesn't work yet)


git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@439 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Feb 5, 2009
1 parent 6ffdffa commit c06cfe9
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 83 deletions.
12 changes: 9 additions & 3 deletions shared/prolog/readXbgf.pro
Expand Up @@ -48,6 +48,11 @@ xml2xbgf(T,deyaccify(N))
self(name(xbgf:deyaccify),T),
content(T,N).

xml2xbgf(T,unterminalize(N))
:-
self(name(xbgf:unterminalize),T),
content(T,N).

xml2xbgf(T,distributeL(L))
:-
self(name(xbgf:distribute),T),
Expand Down Expand Up @@ -309,11 +314,12 @@ xml2xbgf(T,verticalN(N))
child(name(nonterminal),T,T1),
content(T1,N).

xml2xbgf(T,yaccify(P2))
xml2xbgf(T,yaccify(P1,P2))
:-
self(name(xbgf:yaccify),T),
child(name(bgf:production),T,P1),
xmlToP(P1,P2).
children(name(bgf:production),T,[P3,P4]),
xmlToP(P3,P1),
xmlToP(P4,P2).

xml2xbgf(T,G)
:-
Expand Down
33 changes: 25 additions & 8 deletions shared/prolog/xbgf1.pro
Expand Up @@ -1083,6 +1083,22 @@ abridge(P1,g(Rs,Ps1),g(Rs,Ps2))
[P1]),
append(Ps1a,Ps1b,Ps2).

%
% p([l(unterminalize)], f, n(p))
%
% Strip all terminals within a given nonterminal's definition
%

unterminalize(N,g(Rs,Ps1),g(Rs,Ps2))
:-
usedNs(Ps1,Uses1),
require(
member(N,Uses1),
'Nonterminal ~q must be used.',
[N]),
splitN(Ps1,N,Ps0,Ps2a,Ps2b),
transform(try(xbgf1:stripTs_rule),g(Rs,Ps0),g(Rs,Ps3)),
concat([Ps2a,Ps3,Ps2b],Ps2).

%
% p([l(stripL)], f, n(l))
Expand Down Expand Up @@ -1360,13 +1376,14 @@ widen(X1,X2,Ps2,Ps2a,Ps2b,Ps3)
% Expand EBNF-based regular expression operator via BNF encoding
%

yaccify(P1,g(Rs,Ps1),g(Rs,Ps2))
yaccify(P1,P2,g(Rs,Ps1),g(Rs,Ps3))
:-
P1 = p(As,N,X1),
splitN1(Ps1,N,P2,Ps2a,Ps2b),
P2 = p(As,N,X2),
P1 = p(As,N,_),
P2 = p(As,N,_),
splitN1(Ps1,N,P3,Ps2a,Ps2b),
P3 = p(As,N,_),
require(
xbgf1:deyaccify_rules(N,X1,X2),
'~q and ~q not suitable for yaccification.',
[X1,X2]),
append(Ps2a,[P1|Ps2b],Ps2).
xbgf1:newdeyaccify_rules(N,P1,P2,P3),
'~q and ~q not suitable as yaccification of ~q.',
[P1,P2,P3]),
append(Ps2a,[P1,P2|Ps2b],Ps3).
12 changes: 12 additions & 0 deletions shared/xsd/xbgf.xsd
Expand Up @@ -63,6 +63,7 @@
<xsd:element ref="xbgf:undefine"/>
<xsd:element ref="xbgf:unfold"/>
<xsd:element ref="xbgf:unite"/>
<xsd:element ref="xbgf:unterminalize"/>
<xsd:element ref="xbgf:vertical"/>
<xsd:element ref="xbgf:widen"/>
<xsd:element ref="xbgf:yaccify"/>
Expand Down Expand Up @@ -743,6 +744,16 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="unterminalize" type="bgf:nonterminal">
<xsd:annotation>
<xsd:documentation>
Various details of productions can be required to be stripped.
This transformation strips all terminal symbols
within a given nonterminal's definition.
</xsd:documentation>
</xsd:annotation>
</xsd:element>

<xsd:element name="vertical">
<xsd:annotation>
Expand Down Expand Up @@ -796,6 +807,7 @@
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="bgf:production"/>
<xsd:element ref="bgf:production"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Expand Down
19 changes: 9 additions & 10 deletions topics/java/lci/xbgf/extendModifiers.xbgf
Expand Up @@ -220,21 +220,20 @@
<bgf:production>
<nonterminal>ConstantModifiers</nonterminal>
<bgf:expression>
<choice>
<nonterminal>ConstantModifier</nonterminal>
</bgf:expression>
</bgf:production>
<bgf:production>
<nonterminal>ConstantModifiers</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>ConstantModifier</nonterminal>
</bgf:expression>
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>ConstantModifier</nonterminal>
</bgf:expression>
<bgf:expression>
<nonterminal>ConstantModifiers</nonterminal>
</bgf:expression>
</sequence>
<nonterminal>ConstantModifiers</nonterminal>
</bgf:expression>
</choice>
</sequence>
</bgf:expression>
</bgf:production>
</xbgf:yaccify>
Expand Down
2 changes: 1 addition & 1 deletion topics/transformation/xbgf/tests/Makefile
Expand Up @@ -71,14 +71,14 @@ test:
@make strip3.quiet
@make strip4.quiet
@make strip5.quiet
@make strip6.quiet
@make unchain.quiet
@make undefine.quiet
@make unfold1.quiet
@make unfold2.quiet
@make unfold3.quiet
@make unfold4.quiet
@make unite.quiet
@make unterminalize.quiet
@make vertical1.quiet
@make vertical2.quiet
@make widen1.quiet
Expand Down
57 changes: 0 additions & 57 deletions topics/transformation/xbgf/tests/strip6.baseline

This file was deleted.

63 changes: 63 additions & 0 deletions topics/transformation/xbgf/tests/unterminalize.baseline
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>

<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">
<bgf:production>
<label>constant</label>
<nonterminal>expr</nonterminal>
<bgf:expression>
<selectable>
<selector>value</selector>
<bgf:expression>
<nonterminal>int</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
</bgf:production>
<bgf:production>
<label>binary</label>
<nonterminal>expr</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<nonterminal>expr</nonterminal>
</bgf:expression>
<bgf:expression>
<selectable>
<selector>op</selector>
<bgf:expression>
<nonterminal>binary_op</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
<bgf:expression>
<nonterminal>expr</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
<bgf:production>
<label>unary</label>
<nonterminal>expr</nonterminal>
<bgf:expression>
<sequence>
<bgf:expression>
<selectable>
<selector>op</selector>
<bgf:expression>
<nonterminal>unary_op</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
<bgf:expression>
<nonterminal>expr</nonterminal>
</bgf:expression>
</sequence>
</bgf:expression>
</bgf:production>
<bgf:production>
<nonterminal>nonexpr</nonterminal>
<bgf:expression>
<terminal>test</terminal>
</bgf:expression>
</bgf:production>
</bgf:grammar>
Expand Up @@ -58,4 +58,10 @@
</sequence>
</bgf:expression>
</bgf:production>
</bgf:grammar>
<bgf:production>
<nonterminal>nonexpr</nonterminal>
<bgf:expression>
<terminal>test</terminal>
</bgf:expression>
</bgf:production>
</bgf:grammar>
@@ -1,7 +1,5 @@
<xbgf:sequence
xmlns:bgf="http://planet-sl.org/bgf"
xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:strip>
<allTerminals/>
</xbgf:strip>
<xbgf:unterminalize>expr</xbgf:unterminalize>
</xbgf:sequence>

0 comments on commit c06cfe9

Please sign in to comment.