From 5217fee017da863929ce1de0b3f9283d6c1f8cb9 Mon Sep 17 00:00:00 2001 From: "Mike D. Lowis" Date: Mon, 5 Mar 2012 20:47:30 -0500 Subject: [PATCH] Implemented hash map syntax --- example.dl | 7 +++++++ source/dllexer/dllexer.h | 1 + source/dlparser/dlparser.cpp | 19 ++++++++++++++++++- source/dlparser/dlparser.h | 1 + source/main.cpp | 1 - 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/example.dl b/example.dl index bbc0c66..c3a4a72 100644 --- a/example.dl +++ b/example.dl @@ -40,6 +40,13 @@ foo = "12345"[2] # SYMBOL foo = $some_symbol +# MAP +foo = { + $foo : 1 + 1, + $bar : 2 + 2, + $stuff : 3 + 3 +} + #% if [ # (Ex Bk) : exec_if($1, $2), # (Ex Bk Bk) : exec_if($1, $2, $3) diff --git a/source/dllexer/dllexer.h b/source/dllexer/dllexer.h index 620d766..562566e 100644 --- a/source/dllexer/dllexer.h +++ b/source/dllexer/dllexer.h @@ -15,6 +15,7 @@ typedef enum TokenTypes LIST = 5, VECTOR = 6, FUNC = 7, + MAP = 8, // Symbols LBRACK = 10, diff --git a/source/dlparser/dlparser.cpp b/source/dlparser/dlparser.cpp index 22b3965..3b2e0ac 100644 --- a/source/dlparser/dlparser.cpp +++ b/source/dlparser/dlparser.cpp @@ -284,10 +284,27 @@ AST* DLParser::Literal(void) return node; } +// MapLiteral = '{' (Literal ':' LogicalExpr)* '}' AST* DLParser::MapLiteral(void) { AST* ret = NULL; - throw Exception(lookaheadToken(1).line(), lookaheadToken(1).column()); + + //throw Exception(lookaheadToken(1).line(),lookaheadToken(1).column()); + match(LBRACE); + do + { + if( lookaheadType(1) == COMMA ) consume(); + + AST* child = Literal(); + match(SEP); + child = _new AST(SEP, 2, child, LogicalExpr()); + + ret = ((ret == NULL) ? _new AST(MAP) : ret); + ret->addChild(child); + } + while( lookaheadType(1) == COMMA ); + match(RBRACE); + return ret; } diff --git a/source/dlparser/dlparser.h b/source/dlparser/dlparser.h index b3553d0..8fca4ff 100644 --- a/source/dlparser/dlparser.h +++ b/source/dlparser/dlparser.h @@ -60,6 +60,7 @@ class DLParser : public BTParser // | STRING // | SYMBOL // + // MapLiteral = '{' (Literal ':' AssignExpr)* '}' // VectorLiteral = '[' ExpList ']' // // ListLiteral = '(' ExpList ')' diff --git a/source/main.cpp b/source/main.cpp index d9db18d..0493636 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -20,7 +20,6 @@ int main(int argc, char** argv) { string input_fname(argv[1]); string temp_fname = createTempFileName( input_fname ); - (void)temp_fname; DLParser parser; ASTPrinter* visitor = NULL; -- 2.54.0