From: Mike D. Lowis Date: Sat, 10 Mar 2012 02:21:03 +0000 (-0500) Subject: Updated to new parse-utils api X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=1910430b3fd8e7286a5551ab1c270c22fe6b1fbb;p=archive%2Fdlang.git Updated to new parse-utils api --- diff --git a/deps/parse-utils b/deps/parse-utils index 73e5129..2fc4293 160000 --- a/deps/parse-utils +++ b/deps/parse-utils @@ -1 +1 @@ -Subproject commit 73e512953c2ed551b6ac9d5e33ffa37d27b6e24e +Subproject commit 2fc4293edf8a695e0de35ac875753db7b7308b2d diff --git a/example.dl b/example.dl index 3691a0f..cb5ef57 100644 --- a/example.dl +++ b/example.dl @@ -18,14 +18,14 @@ foo = $some_symbol # Id foo = bar -foo.bar = bar +#foo.bar = bar # Map -foo = { - $foo : 1 + 1, - $bar : 2 + 2, - $stuff : 3 + 3 -} +#foo = { +# $foo : 1 + 1, +# $bar : 2 + 2, +# $stuff : 3 + 3 +#} # Vector foo = [] @@ -58,23 +58,28 @@ foo = ({|a,b| a + b })(1,2) if (1==1) { - 1 + 1 + print(1 + 1) }{ - + print(2 + 2) } if (1 == 1) { - + print(1 + 1) } #------------------------------------------------------------------------------ # Delayed Evaluation #------------------------------------------------------------------------------ -% delay [ (Expression) : make_promise({ $1 }) ] -% force [ (Expression) : $1 ] - -foo = delay 1 + 1 -foo = force foo +#% delay [ +# (Expression) : make_promise({ $1 }) +#] +# +#% force [ +# (Expression) : $1 +#] +# +#foo = delay 1 + 1 +#foo = force foo diff --git a/source/dllexer/dllexer.cpp b/source/dllexer/dllexer.cpp index 92f7cbe..94d218b 100644 --- a/source/dllexer/dllexer.cpp +++ b/source/dllexer/dllexer.cpp @@ -22,6 +22,10 @@ SingleCharMatch_T Single_Character_Matches[ NUM_SINGLE_CHAR_MATCHES ] = { { '.', MEMB }, }; +DLLexer::DLLexer(std::istream& in) : ILexer(in) +{ +} + bool DLLexer::isWhiteSpace(void) { return (current == ' ') || @@ -61,7 +65,7 @@ bool DLLexer::isStringChar(void) Token DLLexer::next(void) { Token ret; - while ( (!input->eof()) && (ret.type() == EOF) ) + while ( !eof() && (ret.type() == EOF) ) { if (isWhiteSpace()) { diff --git a/source/dllexer/dllexer.h b/source/dllexer/dllexer.h index 562566e..a9d8be5 100644 --- a/source/dllexer/dllexer.h +++ b/source/dllexer/dllexer.h @@ -62,6 +62,7 @@ typedef struct { class DLLexer : public ILexer { public: + DLLexer(std::istream& in); bool isWhiteSpace(void); bool isLetter(void); bool isDigit(void); diff --git a/source/dlparser/dlparser.cpp b/source/dlparser/dlparser.cpp index 77bc480..4a09736 100644 --- a/source/dlparser/dlparser.cpp +++ b/source/dlparser/dlparser.cpp @@ -2,7 +2,7 @@ #include "exception.h" #include "common.h" -DLParser::DLParser() : BTParser(_new DLLexer()) +DLParser::DLParser() : BTParser() { pattern_types.insert( std::pair( "Map", MAP_TYP )); pattern_types.insert( std::pair( "Vector", VECT_TYP )); @@ -20,9 +20,9 @@ DLParser::~DLParser() { } -AST* DLParser::parse(void) +void DLParser::parse(void) { - return Program(); + result = Program(); } bool DLParser::isMacro( Token& token ) diff --git a/source/dlparser/dlparser.h b/source/dlparser/dlparser.h index 5c55491..5053a1c 100644 --- a/source/dlparser/dlparser.h +++ b/source/dlparser/dlparser.h @@ -14,7 +14,7 @@ class DLParser : public BTParser public: DLParser(); ~DLParser(); - AST* parse(void); + void parse(void); bool isMacro(Token& token); bool speculate_GroupExpr(void); bool speculate_MapLiteral(void); diff --git a/source/main.cpp b/source/main.cpp index 019416f..de129ca 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -3,7 +3,6 @@ #include #include #include "dlparser.h" -#include "astprinter.h" #include "scheme.h" #include "common.h" #include "macro.h" @@ -21,23 +20,29 @@ int main(int argc, char** argv) { string input_fname(argv[1]); string temp_fname = createTempFileName( input_fname ); + ifstream input(input_fname.c_str()); DLParser parser; - ASTPrinter* visitor = NULL; + Scheme printer; + parser.input(new DLLexer(input)); + parser.parse(); + parser.process( printer ); - // Open the input and output files - ifstream input(input_fname.c_str()); + //string input_fname(argv[1]); + //string temp_fname = createTempFileName( input_fname ); + //ASTPrinter* visitor = NULL; - // Parse the file - parser.setInput(&input); + //// Open the input and output files + //ifstream input(input_fname.c_str()); - // Translate the AST - visitor = _new ASTPrinter( parser.parse() ); - visitor->visit(); + //// Parse the file + //parser.setInput(&input); - // Write output to screen - cout << visitor->str(); + //// Translate the AST + //visitor = _new ASTPrinter( parser.parse() ); + //visitor->visit(); - delete visitor; + //// Write output to screen + //cout << visitor->str(); } else { diff --git a/source/visitors/scheme/scheme.cpp b/source/visitors/scheme/scheme.cpp index 9f28fcf..785558d 100644 --- a/source/visitors/scheme/scheme.cpp +++ b/source/visitors/scheme/scheme.cpp @@ -3,7 +3,7 @@ using namespace std; -Scheme::Scheme(AST* root) : IVisitor(root) { +Scheme::Scheme() : IVisitor() { ifstream input("res/environment.scm"); if (input.is_open()) { @@ -11,17 +11,12 @@ Scheme::Scheme(AST* root) : IVisitor(root) { { string line; getline(input,line); - stream << line << endl; + cout << line << endl; } } input.close(); } -string Scheme::str() -{ - return stream.str(); -} - string Scheme::typeToString(ASTNodeType type) { ostringstream ret; @@ -93,7 +88,7 @@ void Scheme::beforeVisit(AST* cur, int depth) void Scheme::afterVisit(AST* cur, int depth) { - stream << endl; + cout << endl; } void Scheme::beforeChildren(AST* cur, int depth) @@ -104,7 +99,7 @@ void Scheme::beforeChildren(AST* cur, int depth) } else { - stream << "(" << typeToString( cur->type() ) << cur->text(); + cout << "(" << typeToString( cur->type() ) << cur->text(); } } @@ -112,16 +107,16 @@ void Scheme::afterChildren(AST* cur, int depth) { if( !isDatatype( cur->type() ) ) { - stream << ")"; + cout << ")"; } } void Scheme::beforeChild(AST* cur, int depth) { - stream << endl; + cout << endl; for(int i = 0; i< depth; i++) { - stream << " "; + cout << " "; } } @@ -152,19 +147,19 @@ void Scheme::printDatatype(AST* cur) switch(cur->type()) { case ID: - stream << "dl/" << cur->text(); + cout << "dl/" << cur->text(); break; case NUM: - stream << cur->text(); + cout << cur->text(); break; case CHAR: charToString( cur->text() ); break; case STRING: - stream << '"' << cur->text() << '"'; + cout << '"' << cur->text() << '"'; break; case SYMBOL: - stream << '\'' << cur->text(); + cout << '\'' << cur->text(); break; default: break; @@ -176,15 +171,15 @@ void Scheme::charToString(string ch) switch(ch.at(0)) { case ' ': - stream << "#\\space"; + cout << "#\\space"; break; case '\n': - stream << "#\\newline"; + cout << "#\\newline"; break; case '\r': - stream << "#\\return"; + cout << "#\\return"; break; default: - stream << "#\\" << ch; + cout << "#\\" << ch; } } diff --git a/source/visitors/scheme/scheme.h b/source/visitors/scheme/scheme.h index 4aaa47a..aaed935 100644 --- a/source/visitors/scheme/scheme.h +++ b/source/visitors/scheme/scheme.h @@ -7,11 +7,8 @@ #include "dllexer.h" class Scheme : public IVisitor { - protected: - ostringstream stream; public: - Scheme(AST* root); - string str(); + Scheme(); string typeToString(ASTNodeType type); bool isDatatype(ASTNodeType type); void printDatatype(AST* cur);