adds arithmetic diagram syntax diagrammer
authorThomas Walker Lynch <xtujpz@reasoningtechnology.com>
Tue, 13 Aug 2024 07:16:02 +0000 (07:16 +0000)
committerThomas Walker Lynch <xtujpz@reasoningtechnology.com>
Tue, 13 Aug 2024 07:16:02 +0000 (07:16 +0000)
20 files changed:
developer/executor/Arithmetic_Echo [deleted file]
developer/executor/Arithmetic_Echo__Test [deleted file]
developer/executor/Arithmetic_Syntax [new file with mode: 0755]
developer/executor/Arithmetic_Syntax__Test [new file with mode: 0755]
developer/executor/cat_w_names [new file with mode: 0755]
developer/executor/env_GP [new file with mode: 0644]
developer/executor/env_build
developer/executor/makefile
developer/experiment/script2.sh [new file with mode: 0644]
developer/javac/Arithmetic_Echo__Test.java
developer/javac/Arithmetic_Syntax.java
developer/javac/Arithmetic_Syntax_PrintVisitor.java
developer/javac/Arithmetic_Syntax__Test.java [new file with mode: 0644]
developer/test/Arithmetic_Syntax__Test_0.txt [new file with mode: 0644]
developer/test/Arithmetic_Syntax__Test_1.txt [new file with mode: 0644]
developer/test/Arithmetic_Syntax__Test_2.txt [new file with mode: 0644]
developer/test/Arithmetic_Syntax__Test_3.txt [new file with mode: 0644]
developer/test/Arithmetic_Syntax__Test_4.txt [new file with mode: 0644]
developer/test/combined_output.txt [new file with mode: 0644]
executor/env_GP [new file with mode: 0755]

diff --git a/developer/executor/Arithmetic_Echo b/developer/executor/Arithmetic_Echo
deleted file mode 100755 (executable)
index 554719e..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env bash
-/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:jvm:jvm/Arithmetic_Echo.jar Arithmetic_Echo $@
diff --git a/developer/executor/Arithmetic_Echo__Test b/developer/executor/Arithmetic_Echo__Test
deleted file mode 100755 (executable)
index 72a2062..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/usr/bin/env bash
-/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:jvm:jvm/Arithmetic_Echo__Test.jar Arithmetic_Echo__Test $@
diff --git a/developer/executor/Arithmetic_Syntax b/developer/executor/Arithmetic_Syntax
new file mode 100755 (executable)
index 0000000..b23b906
--- /dev/null
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:/var/user_data/Thomas-developer/GQL_to_Cypher/developer/jvm:/var/user_data/Thomas-developer/GQL_to_Cypher/developer/jvm/Arithmetic_Syntax.jar Arithmetic_Syntax $@
diff --git a/developer/executor/Arithmetic_Syntax__Test b/developer/executor/Arithmetic_Syntax__Test
new file mode 100755 (executable)
index 0000000..a38f4df
--- /dev/null
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+/var/user_data/Thomas-developer/GQL_to_Cypher/tool/jdk-22.0.1+8/bin/java -cp /var/user_data/Thomas-developer/GQL_to_Cypher/tool/executor/antlr-4.11.1-complete.jar:/var/user_data/Thomas-developer/GQL_to_Cypher/developer/jvm:/var/user_data/Thomas-developer/GQL_to_Cypher/developer/jvm/Arithmetic_Syntax__Test.jar Arithmetic_Syntax__Test $@
diff --git a/developer/executor/cat_w_names b/developer/executor/cat_w_names
new file mode 100755 (executable)
index 0000000..5a3d173
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+# Check if any arguments are provided (input files or directories)
+if [ $# -eq 0 ]; then
+  echo "Usage: $0 <file1> [file2 ...]"
+  exit 1
+fi
+
+# Loop through all provided arguments (files or directories)
+for file in "$@"; do
+  if [ -f "$file" ]; then
+    echo "#--------------------------------------------------------------------------------"
+    echo "# Filename: ${file}"
+    echo "#"
+    cat "$file"
+  fi
+done
diff --git a/developer/executor/env_GP b/developer/executor/env_GP
new file mode 100644 (file)
index 0000000..01f1899
--- /dev/null
@@ -0,0 +1,18 @@
+# Creating env_GP file in the executor directory
+cat << 'EOF' > ../executor/env_GP
+#!/bin/bash
+# Environment setup for GP
+export GP_PROMPT="GP> "
+export PS1="\[$(tput setaf 2)\]\u@\h:\w$GP_PROMPT\[$(tput sgr0)\] "
+export PROJECT_HOME="/var/user_data/Thomas-developer/GQL_to_Cypher/developer"
+cd $PROJECT_HOME/experiment
+EOF
+
+# Make the file executable
+chmod +x ../executor/env_GP
+
+# Source the env_GP file to set up the environment
+source ../executor/env_GP
+
+# Verify that the environment is set up correctly
+pwd
index 67eb327..8bf159a 100755 (executable)
@@ -8,8 +8,11 @@ fi
 
 # Note these suffixes:
 # _FL  = File List
+# _FP  = File Path
 # _FPL = File Path List 
 # _DL  = Directory List
+# _DP  = Directory path
+# _DPL = Directory path list
 
 # _PRIMARY = stuff not built
 # _IN  things input to some program
@@ -25,6 +28,7 @@ export EXECUTOR_IN_FL="\
   Arithmetic_Echo\
   Arithmetic_Echo__Test\
   Arithmetic_Syntax\
+  Arithmetic_Syntax__Test\
   20240412_Syntax\
   "
 
@@ -51,7 +55,12 @@ export JAVA_COMP_OUT_DIR="jvm"
 
 # JVM
 export JVM_IN_DIR="${JAVA_COMP_OUT_DIR}"
-export CLASSPATH="${CLASSPATH}:${JVM_IN_DIR}"
+
+# The generated build scripts might need arguments that are fully specified paths.
+export DEVELOPER_HOME_DP="/var/user_data/Thomas-developer/GQL_to_Cypher/developer"
+export JVM_IN_DP="$DEVELOPER_HOME_DP/jvm"
+export EXECUTOR_IN_DP="$DEVELOPER_HOME_DP/executor"
+export CLASSPATH="${CLASSPATH}:${JVM_IN_DP}"
 
 #--------------------------------------------------------------------------------
 # tools used
index 448f1d6..b4abdeb 100644 (file)
@@ -29,6 +29,13 @@ Arithmetic_Syntax: $(ANTLR_OUT_Arithmetic_FPL)
        fi
        make $(EXECUTOR_IN_DIR)/Arithmetic_Syntax
 
+Arithmetic_Syntax__Test: $(ANTLR_OUT_Arithmetic_FPL)
+       @if [ -z "$(ANTLR_OUT_Arithmetic_FPL)" ]; then \
+         echo "variable ANTLR_OUT_Arithmetic_FPL empty."; \
+         exit 1; \
+       fi
+       make $(EXECUTOR_IN_DIR)/Arithmetic_Syntax__Test
+
 Tree_20240412: $(ANTLR_OUT_GQL_20240412_FPL)
        @if [ -z "$(ANTLR_OUT_GQL_20240412_FPL)" ]; then \
          echo "variable ANTLR_OUT_GQL_20240412_FPL empty."; \
@@ -98,9 +105,9 @@ $(JAVA_COMP_OUT_DIR)/%.jar: $(JAVA_COMP_OUT_DIR)/%.class
        $(JAVA_ARCHIVE) cf $@ -C $(JAVA_COMP_OUT_DIR) $*.class
        @echo "Created $@"
 
-$(EXECUTOR_IN_DIR)/%: $(JAVA_COMP_OUT_DIR)/%.jar
+$(EXECUTOR_IN_DIR)/%: $(JVM_IN_DIR)/%.jar
        @echo "Creating script for $*..."
        @echo "#!/usr/bin/env bash" > $(EXECUTOR_IN_DIR)/$*
-       @echo "$(JAVA_INTERP) -cp ${CLASSPATH}:$(JAVA_COMP_OUT_DIR):$< $*" \$$\@ >> $(EXECUTOR_IN_DIR)/$*
+       @echo "$(JAVA_INTERP) -cp ${CLASSPATH}:${JVM_IN_DP}:$(JVM_IN_DP)/$*.jar $*" \$$\@ >> $(EXECUTOR_IN_DIR)/$*
        chmod +x $(EXECUTOR_IN_DIR)/$*
        @echo "Created script $(EXECUTOR_IN_DIR)/$*"
diff --git a/developer/experiment/script2.sh b/developer/experiment/script2.sh
new file mode 100644 (file)
index 0000000..68b62b2
--- /dev/null
@@ -0,0 +1,16 @@
+# Create the env_GP file in the executor directory
+cat << 'EOF' > ../executor/env_GP
+#!/bin/bash
+# Environment setup for GP
+export GP_PROMPT="GP> "
+export PS1="\[$(tput setaf 2)\]\u@\h:\w$GP_PROMPT\[$(tput sgr0)\] "
+EOF
+
+# Make sure the file is executable
+chmod +x ../executor/env_GP
+
+# Source the env_GP file to set up the environment
+source ../executor/env_GP
+
+# Now let's see the current directory contents
+ls -l
index de89933..0cd7847 100644 (file)
@@ -6,7 +6,7 @@ import java.util.Map;
 
 public class Arithmetic_Echo__Test {
 
-  public static boolean PrintVisitor_0() {
+  public static boolean Arithmetic_Echo_0() {
     // Simple smoke test
     try {
       String input = "3 + 5";
@@ -18,7 +18,7 @@ public class Arithmetic_Echo__Test {
     }
   }
 
-  public static boolean PrintVisitor_1() {
+  public static boolean Arithmetic_Echo_1() {
     // Test with multiplication
     try {
       String input = "2 * 3";
@@ -30,7 +30,7 @@ public class Arithmetic_Echo__Test {
     }
   }
 
-  public static boolean PrintVisitor_2() {
+  public static boolean Arithmetic_Echo_2() {
     // Test with parentheses
     try {
       String input = "2 * (3 + 4)";
@@ -42,7 +42,7 @@ public class Arithmetic_Echo__Test {
     }
   }
 
-  public static boolean PrintVisitor_3() {
+  public static boolean Arithmetic_Echo_3() {
     // Test with division
     try {
       String input = "10 / 2";
@@ -54,14 +54,14 @@ public class Arithmetic_Echo__Test {
     }
   }
 
-  public static boolean PrintVisitor_4() {
+  public static boolean Arithmetic_Echo_4() {
     // Test with complex expression
     try {
       String input = "3 + 5 * (10 - 4)";
       String expectedOutput = "(3 + (5 * (10 - 4)))";
       String actualOutput = runSyntax(input);
       // Uncomment the print statement for debugging
-      // System.out.println("PrintVisitor_4 - Expected: " + expectedOutput + ", Actual: " + actualOutput);
+      // System.out.println("Arithmetic_Echo_4 - Expected: " + expectedOutput + ", Actual: " + actualOutput);
       return expectedOutput.equals(actualOutput);
     } catch (Exception e) {
       return false;
@@ -81,11 +81,11 @@ public class Arithmetic_Echo__Test {
 
   public static void main(String[] args) {
     Map<String, Boolean> tests = new HashMap<>();
-    tests.put("PrintVisitor_0", PrintVisitor_0());
-    tests.put("PrintVisitor_1", PrintVisitor_1());
-    tests.put("PrintVisitor_2", PrintVisitor_2());
-    tests.put("PrintVisitor_3", PrintVisitor_3());
-    tests.put("PrintVisitor_4", PrintVisitor_4());
+    tests.put("Arithmetic_Echo_0", Arithmetic_Echo_0());
+    tests.put("Arithmetic_Echo_1", Arithmetic_Echo_1());
+    tests.put("Arithmetic_Echo_2", Arithmetic_Echo_2());
+    tests.put("Arithmetic_Echo_3", Arithmetic_Echo_3());
+    tests.put("Arithmetic_Echo_4", Arithmetic_Echo_4());
 
     TestBench.runTests(tests);
   }
index e433223..088d7ec 100644 (file)
@@ -4,7 +4,7 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 
-public class Arithmetic_Syntax{
+public class Arithmetic_Syntax {
 
   public static void main(String[] args) throws IOException {
     if (args.length != 1) {
@@ -22,9 +22,9 @@ public class Arithmetic_Syntax{
       ArithmeticParser parser = new ArithmeticParser(tokens);
 
       // Directly calling the start rule method
-      ParseSyntax tree = parser.program(); // Assuming 'program' is the start rule
+      ParseTree tree = parser.program(); // Assuming 'program' is the start rule
 
-      PrintVisitor visitor = new PrintVisitor(parser.getRuleNames());
+      Arithmetic_Syntax_PrintVisitor visitor = new Arithmetic_Syntax_PrintVisitor(parser.getRuleNames());
       String syntaxSyntax = visitor.visit(tree);
       System.out.println(syntaxSyntax);
     } catch (Exception e) {
index b70c0f0..d2a74a0 100644 (file)
@@ -1,9 +1,9 @@
-import org.antlr.v4.runtime.tree.AbstractParseSyntaxVisitor;
+import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
 
 public class Arithmetic_Syntax_PrintVisitor extends ArithmeticBaseVisitor<String> {
   private final String[] ruleNames;
 
-  public PrintVisitor(String[] ruleNames) {
+  public Arithmetic_Syntax_PrintVisitor(String[] ruleNames) {
     this.ruleNames = ruleNames;
   }
 
diff --git a/developer/javac/Arithmetic_Syntax__Test.java b/developer/javac/Arithmetic_Syntax__Test.java
new file mode 100644 (file)
index 0000000..95d8460
--- /dev/null
@@ -0,0 +1,77 @@
+import org.antlr.v4.runtime.*;
+import org.antlr.v4.runtime.tree.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class Arithmetic_Syntax__Test {
+
+  public static boolean Arithmetic_Syntax_0() {
+    return runTest(
+      "Arithmetic_Syntax__Test_0.txt"
+     ,"program(expression(INT(3) operator(+) INT(5)))"
+     );
+  }
+
+  public static boolean Arithmetic_Syntax_1() {
+    return runTest(
+      "Arithmetic_Syntax__Test_1.txt"
+      ,"program(expression(INT(3) operator(+) INT(5)))"
+   );
+  }
+
+  public static boolean Arithmetic_Syntax_2() {
+    return runTest(
+      "Arithmetic_Syntax__Test_2.txt" 
+      ,"program(expression(INT(2) operator(*) expression(INT(3) operator(+) INT(4))))"
+      );
+  }
+
+  public static boolean Arithmetic_Syntax_3() {
+    return runTest(
+      "Arithmetic_Syntax__Test_3.txt" 
+      ,"program(expression(INT(10) operator(/) INT(2)))"
+      );
+  }
+
+  public static boolean Arithmetic_Syntax_4() {
+    return runTest(
+      "Arithmetic_Syntax__Test_4.txt" 
+      ,"program(expression(INT(3) operator(+) expression(INT(5) operator(*) expression(INT(10) operator(-) INT(4)))))"
+      );
+  }
+
+  private static boolean runTest(String filename ,String expectedOutput) {
+    try {
+      String input = Files.readString(Paths.get(filename));
+      String actualOutput = runSyntax(input);
+      return expectedOutput.equals(actualOutput);
+    } catch (Exception e) {
+      e.printStackTrace();
+      return false;
+    }
+  }
+
+  private static String runSyntax(String input) throws Exception {
+    Lexer lexer = new ArithmeticLexer(CharStreams.fromString(input));
+    CommonTokenStream tokens = new CommonTokenStream(lexer);
+    ArithmeticParser parser = new ArithmeticParser(tokens);
+    ParseTree tree = parser.program(); // Directly calling the start rule method
+
+    Arithmetic_Syntax_PrintVisitor visitor = new Arithmetic_Syntax_PrintVisitor(parser.getRuleNames());
+    return visitor.visit(tree);
+  }
+
+  public static void main(String[] args) {
+    // Use LinkedHashMap to maintain order of test results
+    Map<String ,Boolean> tests = new LinkedHashMap<>();
+    tests.put("Arithmetic_Syntax_0" ,Arithmetic_Syntax_0());
+    tests.put("Arithmetic_Syntax_1" ,Arithmetic_Syntax_1());
+    tests.put("Arithmetic_Syntax_2" ,Arithmetic_Syntax_2());
+    tests.put("Arithmetic_Syntax_3" ,Arithmetic_Syntax_3());
+    tests.put("Arithmetic_Syntax_4" ,Arithmetic_Syntax_4());
+
+    TestBench.runTests(tests);
+  }
+}
diff --git a/developer/test/Arithmetic_Syntax__Test_0.txt b/developer/test/Arithmetic_Syntax__Test_0.txt
new file mode 100644 (file)
index 0000000..fe7e39e
--- /dev/null
@@ -0,0 +1 @@
+3 + 5
diff --git a/developer/test/Arithmetic_Syntax__Test_1.txt b/developer/test/Arithmetic_Syntax__Test_1.txt
new file mode 100644 (file)
index 0000000..fe7e39e
--- /dev/null
@@ -0,0 +1 @@
+3 + 5
diff --git a/developer/test/Arithmetic_Syntax__Test_2.txt b/developer/test/Arithmetic_Syntax__Test_2.txt
new file mode 100644 (file)
index 0000000..1603bfc
--- /dev/null
@@ -0,0 +1,2 @@
+2 * (3 + 4)
+
diff --git a/developer/test/Arithmetic_Syntax__Test_3.txt b/developer/test/Arithmetic_Syntax__Test_3.txt
new file mode 100644 (file)
index 0000000..d11b7e2
--- /dev/null
@@ -0,0 +1 @@
+10 / 2
diff --git a/developer/test/Arithmetic_Syntax__Test_4.txt b/developer/test/Arithmetic_Syntax__Test_4.txt
new file mode 100644 (file)
index 0000000..df1f368
--- /dev/null
@@ -0,0 +1,2 @@
+3 + 5 * (10 - 4)
+
diff --git a/developer/test/combined_output.txt b/developer/test/combined_output.txt
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/executor/env_GP b/executor/env_GP
new file mode 100755 (executable)
index 0000000..354c3ed
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+# Environment setup for GP
+export GP_PROMPT="GP> "
+export PS1="\[$(tput setaf 2)\]\u@\h:\w$GP_PROMPT\[$(tput sgr0)\] "
+export PROJECT_HOME="/var/user_data/Thomas-developer/GQL_to_Cypher/developer"
+cd $PROJECT_HOME/experiment