]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Updated to new parse-utils api
authorMike D. Lowis <mike@mdlowis.com>
Sat, 10 Mar 2012 02:21:03 +0000 (21:21 -0500)
committerMike D. Lowis <mike@mdlowis.com>
Sat, 10 Mar 2012 02:21:03 +0000 (21:21 -0500)
deps/parse-utils
example.dl
source/dllexer/dllexer.cpp
source/dllexer/dllexer.h
source/dlparser/dlparser.cpp
source/dlparser/dlparser.h
source/main.cpp
source/visitors/scheme/scheme.cpp
source/visitors/scheme/scheme.h

index 73e512953c2ed551b6ac9d5e33ffa37d27b6e24e..2fc4293edf8a695e0de35ac875753db7b7308b2d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 73e512953c2ed551b6ac9d5e33ffa37d27b6e24e
+Subproject commit 2fc4293edf8a695e0de35ac875753db7b7308b2d
index 3691a0ffede7ba4d7c9a3fcb0829066b4ced3dc1..cb5ef5726921b6c05e779ca2f4bce26671e6aae1 100644 (file)
@@ -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
 
index 92f7cbe3d2a75a515517c7dff34cec6d89516b65..94d218b1dacf9726d4b35e0cab6615da59cb726e 100644 (file)
@@ -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())
         {
index 562566e4ff7ef973a2ece0c8428d48ccde09108f..a9d8be5d4e194656d7de8f50c23665557df9fa06 100644 (file)
@@ -62,6 +62,7 @@ typedef struct {
 
 class DLLexer : public ILexer {
     public:
+        DLLexer(std::istream& in);
         bool isWhiteSpace(void);
         bool isLetter(void);
         bool isDigit(void);
index 77bc480201800b4c9d441811ffd9c3a8c567d3e2..4a0973679d3dd1ac4ab98d2654b5704a7bd12d98 100644 (file)
@@ -2,7 +2,7 @@
 #include "exception.h"
 #include "common.h"
 
-DLParser::DLParser() : BTParser(_new DLLexer())
+DLParser::DLParser() : BTParser()
 {
     pattern_types.insert( std::pair<std::string,PatternType_T>( "Map", MAP_TYP ));
     pattern_types.insert( std::pair<std::string,PatternType_T>( "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 )
index 5c55491e5a215184e5f1fdbf9f172f628879a644..5053a1c9172d85c49653a466fc65c47f40c79d08 100644 (file)
@@ -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);
index 019416f6f086d08b69652289fd97e075a248973c..de129ca7aefa91e7e644f03a2a3554a779e97f96 100644 (file)
@@ -3,7 +3,6 @@
 #include <sstream>
 #include <fstream>
 #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
     {
index 9f28fcf5be849d3383ae5bd5820954535499029e..785558db0921f59352f1ba9e921e4ead1a3fe09d 100644 (file)
@@ -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;
     }
 }
index 4aaa47af1b2c5ff09956b6e5e73ba20cd29b4167..aaed935a9c53a539ca9f11ffd70e13846c02616c 100644 (file)
@@ -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);