From 2eb5d2d26fb31ef43ea90909565d5fe0e6075762 Mon Sep 17 00:00:00 2001 From: Nathan R Date: Thu, 5 Aug 2021 16:37:51 +0200 Subject: [PATCH] Updated Makefile and ccmeta to chose to print either the tree the output --- Makefile | 16 ++++++++++++++-- ccmeta.leg | 14 +++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 492c1a1..15faea1 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,27 @@ CFLAGS = -I/opt/local/include -std=gnu99 -Wall -Wno-unused-label -Wno-unused-function -g LDLIBS = -L/opt/local/lib -lgc -lm +TREE = -t MAIN = ccmeta all : $(MAIN) tree : all .FORCE - ./$(MAIN) < $(MAIN)-tree.txt > $(MAIN)-tree.out + ./$(MAIN) $(TREE) < $(MAIN)-input.txt > $(MAIN)-tree.out -test : all .FORCE +output : all .FORCE + ./$(MAIN) < $(MAIN)-input.txt > $(MAIN)-output.out + diff $(MAIN)-input.txt $(MAIN)-output.out + +test : output ./dotest +both : all .FORCE + ./$(MAIN) $(TREE) < $(MAIN)-input.txt > $(MAIN)-tree.out + ./$(MAIN) < $(MAIN)-input.txt > $(MAIN)-output.out + diff $(MAIN)-input.txt $(MAIN)-output.out + + debug : all .FORCE ./$(MAIN) < debug.c > debug.out gcc -o debug debug.c @@ -27,6 +38,7 @@ $(MAIN) : $(MAIN).c object.c buffer.h clean : .FORCE rm -f $(MAIN) $(MAIN).c + rm -f *~ $(MAIN)-output.out tidy : .FORCE rm -f *~ $(MAIN)-tree.out diff --git a/ccmeta.leg b/ccmeta.leg index 16d3347..6787253 100644 --- a/ccmeta.leg +++ b/ccmeta.leg @@ -3733,7 +3733,6 @@ void outputTree(oop node, int depth) } #undef CASE #undef OUT - //outputTree(map_get(node, comment_symbol), depth); // if we want to print comments } void printTree() { @@ -3741,6 +3740,8 @@ void printTree() { printf("\n"); } +int toPrint = 0; + int main(int argc, char **argv) { # if (USE_GC) @@ -3798,13 +3799,19 @@ int main(int argc, char **argv) #undef _DO + /* Checking arguments */ + while (argc-- > 1) { + ++argv; + if (!strcmp(*argv, "-t")) toPrint = 1; + } + /* File scope */ pushScope(); inputStackPush(NULL); while (yyparse()) { - outputNode(yylval); - //printTree(); + if (toPrint) printTree(); + else outputNode(yylval); } popScope(); @@ -3818,6 +3825,7 @@ int main(int argc, char **argv) ++argv; if (!strcmp(*argv, "-g")) ++opt_g; else if (!strcmp(*argv, "-v")) ++opt_v; + else if (!strcmp(*argv, "-t")) toPrint = 1; else if (!strcmp(*argv, "-")) { readEvalPrint(globals, NULL); repled= 1;