From: Thomas Walker Lynch Date: Sat, 3 Aug 2024 07:49:47 +0000 (+0000) Subject: a utility program and a new makefile that supports different grammars being used... X-Git-Url: https://git.reasoningtechnology.com/usr/lib/python2.7/encodings/cp855.py?a=commitdiff_plain;h=e129d68ef54d90a97b56435e45ba04420e2a42ed;p=GQL-to-Cypher a utility program and a new makefile that supports different grammars being used side by side --- diff --git a/developer/deprecated/makefile_0 b/developer/deprecated/makefile_0 new file mode 100644 index 0000000..5cea41c --- /dev/null +++ b/developer/deprecated/makefile_0 @@ -0,0 +1,237 @@ +# GQL_to_Cypher makefile + +#================================================================================ +# Setup the environment +# +# Use `make variable` to print the value assigned to the variables in this section + +#---------------------------------------- +# some notes about setting variables. Save yourself some grief by reading this. +# + +# An example of setting a make variable. Embedded and trailing spaces are +# included in the value, there are 4 of each present in the value for +# ISLAND. Leading spaces are not included. If there is a comment starting with +# a hash, the trailing spaces leading up to it the hash will be included in the +# value. A `:=` will evaluate immediately. A `=` will evaluate at point of variable +# expansion. +ISLAND := land island + +# Note these abbreviations: +# FL = File List, out file lists are those we want make to create +# DL = Directory List + +#---------------------------------------- +# programs used by this makefile +# +JAVA_COMP := $(JAVA_HOME)/bin/javac +JAVA_INTERP := $(JAVA_HOME)/bin/java +JAVA_ARCHIVE := $(JAVA_HOME)/bin/jar + +#---------------------------------------- +# programs being built by this makefile: +# +PRINT_RULE_NAME_LIS := PrintRuleNameList +SYNTAX_TREE_TEST := SyntaxTree_Test +SYNTAX_TREE_20240412 := SyntaxTree_20240412 +# put your version here + +PROGRAM_LIST := $(PRINT_RULE_NAME_LIST) $(SYNTAX_TREE_TEST) $(SYNTAX_TREE_20240412) + +#---------------------------------------- +# ANTLR environment + +# ANTLR directories +ANTLR_IN_DIR := ANTLR +ANTLR_OUT_DIR := javac/ANTLR +ANTLR_OUT_DIR_PARENT := javac + +# ANTLR input files +ANTLR_IN_FL := $(wildcard $(ANTLR_IN_DIR)/*.g4) +ifneq ($(strip $(ANTLR_IN_FL)),) + ($info empty ANTLR_IN_FL) +endif + +# ANTLR will produce these output files. + +# This function accepts a grammar name, or a grammar name with an extension; +# and sets a variable of the form ANTLR_OUT__FL to a list of +# files that ANTLR would produce for . +define set_ANTLR_out_fl_var + ANTLR_OUT_$(basename $(notdir $1))_FL := \ + $(ANTLR_OUT_DIR)/$(basename $(notdir $1))Lexer.java \ + $(ANTLR_OUT_DIR)/$(basename $(notdir $1))Parser.java \ + $(ANTLR_OUT_DIR)/$(basename $(notdir $1))BaseVisitor.java \ + $(ANTLR_OUT_DIR)/$(basename $(notdir $1))Visitor.java +endef + +# Generate an ANTLR_OUT__FL and set it, for each grammar +$(foreach file,$(ANTLR_IN_FL),$(eval $(call set_ANTLR_out_fl_var,$(file)))) + +# Combine all individual file lists into ANTLR_OUT_FL +ANTLR_OUT_FL := $(foreach file,$(ANTLR_IN_FL),$(value ANTLR_OUT_$(basename $(notdir $(file)))_FL)) + + +#---------------------------------------- +# Java environment + +# JAVA directories +JAVA_COMP_IN_PRIMARY_DIR := javac +JAVA_COMP_IN_ANTLR_DIR := $(ANTLR_OUT_DIR) +JAVA_COMP_IN_DL := $(JAVA_COMP_IN_PRIMARY_DIR):$(JAVA_COMP_IN_ANTLR_DIR) +JAVA_COMP_OUT_DIR := jvm + +# JAVA input files +JAVA_COMP_IN_PRIMARY_FL := $(wildcard $(JAVA_COMP_IN_PRIMARY_DIR)/*.java) +JAVA_COMP_IN_ANTLR_FL := $(ANTLR_OUT_FL) +JAVA_COMP_IN_FL := $(JAVA_COMP_IN_PRIMARY_FL) $(JAVA_COMP_IN_ANTLR_FL) + +# JAVA will produce these output files +JAVA_COMP_OUT_PRIMARY_FL := $(patsubst $(JAVA_COMP_IN_PRIMARY_DIR)/%.java,$(JVM_IN_DIR)/%.class,$(JAVA_COMP_IN_PRIMARY_FL)) +JAVA_COMP_OUT_ANTLR_FL := $(patsubst $(JAVA_COMP_IN_ANTLR_DIR)/%.java,$(JVM_IN_DIR)/%.class,$(JAVA_COMP_IN_ANTLR_FL)) +JAVA_COMP_OUT_FL := $(JAVA_COMP_OUT_PRIMARY_FL) $(JAVA_COMP_OUT_ANTLR_FL) + +#---------------------------------------- +# JVM environment + +JVM_IN_DIR := $(JAVA_COMP_OUT_DIR) +CLASSPATH := $(CLASSPATH):$(JVM_IN_DIR) +export CLASSPATH + + +#================================================================================ +# Make targets +# + +# The general make everything targets: +all: setup $(PROGRAM_LIST) +grammar: setup $(ANTLR_OUT_FL) + +# specific programs or program versions: +PrintRuleNameList: PrintRuleNameList.jar +SyntaxTree_Test: $(ANTLR_OUT_SyntaxTree_Test_FL) SyntaxTree_Test.jar +SyntaxTree_20240412: $(ANTLR_OUT_SyntaxTree_20240412_FL) SyntaxTree_20240412.jar + +# Specific grammar targets. Run them like this: +# > make +# e.g. > make GQL_test +# Specific grammar targets. Run them like this: +# > make +# e.g. > make GQL_test + +# Specific grammar targets. Run them like this: +# > make +# e.g. > make GQL_test +define generate_grammar_target +grammar_name := $(basename $(notdir $1)) +$(info Generating target: $(grammar_name) with dependencies: $(value ANTLR_OUT_$(grammar_name)_FL)) +$(basename $(notdir $1)): $(value ANTLR_OUT_$(basename $(notdir $1))_FL) +endef +$(foreach file,$(ANTLR_IN_FL),$(eval $(call generate_grammar_target,$(file)))) + + +# Compile all the .java files. +java: setup $(JAVA_COMP_OUT_FL) + +# print out all variables within quotes so that spaces can be detected +.PHONY: variable +variable: + $(info ISLAND is '$(ISLAND)') + + $(info PRINT_RULE_NAME_LIST is '$(PRINT_RULE_NAME_LIST)') + $(info SYNTAX_TREE_TEST is '$(SYNTAX_TREE_TEST)') + $(info SYNTAX_TREE_20240412 is '$(SYNTAX_TREE_20240412)') + $(info PROGRAM_LIST is '$(PROGRAM_LIST)') + + $(info JAVA_COMP is '$(JAVA_COMP)') + $(info JAVA_INTERP is '$(JAVA_INTERP)') + $(info JAVA_ARCHIVE is '$(JAVA_ARCHIVE)') + + $(info ANTLR_IN_DIR is '$(ANTLR_IN_DIR)') + $(info ANTLR_OUT_DIR is '$(ANTLR_OUT_DIR)') + $(info ANTLR_OUT_DIR_PARENT is '$(ANTLR_OUT_DIR_PARENT)') + $(info ANTLR_IN_FL is '$(ANTLR_IN_FL)') + $(foreach file,$(ANTLR_IN_FL),$(info ANTLR_OUT_$(basename $(notdir $(file)))_FL is '$(value ANTLR_OUT_$(basename $(notdir $(file)))_FL)')) + $(info ANTLR_OUT_FL is '$(ANTLR_OUT_FL)') + + $(info JAVA_COMP_IN_PRIMARY_DIR is '$(JAVA_COMP_IN_PRIMARY_DIR)') + $(info JAVA_COMP_IN_ANTLR_DIR is '$(JAVA_COMP_IN_ANTLR_DIR)') + $(info JAVA_COMP_IN_DL is '$(JAVA_COMP_IN_DL)') + $(info JAVA_COMP_OUT_DIR is '$(JAVA_COMP_OUT_DIR)') + + $(info JAVA_COMP_IN_PRIMARY_FL is '$(JAVA_COMP_IN_PRIMARY_FL)') + $(info JAVA_COMP_IN_ANTLR_FL is '$(JAVA_COMP_IN_ANTLR_FL)') + $(info JAVA_COMP_IN_FL is '$(JAVA_COMP_IN_FL)') + + $(info JAVA_COMP_OUT_PRIMARY_FL is '$(JAVA_COMP_OUT_PRIMARY_FL)') + $(info JAVA_COMP_OUT_ANTLR_FL is '$(JAVA_COMP_OUT_ANTLR_FL)') + $(info JAVA_COMP_OUT_FL is '$(JAVA_COMP_OUT_FL)') + + $(info JVM_IN_DIR is '$(JVM_IN_DIR)') + $(info CLASSPATH is '$(CLASSPATH)') + @: + +.PHONY: version +version: + $(info ANTLR_JAR is '$(notdir $(ANTLR_JAR))') + @ $(JAVA_COMP) --version + @ $(JAVA_ARCHIVE) --version + @ make -v | head -n 1 + @ echo "makefile 0.1" + +.PHONY: setup +setup: + # ANTLR automatically creates $(ANTLR_OUT_DIR) + mkdir -p $(ANTLR_IN_DIR) $(JAVA_COMP_IN_PRIMARY_DIR) $(JVM_IN_DIR) + mkdir -p test deprecated experiment documentation temporary + +.PHONY: clean +clean: + @if [ -n "$(JVM_IN_DIR)" ]; then \ + echo "Cleaning $(JVM_IN_DIR)"; \ + rm -rf $(JVM_IN_DIR)/*; \ + else \ + echo "Warning: JVM_IN_DIR is not set"; \ + fi + @if [ -n "$(ANTLR_OUT_DIR)" ]; then \ + echo "Cleaning $(ANTLR_OUT_DIR)"; \ + rm -rf $(ANTLR_OUT_DIR); \ + else \ + echo "Warning: ANTLR_OUT_DIR is not set"; \ + fi + @if [ -d "temporary" ]; then \ + echo "Cleaning temporary directory"; \ + rm -rf temporary/*; \ + else \ + echo "Warning: temporary directory does not exist"; \ + fi + +#================================================================================ +# recipes + +# ANTLR a run of any of these will make all the files +$(ANTLR_OUT_DIR)/%Lexer.java: $(ANTLR_IN_DIR)/%.g4 + @echo "making grammar from:" $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< + +$(ANTLR_OUT_DIR)/%Parser.java: $(ANTLR_IN_DIR)/%.g4 + @echo "making grammar from:" $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< + +$(ANTLR_OUT_DIR)/%BaseVisitor.java: $(ANTLR_IN_DIR)/%.g4 + @echo "making grammar from:" $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< + +$(ANTLR_OUT_DIR)/%Visitor.java: $(ANTLR_IN_DIR)/%.g4 + @echo "making grammar from:" $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< + +# Generic recipe for building .jar files and placing scripts in the executor directory +$(JAVA_COMP_OUT_DIR)/%.jar: $(JAVA_COMP_IN_PRIMARY_DIR)/%.java + @echo "Building $*..." + $(JAVA_COMP) -d $(JAVA_COMP_OUT_DIR) -sourcepath $(JAVA_COMP_IN_DL) $< + $(JAVA_ARCHIVE) cf $@ -C $(JVM_IN_DIR) $*.class + @echo "Creating script for $*..." + echo "#!/usr/bin/env bash\n$(JAVA_INTERP) -cp $@ $*" > executor/$*.sh + chmod +x executor/$*.sh + diff --git a/developer/documentation/GQL_20240412_rule_list.txt b/developer/documentation/GQL_20240412_rule_list.txt new file mode 100644 index 0000000..729a7e6 --- /dev/null +++ b/developer/documentation/GQL_20240412_rule_list.txt @@ -0,0 +1,215 @@ +Here's the list of rules found in the GQL_20240412.g4 file: + +transactionMode +transactionAccessMode +rollbackCommand +commitCommand +nestedProcedureSpecification +procedureSpecification +nestedDataModifyingProcedureSpecification +nestedQuerySpecification +procedureBody +bindingVariableDefinitionBlock +bindingVariableDefinition +statementBlock +statement +nextStatement +graphVariableDefinition +optTypedGraphInitializer +graphInitializer +bindingTableVariableDefinition +optTypedBindingTableInitializer +bindingTableInitializer +valueVariableDefinition +optTypedValueInitializer +valueInitializer +graphExpression +currentGraph +bindingTableExpression +nestedBindingTableQuerySpecification +objectExpressionPrimary +linearCatalogModifyingStatement +simpleCatalogModifyingStatement +primitiveCatalogModifyingStatement +createSchemaStatement +dropSchemaStatement +createGraphStatement +openGraphType +ofGraphType +graphTypeLikeGraph +graphSource +dropGraphStatement +createGraphTypeStatement +graphTypeSource +copyOfGraphType +dropGraphTypeStatement +callCatalogModifyingProcedureStatement +linearDataModifyingStatement +focusedLinearDataModifyingStatement +focusedLinearDataModifyingStatementBody +focusedNestedDataModifyingProcedureSpecification +ambientLinearDataModifyingStatement +ambientLinearDataModifyingStatementBody +simpleLinearDataAccessingStatement +simpleDataModifyingStatement +primitiveDataModifyingStatement +insertStatement +setStatement +setItemList +setItem +setPropertyItem +setAllPropertiesItem +setLabelItem +removeStatement +removeItemList +removeItem +removePropertyItem +removeLabelItem +deleteStatement +deleteItemList +deleteItem +callDataModifyingProcedureStatement +compositeQueryStatement +compositeQueryExpression +queryConjunction +setOperator +compositeQueryPrimary +linearQueryStatement +focusedLinearQueryStatement +focusedLinearQueryStatementBody +focusedNestedQuerySpecification +ambientLinearQueryStatement +ambientLinearQueryStatementBody +nestedLinearQuerySpecification +simpleQuerySpecification +simpleQueryPrimary +callDataAccessingProcedureStatement +ambientDataModifyingProcedureStatement +ambientQuerySpecification +ambientQueryPrimary +simpleQuerySpecificationBody +simpleQueryPrimaryExpression +simpleQueryBodyExpression +compoundQuerySpecification +ambientLinearQuerySpecification +simpleDataAccessingStatement +ambientDataModifyingStatement +ambientLinearDataModifyingSpecification +simpleDataAccessingSpecification +ambientDataModifyingStatementBody +simpleDataModifyingSpecification +ambientLinearDataModifyingStatementBody +simpleLinearDataModifyingSpecification +focusedLinearDataModifyingSpecification +focusedDataModifyingSpecification +focusedLinearDataModifyingStatementBodyExpression +focusedLinearQuerySpecification +simpleLinearQuerySpecification +focusedLinearQuerySpecificationBody +simpleLinearQuerySpecificationBody +focusedLinearQuerySpecificationBodyExpression +simpleLinearQuerySpecificationBodyExpression +compoundQueryBody +compoundQueryExpression +compoundQueryExpressionPart +queryPrimary +queryExpression +queryTerm +query +querySpecification +queryExpressionBody +simpleQueryExpression +simpleQuerySpecificationBodyExpression +simpleQuerySpecificationBodyExpressionPart +compoundQuerySpecificationBodyExpression +compoundQuerySpecificationBodyExpressionPart +simpleQuerySpecificationBodyPart +simpleQuerySpecificationBodyExpressionPart +simpleQuerySpecificationBodyExpression +queryPrimaryExpression +queryExpressionPart +queryExpressionBodyPart +queryExpressionPrimary +queryExpressionTerm +queryExpressionPrimaryExpression +queryExpressionPrimaryExpressionPart +queryExpressionPrimaryExpressionBody +queryExpressionPrimaryExpressionTerm +queryExpressionPrimaryExpressionBodyPart +queryExpressionPrimaryExpressionPrimary +queryExpressionPrimaryExpressionTermPart +queryExpressionPrimaryExpressionPrimaryPart +simpleQueryExpressionPrimary +simpleQueryExpressionPrimaryPart +simpleQueryExpressionPrimaryBody +simpleQueryExpressionPrimaryTerm +simpleQueryExpressionPrimaryBodyPart +simpleQueryExpressionPrimaryPrimary +simpleQueryExpressionPrimaryPrimaryPart +simpleQueryExpressionPrimaryTermPart +simpleQueryExpressionPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyTermPart +simpleQueryExpressionPrimaryBodyExpression +simpleQueryExpressionPrimaryBodyExpressionPart +simpleQueryExpressionPrimaryBodyExpressionBody +simpleQueryExpressionPrimaryBodyExpressionTerm +simpleQueryExpressionPrimaryBodyExpressionBodyPart +simpleQueryExpressionPrimaryBodyExpressionTermPart +simpleQueryExpressionPrimaryBodyExpressionPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimary +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBody +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPart +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPrimaryBodyPartTerm +simpleQueryExpressionPrimaryBodyExpressionPrimaryBodyPrimaryBodyPrimaryBodyPrimary ​​ + + + + + + + diff --git a/developer/javac/PrintRuleNameList.java b/developer/javac/PrintRuleNameList.java new file mode 100644 index 0000000..b5df9fc --- /dev/null +++ b/developer/javac/PrintRuleNameList.java @@ -0,0 +1,43 @@ +/* +Directly reads an ANTLR grammar file, a `.g4` file, and lists all the rules found in it. + +*/ +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class MakeRuleNameList { + + public static void main(String[] args) { + if (args.length != 1) { + System.out.println("Usage: java GrammarRuleExtractor "); + return; + } + + String filePath = args[0]; + Set ruleNames = new HashSet<>(); + + try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { + String line; + Pattern rulePattern = Pattern.compile("^([a-zA-Z_][a-zA-Z0-9_]*)\\s*:"); + + while ((line = br.readLine()) != null) { + Matcher matcher = rulePattern.matcher(line); + if (matcher.find()) { + ruleNames.add(matcher.group(1)); + } + } + + System.out.println("Extracted Rules:"); + for (String rule : ruleNames) { + System.out.println(rule); + } + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/developer/javac/PrintVisitor.java b/developer/javac/PrintVisitor.java index 91da9a8..3001677 100644 --- a/developer/javac/PrintVisitor.java +++ b/developer/javac/PrintVisitor.java @@ -29,11 +29,230 @@ public class PrintVisitor extends AbstractParseTreeVisitor implements GQ return sb.toString(); } + @Override + public String visitGeneralLogarithmFunction(GQL_20240412Parser.GeneralLogarithmFunctionContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitGeneralLogarithmBase(GQL_20240412Parser.GeneralLogarithmBaseContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitGeneralLogarithmArgument(GQL_20240412Parser.GeneralLogarithmArgumentContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitCommonLogarithm(GQL_20240412Parser.CommonLogarithmContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNaturalLogarithm(GQL_20240412Parser.NaturalLogarithmContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitExponentialFunction(GQL_20240412Parser.ExponentialFunctionContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitPowerFunction(GQL_20240412Parser.PowerFunctionContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNumericValueExpressionBase(GQL_20240412Parser.NumericValueExpressionBaseContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNumericValueExpressionExponent(GQL_20240412Parser.NumericValueExpressionExponentContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNumericValueExpressionFactor(GQL_20240412Parser.NumericValueExpressionFactorContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNumericValueExpressionSummand(GQL_20240412Parser.NumericValueExpressionSummandContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNumericValueExpression(GQL_20240412Parser.NumericValueExpressionContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitBooleanValueExpressionBase(GQL_20240412Parser.BooleanValueExpressionBaseContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitBooleanValueExpressionFactor(GQL_20240412Parser.BooleanValueExpressionFactorContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitBooleanValueExpressionSummand(GQL_20240412Parser.BooleanValueExpressionSummandContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitBooleanValueExpression(GQL_20240412Parser.BooleanValueExpressionContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitFieldPath(GQL_20240412Parser.FieldPathContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNodeLabel(GQL_20240412Parser.NodeLabelContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitEdgeLabel(GQL_20240412Parser.EdgeLabelContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitLabel(GQL_20240412Parser.LabelContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNodeType(GQL_20240412Parser.NodeTypeContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitEdgeType(GQL_20240412Parser.EdgeTypeContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitType(GQL_20240412Parser.TypeContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitFieldName(GQL_20240412Parser.FieldNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNodeName(GQL_20240412Parser.NodeNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitEdgeName(GQL_20240412Parser.EdgeNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitAliasName(GQL_20240412Parser.AliasNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitTypeName(GQL_20240412Parser.TypeNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitLabelName(GQL_20240412Parser.LabelNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNonTypeName(GQL_20240412Parser.NonTypeNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitTypeVariableName(GQL_20240412Parser.TypeVariableNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitFieldVariableName(GQL_20240412Parser.FieldVariableNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNodeVariableName(GQL_20240412Parser.NodeVariableNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitEdgeVariableName(GQL_20240412Parser.EdgeVariableNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitVariableName(GQL_20240412Parser.VariableNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitDatabaseName(GQL_20240412Parser.DatabaseNameContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitDateString(GQL_20240412Parser.DateStringContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitTimeString(GQL_20240412Parser.TimeStringContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitDatetimeString(GQL_20240412Parser.DatetimeStringContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitDurationLiteral(GQL_20240412Parser.DurationLiteralContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitDurationString(GQL_20240412Parser.DurationStringContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitNodeSynonym(GQL_20240412Parser.NodeSynonymContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitEdgesSynonym(GQL_20240412Parser.EdgesSynonymContext ctx) { + return visitChildren(ctx); + } + + @Override + public String visitEdgeSynonym(GQL_20240412Parser.EdgeSynonymContext ctx) { + return visitChildren(ctx); + } + @Override public String visitNonReservedWords(GQL_20240412Parser.NonReservedWordsContext ctx) { - // Your implementation here return visitChildren(ctx); } - // Implement other methods as needed + } diff --git a/developer/javac/SyntaxTree20240412.java b/developer/javac/SyntaxTree20240412.java deleted file mode 100644 index a8db135..0000000 --- a/developer/javac/SyntaxTree20240412.java +++ /dev/null @@ -1,36 +0,0 @@ -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.tree.*; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -public class SyntaxTree20240412 { - - // Versioned Lexer and Parser - static final Class GQL_Lexer = GQL_20240412Lexer.class; - static final Class GQL_Parser = GQL_20240412Parser.class; - - public static void main(String[] args) throws IOException { - if (args.length != 1) { - System.err.println("Usage: java SyntaxTree20240412 "); - System.exit(1); - } - - String inputFile = args[0]; - String input = new String(Files.readAllBytes(Paths.get(inputFile))); - - try { - Lexer lexer = (Lexer) GQL_Lexer.getConstructor(CharStream.class).newInstance(CharStreams.fromString(input)); - CommonTokenStream tokens = new CommonTokenStream(lexer); - Parser parser = (Parser) GQL_Parser.getConstructor(TokenStream.class).newInstance(tokens); - Method startRule = parser.getClass().getMethod("program"); // Assuming 'program' is the start rule - ParseTree tree = (ParseTree) startRule.invoke(parser); - - PrintVisitor visitor = new PrintVisitor(parser.getRuleNames()); - String syntaxTree = visitor.visit(tree); - System.out.println(syntaxTree); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/developer/javac/SyntaxTree_20240412.java b/developer/javac/SyntaxTree_20240412.java new file mode 100644 index 0000000..a8db135 --- /dev/null +++ b/developer/javac/SyntaxTree_20240412.java @@ -0,0 +1,36 @@ +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.tree.*; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class SyntaxTree20240412 { + + // Versioned Lexer and Parser + static final Class GQL_Lexer = GQL_20240412Lexer.class; + static final Class GQL_Parser = GQL_20240412Parser.class; + + public static void main(String[] args) throws IOException { + if (args.length != 1) { + System.err.println("Usage: java SyntaxTree20240412 "); + System.exit(1); + } + + String inputFile = args[0]; + String input = new String(Files.readAllBytes(Paths.get(inputFile))); + + try { + Lexer lexer = (Lexer) GQL_Lexer.getConstructor(CharStream.class).newInstance(CharStreams.fromString(input)); + CommonTokenStream tokens = new CommonTokenStream(lexer); + Parser parser = (Parser) GQL_Parser.getConstructor(TokenStream.class).newInstance(tokens); + Method startRule = parser.getClass().getMethod("program"); // Assuming 'program' is the start rule + ParseTree tree = (ParseTree) startRule.invoke(parser); + + PrintVisitor visitor = new PrintVisitor(parser.getRuleNames()); + String syntaxTree = visitor.visit(tree); + System.out.println(syntaxTree); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/developer/makefile b/developer/makefile index abac16c..e9e8982 100644 --- a/developer/makefile +++ b/developer/makefile @@ -1,110 +1,166 @@ # GQL_to_Cypher makefile -#-------------------------------------------------------------------------------- +#================================================================================ # Setup the environment # -# Use `make variable` to print the value assigned to the variables in this section +# Use `make variable` to print the value assigned to each variable in this section -# An example. Embedded and trailing spaces are included in the value, there are -# 4 of each present in the value for ISLAND. Leading spaces are not included. -# If there is a comment starting with a hash, the trailing spaces leading up to -# it are included. -ISLAND := land island +#---------------------------------------- +# some notes about setting variables. Save yourself some grief by reading this. +# + +# Note these suffixes: +# _FL = File List +# _FPL = File Path List +# _DL = Directory List + +# _PRIMARY means these are primary inputs, this makefile does not build them +# _IN program inputs +# _OUT expected program outputs -# Note these abreviations: -# FL = File List, out file lists are those we want make to create -# DL = Directory List +# The following is an example of setting a variable. Use `make variable` +# to prints its value, and note the embedded and trailing spaces. +ISLAND := land island +#---------------------------------------- # programs used by this makefile +# JAVA_COMP := $(JAVA_HOME)/bin/javac JAVA_INTERP := $(JAVA_HOME)/bin/java JAVA_ARCHIVE := $(JAVA_HOME)/bin/jar +#---------------------------------------- +# programs being built by this makefile: +# +PRINT_RULE_NAME_LIST := PrintRuleNameList +SYNTAX_TREE_TEST := SyntaxTree_Test +SYNTAX_TREE_20240412 := SyntaxTree_20240412 + +PROGRAM_LIST := $(PRINT_RULE_NAME_LIST) $(SYNTAX_TREE_TEST) $(SYNTAX_TREE_20240412) + +#---------------------------------------- +# ANTLR environment +# Add a `.g4` file into the ANTLR_IN_DIR + # ANTLR directories -ANTLR_IN_DIR := ANTLR -ANTLR_OUT_DIR := javac/ANTLR +ANTLR_PRIMARY_DIR := ANTLR +ANTLR_IN_DIR := $(ANTLR_PRIMARY_DIR) +ANTLR_OUT_DIR := javac/ANTLR ANTLR_OUT_DIR_PARENT := javac -# ANTLR files -ANTLR_IN_FL := $(wildcard $(ANTLR_IN_DIR)/*.g4) -ANTLR_OUT_FL := $(patsubst $(ANTLR_IN_DIR)/%.g4,$(ANTLR_OUT_DIR)/%.java,$(ANTLR_IN_FL)) -# JAVA directories -JAVAC_IN_PRIMARY_DIR := javac -JAVAC_IN_ANTLR_DIR := $(ANTLR_OUT_DIR) -JAVAC_IN_DL := $(JAVAC_IN_PRIMARY_DIR) $(JAVAC_IN_ANTLR_DIR) -JVM_IN_DIR := jvm +# ANTLR input files +ANTLR_IN_FPL := $(wildcard $(ANTLR_IN_DIR)/*.g4) +ANTLR_GRAMMAR_LIST := $(basename $(notdir $(ANTLR_IN_FPL))) +ifeq ($(strip $(ANTLR_IN_FPL)),) + $(info No ANTLR input grammar files found) +endif + +# ANTLR will produce these output files. -# JAVA files -JAVAC_IN_PRIMARY_FL := $(wildcard $(JAVAC_IN_PRIMARY_DIR)/*.java) -JAVAC_IN_ANTLR_FL := $(ANTLR_OUT_FL) -JAVAC_IN_FL := $(JAVAC_IN_PRIMARY_FL) $(JAVAC_IN_ANTLR_FL) +# This function accepts a grammar name, or a grammar name with an extension; +# and sets a variable of the form ANTLR_OUT__FPL to a list of +# files that ANTLR would produce for . +define set_ANTLR_out_fpl_var + ANTLR_OUT_$(basename $1)_FPL := \ + $(ANTLR_OUT_DIR)/$(basename $1)Lexer.java \ + $(ANTLR_OUT_DIR)/$(basename $1)Parser.java \ + $(ANTLR_OUT_DIR)/$(basename $1)BaseVisitor.java \ + $(ANTLR_OUT_DIR)/$(basename $1)Visitor.java +endef -JAVAC_OUT_PRIMARY_FL := $(patsubst $(JAVAC_IN_PRIMARY_DIR)/%.java,$(JVM_IN_DIR)/%.class,$(JAVAC_IN_PRIMARY_FL)) -JAVAC_OUT_ANTLR_FL := $(patsubst $(ANTLR_OUT_DIR)/%.java,$(JVM_IN_DIR)/%.class,$(JAVAC_IN_ANTLR_FL)) -JAVAC_OUT_FL := $(JAVAC_OUT_PRIMARY_FL) $(JAVAC_OUT_ANTLR_FL) +# Generate ANTLR_OUT__FPL for each grammar +$(foreach file,$(ANTLR_GRAMMAR_LIST),$(eval $(call set_ANTLR_out_fpl_var,$(file)))) -# programs we are creating -SYNTAX_TREE_20240412 := SyntaxTree20240412 -OUT_FL := $(JVM_IN_DIR)/$(SYNTAX_TREE_20240412).jar +# Combine all individual file lists into ANTLR_OUT_FPL +ANTLR_OUT_FPL := $(foreach file,$(ANTLR_GRAMMAR_LIST),$(value ANTLR_OUT_$(file)_FPL)) + +#---------------------------------------- +# Java environment + +# JAVA directories +JAVA_COMP_IN_PRIMARY_DIR := javac +JAVA_COMP_IN_ANTLR_DIR := $(ANTLR_OUT_DIR) +JAVA_COMP_IN_DL := $(JAVA_COMP_IN_PRIMARY_DIR):$(JAVA_COMP_IN_ANTLR_DIR) +JAVA_COMP_OUT_DIR := jvm +# JAVA input files +JAVA_COMP_IN_PRIMARY_FPL := $(wildcard $(JAVA_COMP_IN_PRIMARY_DIR)/*.java) +JAVA_COMP_IN_ANTLR_FPL := $(ANTLR_OUT_FPL) +JAVA_COMP_IN_FPL := $(JAVA_COMP_IN_PRIMARY_FPL) $(JAVA_COMP_IN_ANTLR_FPL) -# java command CLASS directory search and source directory search +# JAVA will produce these output files +JAVA_COMP_OUT_PRIMARY_FPL := $(patsubst $(JAVA_COMP_IN_PRIMARY_DIR)/%.java,$(JAVA_COMP_OUT_DIR)/%.class,$(JAVA_COMP_IN_PRIMARY_FPL)) +JAVA_COMP_OUT_ANTLR_FPL := $(patsubst $(JAVA_COMP_IN_ANTLR_DIR)/%.java,$(JAVA_COMP_OUT_DIR)/%.class,$(JAVA_COMP_IN_ANTLR_FPL)) +JAVA_COMP_OUT_FPL := $(JAVA_COMP_OUT_PRIMARY_FPL) $(JAVA_COMP_OUT_ANTLR_FPL) + +#---------------------------------------- +# JVM environment + +JVM_IN_DIR := $(JAVA_COMP_OUT_DIR) CLASSPATH := $(CLASSPATH):$(JVM_IN_DIR) export CLASSPATH -JAVA_IN_DL := $(JAVAC_IN_PRIMARY_DIR):$(ANTLR_OUT_DIR) - -#-------------------------------------------------------------------------------- -# Top level make targets +#================================================================================ +# Make targets # -# compile all the programs -# this first target is the default for make -.PHONY: program -program: setup $(OUT_FL) +# The general make everything targets: +all: setup $(PROGRAM_LIST) +grammar: setup $(ANTLR_OUT_FPL) + +# specific programs or program versions: +PrintRuleNameList: $(JAVA_COMP_OUT_DIR)/PrintRuleNameList.jar +SyntaxTree_Test: $(ANTLR_OUT_SyntaxTree_Test_FPL) $(JAVA_COMP_OUT_DIR)/SyntaxTree_Test.jar +SyntaxTree_20240412: $(ANTLR_OUT_SyntaxTree_20240412_FPL) $(JAVA_COMP_OUT_DIR)/SyntaxTree_20240412.jar -# compile all the grammar files whether they are needed or not -.PHONY: grammar -grammar: setup $(ANTLR_OUT_FL) +# Specific grammar targets. Run them like this: +# > make +# e.g. > make GQL_test +$(foreach grammar,$(ANTLR_GRAMMAR_LIST),$(eval $(grammar): $(value ANTLR_OUT_$(grammar)_FPL))) -# compile all the .java files, whether they are needed or not -.PHONY: java -program: setup $(JAVAC_OUT_FL) +# Compile all the .java files. +java: setup $(JAVA_COMP_OUT_FPL) -# print out all variables with quotes so that spaces can be detected +# print out all variables within quotes so that spaces can be detected .PHONY: variable variable: $(info ISLAND is '$(ISLAND)') - $(info JAVA_HOME is '$(JAVA_HOME)') - $(info ANTLR_JAR is '$(ANTLR_JAR)') + $(info PRINT_RULE_NAME_LIST is '$(PRINT_RULE_NAME_LIST)') + $(info SYNTAX_TREE_TEST is '$(SYNTAX_TREE_TEST)') + $(info SYNTAX_TREE_20240412 is '$(SYNTAX_TREE_20240412)') + $(info PROGRAM_LIST is '$(PROGRAM_LIST)') $(info JAVA_COMP is '$(JAVA_COMP)') $(info JAVA_INTERP is '$(JAVA_INTERP)') $(info JAVA_ARCHIVE is '$(JAVA_ARCHIVE)') + $(info ANTLR_PRIMARY_DIR is '$(ANTLR_PRIMARY_DIR)') $(info ANTLR_IN_DIR is '$(ANTLR_IN_DIR)') $(info ANTLR_OUT_DIR is '$(ANTLR_OUT_DIR)') $(info ANTLR_OUT_DIR_PARENT is '$(ANTLR_OUT_DIR_PARENT)') - $(info ANTLR_IN_FL is '$(ANTLR_IN_FL)') - $(info ANTLR_OUT_FL is '$(ANTLR_OUT_FL)') + $(info ANTLR_IN_FPL is '$(ANTLR_IN_FPL)') + $(info ANTLR_GRAMMAR_LIST is '$(ANTLR_GRAMMAR_LIST)') + $(foreach file,$(ANTLR_GRAMMAR_LIST),$(info ANTLR_OUT_$(file)_FPL is '$(value ANTLR_OUT_$(file)_FPL)')) + $(info ANTLR_OUT_FPL is '$(ANTLR_OUT_FPL)') - $(info JAVAC_IN_PRIMARY_DIR is '$(JAVAC_IN_PRIMARY_DIR)') - $(info JAVAC_IN_ANTLR_DIR is '$(JAVAC_IN_ANTLR_DIR)') - $(info JVM_IN_DIR is '$(JVM_IN_DIR)') + $(info JAVA_COMP_IN_PRIMARY_DIR is '$(JAVA_COMP_IN_PRIMARY_DIR)') + $(info JAVA_COMP_IN_ANTLR_DIR is '$(JAVA_COMP_IN_ANTLR_DIR)') + $(info JAVA_COMP_IN_DL is '$(JAVA_COMP_IN_DL)') + $(info JAVA_COMP_OUT_DIR is '$(JAVA_COMP_OUT_DIR)') - $(info JAVAC_IN_PRIMARY_FL is '$(JAVAC_IN_PRIMARY_FL)') - $(info JAVAC_IN_ANTLR_FL is '$(JAVAC_IN_ANTLR_FL)') - $(info JAVAC_IN_FL is '$(JAVAC_IN_FL)') + $(info JAVA_COMP_IN_PRIMARY_FPL is '$(JAVA_COMP_IN_PRIMARY_FPL)') + $(info JAVA_COMP_IN_ANTLR_FPL is '$(JAVA_COMP_IN_ANTLR_FPL)') + $(info JAVA_COMP_IN_FPL is '$(JAVA_COMP_IN_FPL)') - $(info JAVAC_OUT_PRIMARY_FL is '$(JAVAC_OUT_PRIMARY_FL)') - $(info JAVAC_OUT_ANTLR_FL is '$(JAVAC_OUT_ANTLR_FL)') - $(info JAVAC_OUT_FL is '$(JAVAC_OUT_FL)') + $(info JAVA_COMP_OUT_PRIMARY_FPL is '$(JAVA_COMP_OUT_PRIMARY_FPL)') + $(info JAVA_COMP_OUT_ANTLR_FPL is '$(JAVA_COMP_OUT_ANTLR_FPL)') + $(info JAVA_COMP_OUT_FPL is '$(JAVA_COMP_OUT_FPL)') + $(info JVM_IN_DIR is '$(JVM_IN_DIR)') $(info CLASSPATH is '$(CLASSPATH)') - $(info JAVA_IN_DL is '$(JAVA_IN_DL)') @: .PHONY: version @@ -118,7 +174,7 @@ version: .PHONY: setup setup: # ANTLR automatically creates $(ANTLR_OUT_DIR) - mkdir -p $(ANTLR_IN_DIR) $(JAVAC_IN_PRIMARY_DIR) $(JVM_IN_DIR) + mkdir -p $(ANTLR_IN_DIR) $(JAVA_COMP_IN_PRIMARY_DIR) $(JVM_IN_DIR) mkdir -p test deprecated experiment documentation temporary .PHONY: clean @@ -142,33 +198,33 @@ clean: echo "Warning: temporary directory does not exist"; \ fi -#-------------------------------------------------------------------------------- +#================================================================================ # recipes -ANTLR_FILES := GQL_20240412BaseListener.java GQL_20240412BaseVisitor.java GQL_20240412Lexer.java GQL_20240412Listener.java GQL_20240412Parser.java GQL_20240412Visitor.java - - -# Generate ANTLR .java files -$(ANTLR_OUT_FL): $(ANTLR_OUT_DIR)/%.java: $(ANTLR_IN_DIR)/%.g4 +# ANTLR a run of any of these will make all the files +$(ANTLR_OUT_DIR)/%Lexer.java: $(ANTLR_IN_DIR)/%.g4 @echo "making grammar from:" $< $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< +$(ANTLR_OUT_DIR)/%Parser.java: $(ANTLR_IN_DIR)/%.g4 + @echo "making grammar from:" $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< -$(JAVAC_OUT_ANTLR_FL): $(JVM_IN_DIR)/%.class: $(ANTLR_OUT_DIR)/%.java - @echo "making class from ANTLR generated" $< - $(JAVA_COMP) -d $(JVM_IN_DIR) -sourcepath $(JAVA_IN_DL) $(addprefix $(ANTLR_OUT_DIR)/, $(ANTLR_FILES)) +$(ANTLR_OUT_DIR)/%BaseVisitor.java: $(ANTLR_IN_DIR)/%.g4 + @echo "making grammar from:" $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< -# # Compile ANTLR-generated Java files -# $(JAVAC_OUT_ANTLR_FL): $(JVM_IN_DIR)/%.class: $(ANTLR_OUT_DIR)/%.java -# @echo "making class from ANTLR generated" $< -# $(JAVA_COMP) -d $(JVM_IN_DIR) -sourcepath $(JAVA_IN_DL) $< +$(ANTLR_OUT_DIR)/%Visitor.java: $(ANTLR_IN_DIR)/%.g4 + @echo "making grammar from:" $< + $(JAVA_INTERP) -jar $(ANTLR_JAR) -Dlanguage=Java -visitor -o $(ANTLR_OUT_DIR_PARENT) $< -# Compile primary Java files -$(JAVAC_OUT_PRIMARY_FL): $(JVM_IN_DIR)/%.class: $(JAVAC_IN_PRIMARY_DIR)/%.java $(JAVAC_OUT_ANTLR_FL) - @echo "making class from primary" $< - $(JAVA_COMP) -d $(JVM_IN_DIR) -sourcepath $(JAVA_IN_DL) $< +# Generic recipe for building .jar files and placing scripts in the executor directory +$(JAVA_COMP_OUT_DIR)/%.jar: $(JAVA_COMP_IN_PRIMARY_DIR)/%.java + @echo "Building $*..." + $(JAVA_COMP) -d $(JAVA_COMP_OUT_DIR) -sourcepath $(JAVA_COMP_IN_DL) $< + $(JAVA_ARCHIVE) cf $@ -C $(JVM_IN_DIR) $*.class + @echo "Creating script for $*..." + echo "#!/usr/bin/env bash\n$(JAVA_INTERP) -cp $@ $*" > executor/$*.sh + chmod +x executor/$*.sh -# Create JAR file -$(JVM_IN_DIR)/$(SYNTAX_TREE_20240412).jar: $(JAVAC_OUT_FL) - @echo "making program" $@ "from files found in" $(JVM_IN_DIR) - $(JAVA_ARCHIVE) cvf $@ -C $(JVM_IN_DIR) . +# LocalWords: makefile