]> git.mdlowis.com Git - archive/dlang.git/commitdiff
Fixed Floating point number syntax and Implemented syntax for setting object elements...
authorMike D. Lowis <mike@mdlowis.com>
Wed, 28 Mar 2012 15:24:51 +0000 (11:24 -0400)
committerMike D. Lowis <mike@mdlowis.com>
Wed, 28 Mar 2012 15:24:51 +0000 (11:24 -0400)
README.md
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 1b26cfea2ae1bc80603799610493f485c9650b57..86a677d8b4ad432c3c7a67ad3f9cd71ab0722058 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 DLang
 ==============================================
 
-    Version:    0.2
+    Version:    0.3
     Created By: Michael D. Lowis
     Email:      mike@mdlowis.com
 
@@ -18,16 +18,17 @@ License
 ----------------------------------------------
 
 Unless explicitly stated otherwise, all code and documentation in this project
-is released under the FreeBSD License. You can find a copy of the license text
-in the LICENSE.md file.
+is released under the BSD 2-Clause License. You can find a copy of the license
+text in the LICENSE.md file.
 
 Requirements For Building
 ----------------------------------------------
 
-* Ruby and Rake
+* Ruby
+* Rake (>= 0.9.2)
 * Chicken Scheme Compiler
-* A C++ compiler
-* Python (For unit test generation)
+* Chicken Scheme vector-lib Egg
+* A C++ compiler (Tested with gcc)
 
 Build Instructions
 ----------------------------------------------
@@ -45,8 +46,8 @@ following commands:
 Installation
 ----------------------------------------------
 
-There are no installation instructions at the moment. This is a work in
-progress.
+There are no installation instructions at the moment. The binary is self
+contained and can be placed anywhere you want it.
 
 Project Files and Directories
 ----------------------------------------------
@@ -64,18 +65,20 @@ Project Files and Directories
     rakefile.rb    Script containing the build configuration and tasks.
     README.md      You're reading this file right now!
 
-Know Issues or Bugs
+Known Issues or Bugs
 ----------------------------------------------
 
 This is a non-comprehensive list of known issues and bugs that I intend to fix.
 
-* The parser segfaults on \*nix systems due to freeing invalid pointers and other memory management issues
+* The debug build segfaults on \*nix systems due to freeing invalid pointers and other memory management issues
 * Error messages are obtuse and unfriendly.
 * Parser and Lexer have 0 error recovery.
 
 Version History
 ----------------------------------------------
 
+### Version 0.3
+
 ### Version 0.2
 
 This version includes a much improved macro syntax with support for multiple
@@ -87,7 +90,6 @@ syntax for list literals. See example.dl for an example of the updated syntax.
 Very first version ever. Its buggy, has obtuse error messages, and supports
 about 1/20 of what I would like to see. Lets call it a proof of concept.
 
-
 Feature Wish List
 ----------------------------------------------
 
@@ -96,6 +98,7 @@ the future.
 
 * Command line options
 * Multi-file support
+* UTF-8 Support
 
 More Info
 ----------------------------------------------
index 9634dae782f79c7fbe521893b89a874b65661875..3f729fa3023baae0392c278b86abe0a73a973447 100644 (file)
@@ -6,11 +6,9 @@
 foo := 1
 foo = 1.0
 foo = 1.0e1
-foo = 1.0e1.0
 foo = -1
 foo = -1.0
 foo = -1.0e-1
-foo = -1.0e-1.0
 
 # Char
 foo = 'a'
@@ -34,9 +32,15 @@ foo = $some_symbol
 foo = {
     $foo : 1 + 1,
     "stuff" : 2 + 2,
+    $stuff : 2 + 2,
     $bar : 3 + 3,
 }
 
+# Setting map elements
+foo["stuff"] = 3
+foo.stuff = 5
+
+# Accessing map elements
 print( foo[$bar] )
 print( foo["stuff"] )
 print( foo.stuff )
@@ -48,6 +52,9 @@ foo = [1,2,3]
 foo = foo[1]
 foo = [1,2,3,4,5][2]
 
+# Setting Vector Elements
+foo[2] = 6
+
 # List
 foo = ()
 foo = (1,)
@@ -55,6 +62,9 @@ foo = (1,2,3)
 foo = foo[1]
 foo = (1,2,3,4,5)[2]
 
+# Setting List Elements
+foo[2] = 6
+
 # Block
 foo = { 1 + 1 }
 foo = {|a| a + 1}
index 4096321adaa8fd712f3ae86699a4a30a28b453b0..fcf14cbc1c4cdf8f95dd98c3c219d72d6529a083 100644 (file)
@@ -58,7 +58,7 @@
 (define dl/print print)
 (define dl/error error)
 
-; Map
+; map function definitions
 (define dl/list_map map)
 (define dl/vector_map vector-map)
 (define dl/string_map string-map)
         ((hash-table? ls) (apply hash-table-concatenate args))
         ((string? ls) (apply string-concatenate args)) )))
 
+(define (obj-set! obj idx val)
+  (cond
+    ((vector? obj) (vector-set! obj idx val))
+    ((hash-table? obj) (hash-table-set! obj idx val))
+    ((string? obj) (string-set! obj idx val)) ))
+
 (define (error reason . args)
       (display "Error: ")
       (display reason)
                          (set! result x)
                          result))))))))
 
-(define dl/force
-  (lambda (object)
-    (object)))
-
 ;------------------------------------------------------------------------------
 ; Start User Defined Code
 ;------------------------------------------------------------------------------
 
-; Potential implementation of prototype objects
-;(define Proto
-;  (list (make-hash-table)))
-;
-;(define (proto-clone p)
-;  (list (make-hash-table) p))
-;
-;(define (proto? p))
-;(define (proto-value p))
-;(define (proto-member name))
-
index 8631f4a8c77b614258fb7ea00ee37def8919294e..235959ac900a9ed1cec4d67d52efc8f3b04a2cec 100644 (file)
@@ -165,15 +165,28 @@ void DLLexer::Number(Token& tok, bool isNegative)
         oss << current;
         consume();
 
-        // Capture the sign if we have one
         if(current == '-')
         {
+            // Capture the sign
+            oss << current;
             consume();
-            oss << FloatingPoint(true);
+        }
+
+        if( isDigit() )
+        {
+            // Capture the integer part
+            do
+            {
+                oss << current;
+                consume();
+            }
+            while(isDigit());
         }
         else
         {
-            oss << FloatingPoint(false);
+            Exception ex(line,column);
+            ex << "Integer for floating point exponent";
+            throw ex;
         }
     }
 
index b3100a298f1d2c9bb1482a36036c06a415ac75e9..cc4c99ffe1104fd78ce89790f7462b6ff7a8a4cb 100644 (file)
@@ -48,13 +48,14 @@ typedef enum TokenTypes
     ARRY_IDX = 37,
     MACRO    = 38,
     IMPORT   = 39,
+    MUTATE   = 40,
 
     // AST "Virtual" Node Types
-    PROGRAM  = 40,
-    BLOCK    = 41,
-    FN_CALL  = 42,
-    PARAMS   = 43,
-    PATT     = 44,
+    PROGRAM  = 50,
+    BLOCK    = 51,
+    FN_CALL  = 52,
+    PARAMS   = 53,
+    PATT     = 54,
 } eTokenTypes;
 
 typedef struct {
index 1c4ab10f3f45d680bfb41bee471fbe694f6da424..69e2c58cf3fe292f7b3367e605c549b2ad7625cf 100644 (file)
@@ -224,6 +224,7 @@ AST* DLParser::Expression(void)
 AST* DLParser::AssignExpr(void)
 {
     AST* ret = LogicalExpr();
+    AST* child = NULL;
     if(lookaheadType(1) == DEFN)
     {
         match(DEFN);
@@ -232,7 +233,28 @@ AST* DLParser::AssignExpr(void)
     else if(lookaheadType(1) == ASSIGN)
     {
         match(ASSIGN);
-        ret = new AST(ASSIGN, 2, ret, LogicalExpr());
+        child = LogicalExpr();
+        if( (ret->type() != ID) && (ret->type() != ARRY_IDX) && (ret->type() != MEMB))
+        {
+            Exception ex;
+            ex << "Expected ID or object reference on left hand side of assignment.";
+            throw ex;
+        }
+        else if( (ret->type() == ARRY_IDX) || (ret->type() == MEMB) )
+        {
+            AST* obj = NULL;
+            AST* idx = NULL;
+            list<AST*>::iterator it = ret->children()->begin();
+            obj = *it;
+            it++;
+            idx = *it;
+            idx->type( (ret->type() == MEMB) ? SYMBOL : idx->type() );
+            ret = new AST(MUTATE, 3, obj, idx, child );
+        }
+        else
+        {
+            ret = new AST(ASSIGN, 2, ret, child);
+        }
     }
     return ret;
 }
index 1e13c6f7b940be275b65ddaf0bf96e349a904db5..1c362e132a618682b904e2d2462d88f8b318b1b8 100644 (file)
@@ -29,14 +29,14 @@ int main(int argc, char** argv)
         // Setup Parser and Visitors
         DLParser parser;
         Scheme printer(output);
-        //Scheme debug_printer(std::cout);
+        Scheme debug_printer(std::cout);
         parser.input(new DLLexer(input));
 
         // Parse the input stream
         parser.parse();
 
         // Post process the AST (converts to scheme and prints to output file)
-        //parser.process( debug_printer );
+        parser.process( debug_printer );
         parser.process( printer );
 
         // Close the output file
index ae1d40b28d855a5cb307b84dd171a582e9f33788..7d6ba290e1132d6324fb2112715c245fcf0f6274 100644 (file)
@@ -55,6 +55,8 @@ string Scheme::typeToString(ASTNodeType type)
             ret << "define "; break;
         case ASSIGN:
             ret << "set! "; break;
+        case MUTATE:
+            ret << "obj-set! "; break;
         case PROGRAM:
             ret << "begin "; break;
         case VECTOR:
@@ -285,12 +287,15 @@ void Scheme::defineSymbol(AST* cur)
 
 void Scheme::assignSymbol(AST* cur)
 {
-    string text = cur->children()->front()->text();
-    if( scope_stack.lookup( text ) == NULL )
+    if( cur->type() == ID )
     {
-        Exception ex;
-        ex << "Symbol '" << text << "' has not been defined in this scope.";
-        throw ex;
+        string text = cur->children()->front()->text();
+        if( scope_stack.lookup( text ) == NULL )
+        {
+            Exception ex;
+            ex << "Symbol '" << text << "' has not been defined in this scope.";
+            throw ex;
+        }
     }
 }