]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Added define and import operators. Updated assignment parser rule with a rule for...
authorMike D. Lowis <mike@mdlowis.com>
Sun, 11 Mar 2012 16:58:50 +0000 (12:58 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Sun, 11 Mar 2012 16:58:50 +0000 (12:58 -0400)
example.dl
res/environment.scm
source/dllexer/dllexer.cpp
source/dllexer/dllexer.h
source/dlparser/dlparser.cpp
source/main.cpp
source/visitors/scheme/scheme.cpp

index f2d5b554c58eeadd92b6afe84926b1c7e10faf12..4480afaa4976ee874e258af89fe098b98a4c6e03 100644 (file)
@@ -3,7 +3,7 @@
 #------------------------------------------------------------------------------
 
 # Nums
-foo = 1
+foo := 1
 foo = 1.0
 
 # Char
@@ -51,12 +51,12 @@ foo = ({|a,b| a + b })(1,2)
 # Macro Definition and Usage
 #------------------------------------------------------------------------------
 
-% if [
+@ if [
     (E B B) : exec_if($1, $2, $3),
     (E B)   : exec_if($1, $2)
 ]
 
-if (1==1)
+if (1 < 2)
 {
     print(1 + 1)
 }{
@@ -72,11 +72,11 @@ if (1 == 1)
 # Delayed Evaluation
 #------------------------------------------------------------------------------
 
-% delay [
+@ delay [
     (E) : make_promise({ $1 })
 ]
 
-% force [
+@ force [
     (E) : $1()
 ]
 
index 0f2e163b9e22034d796a102d02a506554f9dac20..a1993676f8e7ec76f6d53e815f56cb2a031ceec5 100644 (file)
@@ -1,18 +1,7 @@
 ;------------------------------------------------------------------------------
 ; Built-in Operators
 ;------------------------------------------------------------------------------
-(define ADD +)
-(define SUB -)
-(define MUL *)
-(define DIV /)
-(define NOT not)
-(define EQ equal?)
 (define (NE a b) (not (equal? a b)))
-(define LT <)
-(define GT >)
-(define LTE <=)
-(define GTE >=)
-(define FN_CALL apply)
 (define (ARRY_IDX coll idx)
   (cond
     ((list? coll)
 ;------------------------------------------------------------------------------
 ; Built-in datatype constructors
 ;------------------------------------------------------------------------------
-(define VECTOR vector)
-(define LIST list)
-(define PARAMS list)
 (define (MAP . args) (alist->hash-table args))
-(define (MACRO) '())
 
 ;------------------------------------------------------------------------------
 ; Import necessary libs
index 94d218b1dacf9726d4b35e0cab6615da59cb726e..6186adb97d8bca6863c7c5c5708e82319903af89 100644 (file)
@@ -4,7 +4,7 @@
 
 using namespace std;
 
-#define NUM_SINGLE_CHAR_MATCHES 14
+#define NUM_SINGLE_CHAR_MATCHES 12
 SingleCharMatch_T Single_Character_Matches[ NUM_SINGLE_CHAR_MATCHES ] = {
     { '[', LBRACK },
     { ']', RBRACK },
@@ -17,8 +17,6 @@ SingleCharMatch_T Single_Character_Matches[ NUM_SINGLE_CHAR_MATCHES ] = {
     { '-', SUB },
     { '*', MUL },
     { '/', DIV },
-    { '%', MACRO },
-    { ':', SEP },
     { '.', MEMB },
 };
 
@@ -52,7 +50,9 @@ bool DLLexer::isOperator(void)
             || (current == '<')
             || (current == '>')
             || (current == '|')
-            || (current == '&'));
+            || (current == '&')
+            || (current == ':')
+            || (current == '@'));
 }
 
 bool DLLexer::isStringChar(void)
@@ -317,6 +317,30 @@ void DLLexer::MultiCharOp(Token& tok)
         consume();
         tok = Token(AND, line, column);
     }
+    else if(last == ':')
+    {
+        if(current == '=')
+        {
+            consume();
+            tok = Token(DEFN, line, column);
+        }
+        else
+        {
+            tok = Token(SEP, line, column);
+        }
+    }
+    else if(last == '@')
+    {
+        if(current == '=')
+        {
+            consume();
+            tok = Token(IMPORT, line, column);
+        }
+        else
+        {
+            tok = Token(MACRO, line, column);
+        }
+    }
     else
     {
         throw Exception(line,column);
index a9d8be5d4e194656d7de8f50c23665557df9fa06..3e1c10bb11f67f925359d401317b28d801220b40 100644 (file)
@@ -37,22 +37,24 @@ typedef enum TokenTypes
     GT       = 26,
     LTE      = 27,
     GTE      = 28,
-    ASSIGN   = 29,
-    ADD      = 30,
-    SUB      = 31,
-    MUL      = 32,
-    DIV      = 33,
-    MEMB     = 34,
+    ADD      = 29,
+    SUB      = 30,
+    MUL      = 31,
+    DIV      = 32,
+    DEFN     = 33,
+    ASSIGN   = 34,
+    MEMB     = 35,
+    SEP      = 36,
+    ARRY_IDX = 37,
+    MACRO    = 38,
+    IMPORT   = 39,
 
     // AST "Virtual" Node Types
-    MACRO    = 40,
-    SEP      = 41,
-    PROGRAM  = 42,
-    BLOCK    = 43,
-    FN_CALL  = 44,
-    PARAMS   = 45,
-    ARRY_IDX = 46,
-    PATT     = 47,
+    PROGRAM  = 40,
+    BLOCK    = 41,
+    FN_CALL  = 42,
+    PARAMS   = 43,
+    PATT     = 44,
 } eTokenTypes;
 
 typedef struct {
index cff64172b4f22277057255188672838b6ef93e74..7334642c3f5599c64af4a8e3f85acf132d1a5354 100644 (file)
@@ -224,7 +224,12 @@ AST* DLParser::Expression(void)
 AST* DLParser::AssignExpr(void)
 {
     AST* ret = LogicalExpr();
-    if(lookaheadType(1) == ASSIGN)
+    if(lookaheadType(1) == DEFN)
+    {
+        match(DEFN);
+        ret = new AST(DEFN, 2, ret, LogicalExpr());
+    }
+    else if(lookaheadType(1) == ASSIGN)
     {
         match(ASSIGN);
         ret = new AST(ASSIGN, 2, ret, LogicalExpr());
index d53bad1e05bc794c5dd0ad37e74105876dcec06c..dbea3011cdd6af718ad7e338236fa50e298d583e 100644 (file)
@@ -41,8 +41,9 @@ int main(int argc, char** argv)
         output.close();
 
         // Compile the temporary file with chicken scheme
-        system( string("csc -O5 " + temp_fname).c_str() );
+        system( string("csc -O5 -v " + temp_fname).c_str() );
 
+        cout << "Removing temporary files..." << endl;
         (void)remove( temp_fname.c_str() );
     }
     else
index 1d69f8fe547e624b84fc59966daa4adfe43f57a6..f1aa4a069bca250075d4efb706226e6816b0e1f0 100644 (file)
@@ -32,55 +32,61 @@ string Scheme::typeToString(ASTNodeType type)
         case CHAR:
             ret << "CHAR "; break;
         case ADD:
-            ret << "ADD "; break;
+            ret << "+ "; break;
         case SUB:
-            ret << "SUB "; break;
+            ret << "- "; break;
         case MUL:
-            ret << "MUL "; break;
+            ret << "* "; break;
         case DIV:
-            ret << "DIV "; break;
+            ret << "/ "; break;
         case AND:
             ret << "and "; break;
         case OR:
             ret << "or "; break;
         case NOT:
-            ret << "NOT "; break;
+            ret << "not "; break;
         case EQ:
-            ret << "EQ "; break;
+            ret << "equal? "; break;
         case NE:
             ret << "NE "; break;
         case LT:
-            ret << "LT "; break;
+            ret << "< "; break;
         case GT:
-            ret << "GT "; break;
+            ret << "> "; break;
         case LTE:
-            ret << "LTE "; break;
+            ret << "<= "; break;
         case GTE:
-            ret << "GTE "; break;
-        case MACRO:
-            ret << "MACRO "; break;
-        case ASSIGN:
+            ret << ">= "; break;
+        case DEFN:
             ret << "define "; break;
+        case ASSIGN:
+            ret << "set! "; break;
         case PROGRAM:
             ret << "begin "; break;
         case VECTOR:
-            ret << "VECTOR "; break;
+            ret << "vector "; break;
         case LIST:
-            ret << "LIST "; break;
+            ret << "list "; break;
         case BLOCK:
             ret << "begin "; break;
         case FUNC:
             ret << "lambda "; break;
         case FN_CALL:
-            ret << "FN_CALL "; break;
+            ret << "apply "; break;
         case ARRY_IDX:
             ret << "ARRY_IDX "; break;
         case SEP:
             ret << "cons "; break;
         case MEMB:
             ret << "hash-table-ref "; break;
+
+        // Print nothing for the following nodes
+        case MACRO:
         case PARAMS:
             break;
+
+        // Print out the type id (this will probably cause an error but also
+        // alert us to the fact that it is not properly handled)
         default:
             ret << type; break;
     }
@@ -99,24 +105,27 @@ void Scheme::afterVisit(AST* cur, int depth)
 
 void Scheme::beforeChildren(AST* cur, int depth)
 {
-    if (cur->type() == MEMB)
+    if( cur->type() != MACRO )
     {
-        cur->children()->back()->type(STRING);
-    }
+        if (cur->type() == MEMB)
+        {
+            cur->children()->back()->type(STRING);
+        }
 
-    if( isDatatype( cur->type() ) )
-    {
-        printDatatype( cur );
-    }
-    else
-    {
-        stream << "(" << typeToString( cur->type() ) << cur->text();
+        if( isDatatype( cur->type() ) )
+        {
+            printDatatype( cur );
+        }
+        else
+        {
+            stream << "(" << typeToString( cur->type() ) << cur->text();
+        }
     }
 }
 
 void Scheme::afterChildren(AST* cur, int depth)
 {
-    if( !isDatatype( cur->type() ) )
+    if( !isDatatype( cur->type() ) && (cur->type() != MACRO))
     {
         stream << ")";
     }