From eb91ab681eb0b9f9f0dfd5558bfd7218f425200d Mon Sep 17 00:00:00 2001 From: SamyaDaleh Date: Tue, 16 Jan 2024 13:27:54 +0100 Subject: [PATCH] #302 reverting back to Paull as default left-recursion removal. Grammars generally are larger than with Paull. Need to investigate optimizations before deciding about optimized switch --- .../com/github/samyadaleh/cltoolbox/common/cfg/Cfg.java | 2 +- .../github/samyadaleh/cltoolbox/common/cfg/CfgTest.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/samyadaleh/cltoolbox/common/cfg/Cfg.java b/src/main/java/com/github/samyadaleh/cltoolbox/common/cfg/Cfg.java index 4c8417d..ebd560f 100644 --- a/src/main/java/com/github/samyadaleh/cltoolbox/common/cfg/Cfg.java +++ b/src/main/java/com/github/samyadaleh/cltoolbox/common/cfg/Cfg.java @@ -247,7 +247,7 @@ Cfg getCfgWithoutDirectLeftRecursion() { * loops have to be removed first. */ public Cfg getCfgWithoutLeftRecursion() throws ParseException { - return LeftRecursion.removeLeftRecursionMoore(this); + return LeftRecursion.removeLeftRecursionPaull(this); } /** diff --git a/src/test/java/com/github/samyadaleh/cltoolbox/common/cfg/CfgTest.java b/src/test/java/com/github/samyadaleh/cltoolbox/common/cfg/CfgTest.java index c0f990e..76d19f3 100644 --- a/src/test/java/com/github/samyadaleh/cltoolbox/common/cfg/CfgTest.java +++ b/src/test/java/com/github/samyadaleh/cltoolbox/common/cfg/CfgTest.java @@ -220,10 +220,10 @@ public void testRemoveIndirectLeftRecursionMoore() .getCfgWithoutEmptyProductions().getCfgWithoutNonGeneratingSymbols() .getCfgWithoutNonReachableSymbols().getCfgWithoutLeftRecursion(); assertEquals("G = \n" + - "N = {S, A, S:S, S:A, A:A, A:S, A:b, S:b}\n" + + "N = {S, A, A1}\n" + "T = {a, b}\n" + "S = S\n" + - "P = {S:S -> a S:A, S:A -> a, A:A -> a A:S, A:b -> A:S, A:S -> a, S -> b S:b, S:b -> ε}\n", + "P = {S -> A a, S -> b, A -> b a, A1 -> ε, A -> b a A1, A1 -> a a A1}\n", cfgwlr.toString()); } @@ -269,10 +269,10 @@ public void testLeftRecursionNotRemoved() cfg, "cfg-topdown", true); assertFalse(cfgwlr.hasLeftRecursion()); assertEquals("G = \n" + - "N = {N2, N2:t0, N2:N2}\n" + + "N = {N2, N21}\n" + "T = {t0}\n" + "S = N2\n" + - "P = {N2 -> t0 N2:t0, N2:t0 -> ε, N2:t0 -> N2:N2, N2:N2 -> N2 N2:N2, N2:N2 -> N2}\n", + "P = {N2 -> t0, N21 -> ε, N21 -> N2 N21, N2 -> t0 N21}\n", cfgwlr.toString()); }