From 64f39dc8405acb909f4abf1842fd1317fa42b95c Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Sun, 9 Jul 2023 11:47:29 +0200 Subject: [PATCH] One Value --- .../jeffcheasey88/peeratcode/parser/Bag.java | 2 + .../peeratcode/parser/java/JavaParser.java | 37 +++++++++++-------- .../peeratcode/parser/java/Value.java | 33 +++++++++++++---- .../parser/state/RedirectStateTree.java | 2 +- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/Bag.java b/src/be/jeffcheasey88/peeratcode/parser/Bag.java index a6a37d2..51d3de7 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/Bag.java +++ b/src/be/jeffcheasey88/peeratcode/parser/Bag.java @@ -19,6 +19,7 @@ public class Bag{ } public void set(Object value){ + System.out.println("bag set "+value); this.value = value; } @@ -27,6 +28,7 @@ public class Bag{ } public void set(String key, Object value){ + System.out.println("bag set "+key+" -> "+value); this.map.put(key, value); } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 885cb0b..f49df83 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -18,6 +18,7 @@ import be.jeffcheasey88.peeratcode.parser.TokenValidator; import be.jeffcheasey88.peeratcode.parser.Tokenizer; import be.jeffcheasey88.peeratcode.parser.java.Value.BiValue; import be.jeffcheasey88.peeratcode.parser.java.Value.TriValue; +import be.jeffcheasey88.peeratcode.parser.java.Value.ValueContainer; import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree; import be.jeffcheasey88.peeratcode.parser.state.StateTree; @@ -129,8 +130,10 @@ public class JavaParser extends Parser { StateTree value_q0 = value(LAMBDA_5, LAMBDA_6, LAMBDA_7, LAMBDA_8, LAMBDA_10, LAMBDA_11, LAMBDA_12, LAMBDA_13, LAMBDA_14, LAMBDA_15, LAMBDA_16, LAMBDA_17, LAMBDA_18, LAMBDA_19, LAMBDA_20, LAMBDA_21, LAMBDA_23, LAMBDA_24, LAMBDA_25, LAMBDA_26, LAMBDA_27, LAMBDA_28, LAMBDA_29); System.out.println("----"); - //(ab = (cd & 3)) - tokenizer.getTokens().addAll(build("(","ab","=","(","cd","&","34",")",")")); + //(ab = (cd & 34)) +// tokenizer.getTokens().addAll(build("(","ab","=","(","cd","&","34",")",")")); + tokenizer.getTokens().addAll(build("(","ab","=","cd",")")); +// tokenizer.getTokens().addAll(build("(","ab",")")); value_q0.seed(tokenizer, null); System.out.println("----"); @@ -203,25 +206,27 @@ public class JavaParser extends Parser { Function LAMBDA_28, Function LAMBDA_29 ){ + BiFunction END_NATIVE_VALUE = (element, validator) -> { + System.out.println("\tnative\t"+element); + System.out.println("\t"+validator.getBag()); + return new ValueContainer(validator.getBag().get("?").get()); + }; BiFunction END_VALUE = (element, validator) -> { //single value - System.out.println("end value "+validator.getBag()); - Bag bag = validator.getBag(); - Value v = new Value(bag); - bag.set("result",v); + System.out.println("\tvalue\t"+element); + Value v = new Value(validator.getBag().get()); + validator.getBag().set(v); return v; }; BiFunction END_BIVALUE = (element, validator) -> { //create new value from parent & created single value - System.out.println("end bi value "+validator.getBag()); - Bag bag = validator.getBag(); - return new BiValue((Value)element, bag.get("?").get("result")); + System.out.println("\tbivalue\t"+element); + return null; }; BiFunction END_TRIVALUE = (element, validator) -> { //same but for val ? val : val - System.out.println("end tri value "+validator.getBag()); - Bag bag = validator.getBag(); - return new TriValue(bag); + System.out.println("\ttrivalue\t"+element); + return new TriValue(); }; StateTree value_q0 = new StateTree<>(); StateTree value_q22 = new StateTree<>(); @@ -232,7 +237,7 @@ public class JavaParser extends Parser { value_q24.then(new RedirectStateTree<>(value_q0,(bag) -> "?")).end(END_BIVALUE); // < value_q24.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).end(END_BIVALUE); // <= StateTree value_q41 = value_q24.then(LAMBDA_5); - value_q41.then(new RedirectStateTree<>(value_q0,(bag) -> "?")).end(END_BIVALUE); // << + value_q41.then(new RedirectStateTree<>(value_q0,(bag) -> "<<")).end(END_BIVALUE); // << value_q41.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).end(END_BIVALUE); // <<= StateTree value_q25 = value_q22.then(LAMBDA_6); value_q25.then(new RedirectStateTree<>(value_q0,(bag) -> "?")).end(END_BIVALUE); // > @@ -287,9 +292,9 @@ public class JavaParser extends Parser { value_q1.end(END_VALUE).then(value_q22); StateTree value_q11 = value_q1.then(LAMBDA_25); value_q11.then(value_q1); - value_q0.then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_VALUE).then(value_q22); - value_q0.then(LAMBDA_26).then(LAMBDA_27).then(LAMBDA_26).end(END_VALUE).then(value_q22); - value_q0.then(LAMBDA_28).then(LAMBDA_29).then(LAMBDA_28).end(END_VALUE).then(value_q22); + value_q0.then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_NATIVE_VALUE).then(value_q22); + value_q0.then(LAMBDA_26).then(LAMBDA_27).then(LAMBDA_26).end(END_NATIVE_VALUE).then(value_q22); + value_q0.then(LAMBDA_28).then(LAMBDA_29).then(LAMBDA_28).end(END_NATIVE_VALUE).then(value_q22); return value_q0; } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Value.java b/src/be/jeffcheasey88/peeratcode/parser/java/Value.java index 58c026b..cb05059 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Value.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Value.java @@ -1,6 +1,5 @@ package be.jeffcheasey88.peeratcode.parser.java; -import be.jeffcheasey88.peeratcode.parser.Bag; import be.jeffcheasey88.peeratcode.parser.Token; public class Value extends JavaElement{ @@ -9,9 +8,9 @@ public class Value extends JavaElement{ protected Value(){} - public Value(Bag bag){ - this.token = bag.get(); - System.out.println("NEW value "+token); + public Value(Token token){ + this.token = token; + System.out.println(this); } @Override @@ -19,6 +18,22 @@ public class Value extends JavaElement{ return "[Value="+token+"]"; } + public static class ValueContainer extends Value{ + + private Value value; + + public ValueContainer(Value value){ + this.value = value; + System.out.println(this); + } + + @Override + public String toString(){ + return "[ContainerValue="+value+"]"; + } + + } + public static class BiValue extends Value{ private Value left; @@ -27,15 +42,19 @@ public class Value extends JavaElement{ public BiValue(Value left, Value right){ this.left = left; this.right = right; - System.out.println("NEW BiValue "+left+"|"+right); + System.out.println(this); } + @Override + public String toString(){ + return "[BiValue left="+left+" right="+right+"]"; + } } public static class TriValue extends Value{ - public TriValue(Bag bag){ - super(bag); + public TriValue(){ + } } } diff --git a/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java b/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java index e3f9fb6..0cada2c 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java +++ b/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java @@ -32,7 +32,7 @@ public class RedirectStateTree extends StateTree{ return false; }); Object builded = redirect.internalSeed(branch, (E) element); -// System.out.println("redirect builded "+builded); + System.out.println("redirect "+g+" builded "+builded); if(builded == null) return null; validator.merge(branch);