From: Mike D. Lowis Date: Wed, 28 Mar 2012 15:24:51 +0000 (-0400) Subject: Fixed Floating point number syntax and Implemented syntax for setting object elements... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=6c7442263f01190ac8635d452720efb261b2d691;p=archive%2Fdlang.git Fixed Floating point number syntax and Implemented syntax for setting object elements (vectors, strings, and hashes) --- diff --git a/README.md b/README.md index 1b26cfe..86a677d 100644 --- 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 ---------------------------------------------- diff --git a/example.dl b/example.dl index 9634dae..3f729fa 100644 --- a/example.dl +++ b/example.dl @@ -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} diff --git a/res/environment.scm b/res/environment.scm index 4096321..fcf14cb 100644 --- a/res/environment.scm +++ b/res/environment.scm @@ -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) @@ -193,6 +193,12 @@ ((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) @@ -218,22 +224,7 @@ (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)) - diff --git a/source/dllexer/dllexer.cpp b/source/dllexer/dllexer.cpp index 8631f4a..235959a 100644 --- a/source/dllexer/dllexer.cpp +++ b/source/dllexer/dllexer.cpp @@ -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; } } diff --git a/source/dllexer/dllexer.h b/source/dllexer/dllexer.h index b3100a2..cc4c99f 100644 --- a/source/dllexer/dllexer.h +++ b/source/dllexer/dllexer.h @@ -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 { diff --git a/source/dlparser/dlparser.cpp b/source/dlparser/dlparser.cpp index 1c4ab10..69e2c58 100644 --- a/source/dlparser/dlparser.cpp +++ b/source/dlparser/dlparser.cpp @@ -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::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; } diff --git a/source/main.cpp b/source/main.cpp index 1e13c6f..1c362e1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -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 diff --git a/source/visitors/scheme/scheme.cpp b/source/visitors/scheme/scheme.cpp index ae1d40b..7d6ba29 100644 --- a/source/visitors/scheme/scheme.cpp +++ b/source/visitors/scheme/scheme.cpp @@ -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; + } } }