From 01d5fa75b10f8d100386f7418a981a7bb14f4bc1 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Mon, 5 Mar 2012 14:47:56 -0500 Subject: [PATCH] Modified main to simply print the AST instead of translate it --- deps/parse-utils | 2 +- source/dllexer/dllexer.cpp | 1 - source/main.cpp | 17 +++++---------- source/visitors/sexp/sexp.cpp | 41 ----------------------------------- source/visitors/sexp/sexp.h | 23 -------------------- 5 files changed, 6 insertions(+), 78 deletions(-) delete mode 100644 source/visitors/sexp/sexp.cpp delete mode 100644 source/visitors/sexp/sexp.h diff --git a/deps/parse-utils b/deps/parse-utils index efe0948..78ac356 160000 --- a/deps/parse-utils +++ b/deps/parse-utils @@ -1 +1 @@ -Subproject commit efe094829e9d5b499cc1ec9d22dca2f74b796210 +Subproject commit 78ac3565dc1814885278bb9afd8844c73a02014b diff --git a/source/dllexer/dllexer.cpp b/source/dllexer/dllexer.cpp index 7a1f6d4..96e72c0 100644 --- a/source/dllexer/dllexer.cpp +++ b/source/dllexer/dllexer.cpp @@ -100,7 +100,6 @@ Token DLLexer::next(void) SingleCharOp(ret); } } - cout << "token: " << ret.type() << endl; return ret; } diff --git a/source/main.cpp b/source/main.cpp index 2a412a3..d9db18d 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -3,7 +3,7 @@ #include #include #include "dlparser.h" -#include "sexp.h" +#include "astprinter.h" #include "scheme.h" #include "cork.h" @@ -20,30 +20,23 @@ int main(int argc, char** argv) { string input_fname(argv[1]); string temp_fname = createTempFileName( input_fname ); + (void)temp_fname; DLParser parser; - Scheme* visitor = NULL; + ASTPrinter* visitor = NULL; // Open the input and output files ifstream input(input_fname.c_str()); - ofstream output(temp_fname.c_str()); // Parse the file parser.setInput(&input); // Translate the AST - visitor = _new Scheme( parser.parse() ); + visitor = _new ASTPrinter( parser.parse() ); visitor->visit(); - // Write to a temp file - output << visitor->str(); + // Write output to screen cout << visitor->str(); - output.close(); - // Compile temp file - system(("csc " + temp_fname).c_str()); - - // delete temp file - remove(temp_fname.c_str()); delete visitor; } else diff --git a/source/visitors/sexp/sexp.cpp b/source/visitors/sexp/sexp.cpp deleted file mode 100644 index d0eb266..0000000 --- a/source/visitors/sexp/sexp.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "sexp.h" - -using namespace std; - -string SEXP::str() -{ - return stream.str(); -} - -void SEXP::beforeVisit(AST* cur, int depth) -{ -} - -void SEXP::afterVisit(AST* cur, int depth) -{ - stream << endl; -} - -void SEXP::beforeChildren(AST* cur, int depth) -{ - stream << "(" << cur->type() << " " << cur->text(); -} - -void SEXP::afterChildren(AST* cur, int depth) -{ - stream << ")"; -} - -void SEXP::beforeChild(AST* cur, int depth) -{ - stream << endl; - for(int i = 0; i< depth; i++) - { - stream << " "; - } -} - -void SEXP::afterChild(AST* cur, int depth) -{ -} - diff --git a/source/visitors/sexp/sexp.h b/source/visitors/sexp/sexp.h deleted file mode 100644 index 415fa18..0000000 --- a/source/visitors/sexp/sexp.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef SEXP_H -#define SEXP_H - -#include "ivisitor.h" -#include -#include - -class SEXP : public IVisitor { - protected: - ostringstream stream; - public: - SEXP(AST* root) : IVisitor(root) {}; - string str(); - private: - void beforeVisit(AST* cur, int depth); - void afterVisit(AST* cur, int depth); - void beforeChildren(AST* cur, int depth); - void afterChildren(AST* cur, int depth); - void beforeChild(AST* cur, int depth); - void afterChild(AST* cur, int depth); -}; - -#endif -- 2.55.0