Permalink
Browse files

fixed associativity issues

git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@764 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information...
grammarware committed Feb 3, 2010
1 parent d580ad2 commit d2be3a005f324f6fe046164a11965c56efb5fbb1
View
@@ -631,6 +631,7 @@ massage_rules(+(*(X)),*(X)).
massage_rules(*(?(X)),*(X)).
massage_rules(*(+(X)),*(X)).
massage_rules(*(*(X)),*(X)).
%% All possible choice combinations
% true|...
%massage_rules(?(';'([X|L1])),';'([L2])) :- append(L3,L1,L2), length(L3,2),member(X, L3),member(true,L3).
@@ -639,34 +640,116 @@ massage_rules(*(*(X)),*(X)).
% Not general enough but a good explanation of what follows
%
% massage_rules(?(X),';'(L)) :- length(L,2),member( X, L),member(true,L).
%
% x? -> x | ε
% massage_rules(?(X),';'(L)) :- length(L,2),member(?(X),L),member(true,L).
% x? -> x? | ε
massage_rules(?(X),';'(L))
:-
append(L1,[true|L2],L),
append(L1,L2,L3),
normalizeG(';'(L3),Y),
eqX(X,Y).
(
eqX(X,Y)
;
eqX(?(X),Y)
).
% massage_rules(*(X),';'(L)) :- length(L,2),member(+(X),L),member(true,L).
% x* -> x+ | ε
% massage_rules(*(X),';'(L)) :- length(L,2),member(*(X),L),member(true,L).
% x* -> x* | ε
massage_rules(*(X),';'(L))
:-
append(L1,[true|L2],L),
append(L1,L2,L3),
normalizeG(';'(L3),Y),
(
eqX(+(X),Y)
;
eqX(*(X),Y)
).
massage_rules(?(X),';'(L)) :- length(L,2),member(?(X),L),member(true,L).
massage_rules(*(X),';'(L)) :- length(L,2),member(+(X),L),member(true,L).
massage_rules(*(X),';'(L)) :- length(L,2),member(*(X),L),member(true,L).
% x|...
massage_rules(X,';'([s(_,X),s(_,X)])).
massage_rules(?(X),';'(L)) :- length(L,2),member(?(X),L),member(X,L).
massage_rules(+(X),';'(L)) :- length(L,2),member(+(X),L),member(X,L).
massage_rules(*(X),';'(L)) :- length(L,2),member(*(X),L),member(X,L).
% x?|...
massage_rules(*(X),';'(L)) :- length(L,2),member(+(X),L),member(?(X),L).
massage_rules(*(X),';'(L)) :- length(L,2),member(*(X),L),member(?(X),L).
% x+|...
massage_rules(*(X),';'(L)) :- length(L,2),member(*(X),L),member(+(X),L).
%massage_rules(X,';'([s(_,X),s(_,X)])).
% x -> s::x | ...
massage_rules(X,Y)
:-
normalizeG(Y,';'(L)),
listofselectors(X,L).
% massage_rules(*(X),';'(L)) :- length(L,2),member(*(X),L),member(X,L).
% massage_rules(*(X),';'(L)) :- length(L,2),member(*(X),L),member(?(X),L).
massage_rules(*(X),';'(L))
:-
append(L1,[*(X)|L2],L),
append(L1,L2,L3),
normalizeG(';'(L3),Y),
(
eqX(X,Y)
;
eqX(?(X),Y)
;
eqX(+(X),Y)
).
% massage_rules(*(X),';'(L)) :- length(L,2),member(?(X),L),member(+(X),L).
massage_rules(*(X),';'(L))
:-
append(L1,[+(X)|L2],L),
append(L1,L2,L3),
normalizeG(';'(L3),Y),
eqX(?(X),Y).
% massage_rules(?(X),';'(L)) :- length(L,2),member(?(X),L),member(X,L).
massage_rules(?(X),';'(L))
:-
append(L1,[X|L2],L),
append(L1,L2,L3),
normalizeG(';'(L3),Y),
eqX(?(X),Y).
% massage_rules(+(X),';'(L)) :- length(L,2),member(+(X),L),member(X,L).
massage_rules(+(X),';'(L))
:-
append(L1,[X|L2],L),
append(L1,L2,L3),
normalizeG(';'(L3),Y),
eqX(+(X),Y).
%% All possible sequential combinations
massage_rules(*(X),','([*(X),*(X)])).
massage_rules(+(X),','(L)) :- length(L,2),member( X, L),member(*(X),L).
massage_rules(+(X),','(L)) :- length(L,2),member(+(X),L),member(?(X),L).
massage_rules(*(X),','(L)) :- length(L,2),member(*(X),L),member(?(X),L).
massage_rules(+(X),','(L)) :- length(L,2),member(+(X),L),member(*(X),L).
% massage_rules(*(X),','([*(X),*(X)])).
massage_rules(*(X),Y)
:-
normalizeG(Y,','(L)),
listofthesame(*(X),L).
% massage_rules(+(X),','(L)) :- length(L,2),member(+(X),L),member(?(X),L).
% massage_rules(+(X),','(L)) :- length(L,2),member(+(X),L),member(*(X),L).
massage_rules(+(X),','(L))
:-
append(L1,[+(X)|L2],L),
append(L1,L2,L3),
normalizeG(','(L3),Y),
(eqX(?(X),Y);eqX(*(X),Y)).
% massage_rules(+(X),','(L)) :- length(L,2),member( X, L),member(*(X),L).
massage_rules(+(X),','(L))
:-
append(L1,[X|L2],L),
append(L1,L2,L3),
normalizeG(','(L3),Y),
eqX(*(X),Y).
% massage_rules(*(X),','(L)) :- length(L,2),member(*(X),L),member(?(X),L).
massage_rules(*(X),','(L))
:-
append(L1,[?(X)|L2],L),
append(L1,L2,L3),
normalizeG(','(L3),Y),
eqX(*(X),Y).
%% Miscellaneous
massage_rules(','([X,?(','([Y,X]))]),','([?(','([X,Y])),X])).
massage_rules(','([X,+(','([Y,X]))]),','([+(','([X,Y])),X])).
@@ -684,6 +767,12 @@ massage_rules(','(L1),','(L2))
append(L3,[s(_,true)|L4],L2),
append(L3,L4,L1).
listofselectors(_,[]).
listofselectors(X,[Y|L]) :- eqX(s(_,X),Y), listofselectors(X,L).
listofthesame(_,[]).
listofthesame(X,[Y|L]) :- eqX(X,Y), listofthesame(X,L).
%
% p([l(permute)], f, n(p))
%
@@ -0,0 +1,34 @@
<?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>
<selectable>
<selector>one</selector>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
<bgf:expression>
<selectable>
<selector>two</selector>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
<bgf:expression>
<selectable>
<selector>three</selector>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
</choice>
</bgf:expression>
</bgf:production>
</bgf:grammar>
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<bgf:grammar xmlns:bgf="http://planet-sl.org/bgf">
<bgf:production>
<nonterminal>foo</nonterminal>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
</bgf:production>
</bgf:grammar>
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<xbgf:sequence xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf">
<xbgf:massage>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
<bgf:expression>
<choice>
<bgf:expression>
<selectable>
<selector>one</selector>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
<bgf:expression>
<selectable>
<selector>two</selector>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
<bgf:expression>
<selectable>
<selector>three</selector>
<bgf:expression>
<nonterminal>bar</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
</choice>
</bgf:expression>
</xbgf:massage>
</xbgf:sequence>

0 comments on commit d2be3a0

Please sign in to comment.