diff --git a/shared/prolog/readXbgf.pro b/shared/prolog/readXbgf.pro index 329d050b..de663af4 100644 --- a/shared/prolog/readXbgf.pro +++ b/shared/prolog/readXbgf.pro @@ -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), @@ -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) :- diff --git a/shared/prolog/xbgf1.pro b/shared/prolog/xbgf1.pro index a5e0ea58..4547e714 100644 --- a/shared/prolog/xbgf1.pro +++ b/shared/prolog/xbgf1.pro @@ -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)) @@ -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). diff --git a/shared/xsd/xbgf.xsd b/shared/xsd/xbgf.xsd index 52a002eb..6ac6b62d 100644 --- a/shared/xsd/xbgf.xsd +++ b/shared/xsd/xbgf.xsd @@ -63,6 +63,7 @@ + @@ -743,6 +744,16 @@ + + + + + Various details of productions can be required to be stripped. + This transformation strips all terminal symbols + within a given nonterminal's definition. + + + @@ -796,6 +807,7 @@ + diff --git a/topics/java/lci/xbgf/extendModifiers.xbgf b/topics/java/lci/xbgf/extendModifiers.xbgf index 465827b8..fa3c7a3c 100644 --- a/topics/java/lci/xbgf/extendModifiers.xbgf +++ b/topics/java/lci/xbgf/extendModifiers.xbgf @@ -220,21 +220,20 @@ ConstantModifiers - + ConstantModifier + + + + ConstantModifiers + + ConstantModifier - - - ConstantModifier - - - ConstantModifiers - - + ConstantModifiers - + diff --git a/topics/transformation/xbgf/tests/Makefile b/topics/transformation/xbgf/tests/Makefile index a80b903f..de3eaa28 100644 --- a/topics/transformation/xbgf/tests/Makefile +++ b/topics/transformation/xbgf/tests/Makefile @@ -71,7 +71,6 @@ test: @make strip3.quiet @make strip4.quiet @make strip5.quiet - @make strip6.quiet @make unchain.quiet @make undefine.quiet @make unfold1.quiet @@ -79,6 +78,7 @@ test: @make unfold3.quiet @make unfold4.quiet @make unite.quiet + @make unterminalize.quiet @make vertical1.quiet @make vertical2.quiet @make widen1.quiet diff --git a/topics/transformation/xbgf/tests/strip6.baseline b/topics/transformation/xbgf/tests/strip6.baseline deleted file mode 100644 index bfaea9c9..00000000 --- a/topics/transformation/xbgf/tests/strip6.baseline +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - expr - - - value - - int - - - - - - - expr - - - - expr - - - - op - - binary_op - - - - - expr - - - - - - - expr - - - - - op - - unary_op - - - - - expr - - - - - \ No newline at end of file diff --git a/topics/transformation/xbgf/tests/unterminalize.baseline b/topics/transformation/xbgf/tests/unterminalize.baseline new file mode 100644 index 00000000..3bccc94d --- /dev/null +++ b/topics/transformation/xbgf/tests/unterminalize.baseline @@ -0,0 +1,63 @@ + + + + + + expr + + + value + + int + + + + + + + expr + + + + expr + + + + op + + binary_op + + + + + expr + + + + + + + expr + + + + + op + + unary_op + + + + + expr + + + + + + nonexpr + + test + + + \ No newline at end of file diff --git a/topics/transformation/xbgf/tests/strip6.bgf b/topics/transformation/xbgf/tests/unterminalize.bgf similarity index 90% rename from topics/transformation/xbgf/tests/strip6.bgf rename to topics/transformation/xbgf/tests/unterminalize.bgf index cf434d0f..2feb1d2b 100644 --- a/topics/transformation/xbgf/tests/strip6.bgf +++ b/topics/transformation/xbgf/tests/unterminalize.bgf @@ -58,4 +58,10 @@ - + + nonexpr + + test + + + \ No newline at end of file diff --git a/topics/transformation/xbgf/tests/strip6.xbgf b/topics/transformation/xbgf/tests/unterminalize.xbgf similarity index 68% rename from topics/transformation/xbgf/tests/strip6.xbgf rename to topics/transformation/xbgf/tests/unterminalize.xbgf index c39e9759..4d849e0b 100644 --- a/topics/transformation/xbgf/tests/strip6.xbgf +++ b/topics/transformation/xbgf/tests/unterminalize.xbgf @@ -1,7 +1,5 @@ - - - + expr