From e26925cdf6edb7bb57c699f51ce30fea881ea92b Mon Sep 17 00:00:00 2001 From: grammarware Date: Wed, 4 Feb 2009 18:48:04 +0000 Subject: [PATCH] new deyaccification rules git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@436 ab42f6e0-554d-0410-b580-99e487e6eeb2 --- shared/prolog/xbgf1.pro | 84 ++++++++++++++++++- topics/java/lci/xbgf/deyaccify-doc2.xbgf | 3 - topics/java/lci/xbgf/editDeclarations.xbgf | 10 --- .../java/lci/xbgf/editExpressions-jls1.xbgf | 3 - topics/java/lci/xbgf/editExpressions.xbgf | 2 - topics/java/lci/xbgf/extendModifiers.xbgf | 1 - topics/java/lci/xbgf/generalizeModifiers.xbgf | 7 -- .../java/lci/xbgf/generalizeNames-doc1.xbgf | 1 - topics/java/lci/xbgf/generalizeNames.xbgf | 1 - topics/java/lci/xbgf/inlineStatements.xbgf | 1 - topics/java/lci/xbgf/refactor-app1.xbgf | 1 - topics/java/lci/xbgf/refactor-app3.xbgf | 30 ++++++- .../java/lci/xbgf/refactorClasses-doc2.xbgf | 3 - .../java/lci/xbgf/refactorClasses-doc3.xbgf | 5 -- .../lci/xbgf/refactorDeclarations-doc2.xbgf | 4 - .../lci/xbgf/refactorDeclarations-doc3.xbgf | 3 - topics/java/lci/xbgf/refactorEnums.xbgf | 1 - .../lci/xbgf/refactorExpressions-doc3.xbgf | 4 +- topics/java/lci/xbgf/refactorExpressions.xbgf | 1 - .../lci/xbgf/refactorInterfaces-doc2.xbgf | 2 - .../lci/xbgf/refactorInterfaces-doc3.xbgf | 6 +- .../lci/xbgf/refactorStatements-jls1.xbgf | 6 -- topics/java/lci/xbgf/refactorTypes-doc2.xbgf | 1 - topics/java/lci/xbgf/refactorTypes-doc3.xbgf | 2 - topics/java/lci/xbgf/refactorTypes-jls1.xbgf | 1 - 25 files changed, 115 insertions(+), 68 deletions(-) diff --git a/shared/prolog/xbgf1.pro b/shared/prolog/xbgf1.pro index 9ee48ac1..a5e0ea58 100644 --- a/shared/prolog/xbgf1.pro +++ b/shared/prolog/xbgf1.pro @@ -147,7 +147,89 @@ designate(P1,g(Rs,Ps1),g(Rs,Ps2)) % Use EBNF-based regular expression operator instead of BNF encoding % -deyaccify(N,g(Rs,Ps1),g(Rs,Ps2)) +deyaccify(N,g(Rs,Ps1),g(Rs,Ps3)) + :- + splitN(Ps1,N,Ps2,Ps2a,Ps2b), + require( + ( length(Ps2, Len), Len > 1 ), + 'Nonterminal ~q must be defined vertically for deyaccification to work.', + [N]), + Ps2 = [P1,P2], + require( + once(xbgf1:newdeyaccify_rules(N,P1,P2,P3)), + 'Nonterminal ~q is not deyaccifiable: ~q and ~q', + [N,P1,P2]), + append(Ps2a,[P3|Ps2b],Ps3). + +% N: Nab|x -> N: x(ab)* +newdeyaccify_rules(N,P1,P2,P3) + :- + P1 = p(As,N,','([n(N)|Xs1])), + P2 = p(As,N,Xs2), + normalizeG(','(Xs1),Xs3), + normalizeG(','([Xs2]),Xs4), + ( + eqX(Xs3,Xs4),!, + P3 = p(As,N,+(','(Xs1))) + ; + P3 = p(As,N,','([Xs2,*(','(Xs1))])) + ). +% N: abN|x -> N: (ab)*x +newdeyaccify_rules(N,P1,P2,P3) + :- + P1 = p(As,N,','(Xs1)), + tailless(Xs1,[],Xs2), + tailof(Xs1,n(N)), + P2 = p(As,N,Xs3), + normalizeG(','(Xs2),Xs4), + normalizeG(','([Xs3]),Xs5), + ( + eqX(Xs4,Xs5),!, + P3 = p(As,N,+(','(Xs2))) + ; + P3 = p(As,N,','([*(','(Xs2)),Xs3])) + ). +%%%%%% +% N: Nab|x -> N: x(ab)* +newdeyaccify_rules(N,P1,P2,P3) + :- + P2 = p(As,N,','([n(N)|Xs1])), + P1 = p(As,N,Xs2), + normalizeG(','(Xs1),Xs3), + normalizeG(','([Xs2]),Xs4), + ( + eqX(Xs3,Xs4),!, + P3 = p(As,N,+(','(Xs1))) + ; + P3 = p(As,N,','([Xs2,*(','(Xs1))])) + ). +% N: abN|x -> N: (ab)*x +newdeyaccify_rules(N,P1,P2,P3) + :- + P2 = p(As,N,','(Xs1)), + tailless(Xs1,[],Xs2), + tailof(Xs1,n(N)), + P1 = p(As,N,Xs3), + normalizeG(','(Xs2),Xs4), + normalizeG(','([Xs3]),Xs5), + ( + eqX(Xs4,Xs5),!, + P3 = p(As,N,+(','(Xs2))) + ; + P3 = p(As,N,','([*(','(Xs2)),Xs3])) + ). + +% Needed -> prelude.pro +% Not needed -> throw away +tailof([X],X). +tailof([_|T],X) :- tailof(T,X). +tailless([_],L1,L1). +tailless([H|T],L1,L3) + :- + concat([L1,[H]],L2), + tailless(T,L2,L3). + +olddeyaccify(N,g(Rs,Ps1),g(Rs,Ps2)) :- splitN1(Ps1,N,P1,Ps2a,Ps2b), P1 = p(As,N,X1), diff --git a/topics/java/lci/xbgf/deyaccify-doc2.xbgf b/topics/java/lci/xbgf/deyaccify-doc2.xbgf index ea0210a1..02dd8b51 100644 --- a/topics/java/lci/xbgf/deyaccify-doc2.xbgf +++ b/topics/java/lci/xbgf/deyaccify-doc2.xbgf @@ -8,7 +8,6 @@ vs. - [], ;([n(SwitchBlockStatementGroup), ,([n(SwitchBlockStatementGroups), n(SwitchBlockStatementGroup)])]) --> - SwitchBlockStatementGroups SwitchBlockStatementGroups @@ -56,7 +55,6 @@ vs. - [], ;([n(CatchClause), ,([n(Catches), n(CatchClause)])]) --> - Catches Catches - BlockStatements BlockStatements diff --git a/topics/java/lci/xbgf/editDeclarations.xbgf b/topics/java/lci/xbgf/editDeclarations.xbgf index e6f03541..656a52d0 100644 --- a/topics/java/lci/xbgf/editDeclarations.xbgf +++ b/topics/java/lci/xbgf/editDeclarations.xbgf @@ -65,7 +65,6 @@ with p([], 'ExtendsInterfaces', ;([','([t(extends), n('InterfaceType')]), ','([n('ExtendsInterfaces'), t((',')), n('InterfaceType')])])) --> - ExtendsInterfaces ExtendsInterfaces TypeList @@ -234,7 +233,6 @@ with p([], 'SwitchLabels', ;([n('SwitchLabel'), ','([n('SwitchLabels'), n('SwitchLabel')])])), --> - SwitchLabels SwitchLabels - VariableInitializers VariableInitializers VariableInitializers @@ -368,7 +365,6 @@ vs. - [], ,([t({), *(n(ClassBodyDeclaration)), t(})]) --> - ClassBodyDeclarations ClassBodyDeclarations ClassBodyDeclarations @@ -398,7 +394,6 @@ vs. - [], ,([t({), *(n(InterfaceBodyDeclaration)), t(})]) --> - InterfaceMemberDeclarations InterfaceMemberDeclarations InterfaceMemberDeclarations @@ -434,9 +429,7 @@ vs. - [], ,([?(,([t(package), n(QualifiedIdentifier), t((;))])), *(n(ImportDeclaration)), *(n(TypeDeclaration))]) --> - ImportDeclarations ImportDeclarations - TypeDeclarations TypeDeclarations ImportDeclarations TypeDeclarations @@ -512,7 +505,6 @@ - Modifiers Modifiers Modifiers @@ -768,7 +760,6 @@ InterfaceMemberDecl - MethodDeclarator MethodDeclarator MethodDeclarator @@ -1127,7 +1118,6 @@ vs. - [], ,([n(FormalParameters), n(BracketsOpt), ?(,([t(throws), n(QualifiedIdentifierList)])), t((;))]) --> - FormalParameterList FormalParameterList diff --git a/topics/java/lci/xbgf/editExpressions-jls1.xbgf b/topics/java/lci/xbgf/editExpressions-jls1.xbgf index bec0095b..715145fe 100644 --- a/topics/java/lci/xbgf/editExpressions-jls1.xbgf +++ b/topics/java/lci/xbgf/editExpressions-jls1.xbgf @@ -14,10 +14,8 @@ PrimaryNoNewArray PrimaryNoNewArray - Dims Dims Dims - DimExprs DimExprs DimExprs DimExpr @@ -86,7 +84,6 @@ vs. - [], ,([t(new), n(QualifiedIdentifier), n(Arguments)]) --> - ArgumentList ArgumentList ArgumentList diff --git a/topics/java/lci/xbgf/editExpressions.xbgf b/topics/java/lci/xbgf/editExpressions.xbgf index c8a3bc59..66f1df77 100644 --- a/topics/java/lci/xbgf/editExpressions.xbgf +++ b/topics/java/lci/xbgf/editExpressions.xbgf @@ -261,7 +261,6 @@ vs. - [], ;([n(StatementExpressionList), ,([?(t(final)), n(Type), n(VariableDeclarators)])]) --> - StatementExpressionList StatementExpressionList @@ -292,7 +291,6 @@ vs. - [], ,([t({), ?(n(VariableInitializers)), ?(t((,))), t(})]) --> - VariableInitializers VariableInitializers VariableInitializers diff --git a/topics/java/lci/xbgf/extendModifiers.xbgf b/topics/java/lci/xbgf/extendModifiers.xbgf index ccc14f4d..465827b8 100644 --- a/topics/java/lci/xbgf/extendModifiers.xbgf +++ b/topics/java/lci/xbgf/extendModifiers.xbgf @@ -215,7 +215,6 @@ vs. - [], ;([n(ConstantModifier), ,([n(ConstantModifier), n(ConstantModifers)])]) --> - ConstantModifiers ConstantModifiers diff --git a/topics/java/lci/xbgf/generalizeModifiers.xbgf b/topics/java/lci/xbgf/generalizeModifiers.xbgf index f617f122..12f84ee3 100644 --- a/topics/java/lci/xbgf/generalizeModifiers.xbgf +++ b/topics/java/lci/xbgf/generalizeModifiers.xbgf @@ -55,19 +55,12 @@ --> - AbstractMethodModifiers AbstractMethodModifiers - InterfaceModifiers InterfaceModifiers - MethodModifiers MethodModifiers - FieldModifiers FieldModifiers - ConstructorModifiers ConstructorModifiers - ClassModifiers ClassModifiers - ConstantModifiers ConstantModifiers diff --git a/topics/java/lci/xbgf/generalizeNames.xbgf b/topics/java/lci/xbgf/generalizeNames.xbgf index 1634a9aa..aa173bab 100644 --- a/topics/java/lci/xbgf/generalizeNames.xbgf +++ b/topics/java/lci/xbgf/generalizeNames.xbgf @@ -61,7 +61,6 @@ vs QualifiedIdentifier - QualifiedIdentifier QualifiedIdentifier \ No newline at end of file diff --git a/topics/java/lci/xbgf/inlineStatements.xbgf b/topics/java/lci/xbgf/inlineStatements.xbgf index 46996e59..b86aecf9 100644 --- a/topics/java/lci/xbgf/inlineStatements.xbgf +++ b/topics/java/lci/xbgf/inlineStatements.xbgf @@ -170,7 +170,6 @@ - SwitchLabels SwitchLabels SwitchStatement diff --git a/topics/java/lci/xbgf/refactor-app1.xbgf b/topics/java/lci/xbgf/refactor-app1.xbgf index 14169bb5..0e4ad507 100644 --- a/topics/java/lci/xbgf/refactor-app1.xbgf +++ b/topics/java/lci/xbgf/refactor-app1.xbgf @@ -10,7 +10,6 @@ --> SimpleName QualifiedName - Name Name diff --git a/topics/java/lci/xbgf/refactor-app3.xbgf b/topics/java/lci/xbgf/refactor-app3.xbgf index 27e97ca8..33115366 100644 --- a/topics/java/lci/xbgf/refactor-app3.xbgf +++ b/topics/java/lci/xbgf/refactor-app3.xbgf @@ -7,9 +7,35 @@ - [], ,([n(Annotation), ?(n(Annotations))]) vs. - [], ;([n(Annotation), ,([n(Annotations), n(Annotation)])]) - - Later this should become just deyaccify --> + + + + + Annotations + + + + + + + Annotations + + + + + + + + Annotations + + + + Annotations + + + Annotations + Annotations - ClassBodyDeclarations ClassBodyDeclarations ClassBodyDeclarations @@ -296,7 +295,6 @@ - FormalParameterList FormalParameterList FormalParameterList @@ -330,7 +328,6 @@ ','([n('ModifiersOpt'), t(void), n('Identifier'), n('FormalParameters'), ?(','([t(throws), n('TypeList')])), n('MethodBody')])), --> - MethodDeclarator MethodDeclarator BracketsOpt diff --git a/topics/java/lci/xbgf/refactorClasses-doc3.xbgf b/topics/java/lci/xbgf/refactorClasses-doc3.xbgf index 789129c0..0cadcfc0 100644 --- a/topics/java/lci/xbgf/refactorClasses-doc3.xbgf +++ b/topics/java/lci/xbgf/refactorClasses-doc3.xbgf @@ -103,7 +103,6 @@ vs. - [], ,([t({), ?(n(ClassBodyDeclarations)), t(})]) --> - ClassBodyDeclarations ClassBodyDeclarations ClassBodyDeclarations @@ -427,7 +426,6 @@ Identifier "(" [ FormalParameterList ] ")" MethodDeclarator "[" "]" --> - MethodDeclarator MethodDeclarator MethodDeclarator @@ -692,7 +690,6 @@ vs. - [], ;([n(Identifier), ,([n(VariableDeclaratorId), t([), t(])])]) --> - VariableDeclaratorId VariableDeclaratorId - TypeParameterList TypeParameterList TypeParameterList @@ -1109,7 +1105,6 @@ AdditionalBound is defined as: "&" InterfaceType --> - AdditionalBoundList AdditionalBoundList AdditionalBoundList diff --git a/topics/java/lci/xbgf/refactorDeclarations-doc2.xbgf b/topics/java/lci/xbgf/refactorDeclarations-doc2.xbgf index 116d72d5..caf9558c 100644 --- a/topics/java/lci/xbgf/refactorDeclarations-doc2.xbgf +++ b/topics/java/lci/xbgf/refactorDeclarations-doc2.xbgf @@ -2,7 +2,6 @@ xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf"> - VariableDeclarators VariableDeclarators - VariableDeclaratorId VariableDeclaratorId VariableDeclarator @@ -138,7 +136,6 @@ - [], ,([?(n(PackageDeclaration)), ?(n(ImportDeclarations)), ?(n(TypeDeclarations))]) --> PackageDeclaration - ImportDeclarations ImportDeclarations ImportDeclarations @@ -161,7 +158,6 @@ - TypeDeclarations TypeDeclarations TypeDeclarations diff --git a/topics/java/lci/xbgf/refactorDeclarations-doc3.xbgf b/topics/java/lci/xbgf/refactorDeclarations-doc3.xbgf index 117087dc..532deedf 100644 --- a/topics/java/lci/xbgf/refactorDeclarations-doc3.xbgf +++ b/topics/java/lci/xbgf/refactorDeclarations-doc3.xbgf @@ -2,7 +2,6 @@ xmlns:bgf="http://planet-sl.org/bgf" xmlns:xbgf="http://planet-sl.org/xbgf"> - VariableDeclarators VariableDeclarators PackageDeclaration - ImportDeclarations ImportDeclarations ImportDeclarations @@ -157,7 +155,6 @@ - TypeDeclarations TypeDeclarations TypeDeclarations diff --git a/topics/java/lci/xbgf/refactorEnums.xbgf b/topics/java/lci/xbgf/refactorEnums.xbgf index e8723d92..091e5bc9 100644 --- a/topics/java/lci/xbgf/refactorEnums.xbgf +++ b/topics/java/lci/xbgf/refactorEnums.xbgf @@ -23,7 +23,6 @@ vs. - [], ,([t((), ?(n(ArgumentList)), t())]) --> - ArgumentList ArgumentList ArgumentList diff --git a/topics/java/lci/xbgf/refactorExpressions-doc3.xbgf b/topics/java/lci/xbgf/refactorExpressions-doc3.xbgf index 81e3f587..f733279a 100644 --- a/topics/java/lci/xbgf/refactorExpressions-doc3.xbgf +++ b/topics/java/lci/xbgf/refactorExpressions-doc3.xbgf @@ -130,7 +130,6 @@ - Dims Dims @@ -1291,6 +1290,9 @@ + + PostfixExpression + PostfixExpression TMP diff --git a/topics/java/lci/xbgf/refactorExpressions.xbgf b/topics/java/lci/xbgf/refactorExpressions.xbgf index 431ced0d..fbcda439 100644 --- a/topics/java/lci/xbgf/refactorExpressions.xbgf +++ b/topics/java/lci/xbgf/refactorExpressions.xbgf @@ -192,7 +192,6 @@ vs - PostfixExpression PostfixExpression diff --git a/topics/java/lci/xbgf/refactorInterfaces-doc2.xbgf b/topics/java/lci/xbgf/refactorInterfaces-doc2.xbgf index 030e369a..b4ddc5b3 100644 --- a/topics/java/lci/xbgf/refactorInterfaces-doc2.xbgf +++ b/topics/java/lci/xbgf/refactorInterfaces-doc2.xbgf @@ -86,7 +86,6 @@ - ExtendsInterfaces ExtendsInterfaces TypeList @@ -102,7 +101,6 @@ vs. - [], ,([t({), ?(n(InterfaceMemberDeclarations)), t(})]) --> - InterfaceMemberDeclarations InterfaceMemberDeclarations InterfaceMemberDeclarations diff --git a/topics/java/lci/xbgf/refactorInterfaces-doc3.xbgf b/topics/java/lci/xbgf/refactorInterfaces-doc3.xbgf index 3fd1b5bd..ec0c8ed0 100644 --- a/topics/java/lci/xbgf/refactorInterfaces-doc3.xbgf +++ b/topics/java/lci/xbgf/refactorInterfaces-doc3.xbgf @@ -92,7 +92,6 @@ - ExtendsInterfaces ExtendsInterfaces TypeList @@ -147,7 +146,6 @@ vs. - [], ,([t({), ?(n(InterfaceMemberDeclarations)), t(})]) --> - InterfaceMemberDeclarations InterfaceMemberDeclarations InterfaceMemberDeclarations @@ -252,7 +250,6 @@ vs. - [], ;([n(Annotation), ,([n(Annotations), n(Annotation)])]) --> - Annotations Annotations - ElementValues ElementValues - + diff --git a/topics/java/lci/xbgf/refactorStatements-jls1.xbgf b/topics/java/lci/xbgf/refactorStatements-jls1.xbgf index 79af6f73..4920c6da 100644 --- a/topics/java/lci/xbgf/refactorStatements-jls1.xbgf +++ b/topics/java/lci/xbgf/refactorStatements-jls1.xbgf @@ -34,7 +34,6 @@ vs. - [], *(n(SwitchBlockStatementGroup)) --> - SwitchBlockStatementGroups SwitchBlockStatementGroups SwitchBlockStatementGroups @@ -280,7 +279,6 @@ - [], ,([t({), n(BlockStatements), t(})]) ... --> - BlockStatements BlockStatements BlockStatements @@ -386,7 +384,6 @@ vs p([], 'MoreStatementExpressions', *(','([t((',')), n('StatementExpression')]))), --> - StatementExpressionList StatementExpressionList @@ -446,7 +443,6 @@ vs. - [], +n(CatchClause) --> - Catches Catches - VariableDeclarators VariableDeclarators - VariableDeclaratorId VariableDeclaratorId diff --git a/topics/java/lci/xbgf/refactorTypes-doc2.xbgf b/topics/java/lci/xbgf/refactorTypes-doc2.xbgf index 3aaaa835..edadb7b5 100644 --- a/topics/java/lci/xbgf/refactorTypes-doc2.xbgf +++ b/topics/java/lci/xbgf/refactorTypes-doc2.xbgf @@ -154,7 +154,6 @@ TypeList - TypeList TypeList - TypeDeclSpecifier TypeDeclSpecifier