From 7ffdddb6918982ee2a3048391c2f9f0da7f99cdd Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Fri, 13 Mar 2009 10:03:23 +0000 Subject: [PATCH] [pointers] finished :-) --- doc/roadmap.doch | 2 +- src/ast/generator-data.cc | 1 + src/lang/mugiwara/bison-parser/lexer.l | 3 ++ src/lang/mugiwara/bison-parser/parser.y | 33 ++++++++++++---------- .../mugiwara/input/pointers/double-dereference.mgw | 2 +- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/doc/roadmap.doch b/doc/roadmap.doch index f83b74d..9c0d7cd 100644 --- a/doc/roadmap.doch +++ b/doc/roadmap.doch @@ -11,7 +11,7 @@ * - Bools \htmlonly[OK]\endhtmlonly * - Integers \htmlonly[OK]\endhtmlonly * - Floats \htmlonly[OK]\endhtmlonly - * - Pointers + * - Pointers \htmlonly[OK]\endhtmlonly * - Arrays * - Union * - Structs diff --git a/src/ast/generator-data.cc b/src/ast/generator-data.cc index 40cee2a..7e14639 100644 --- a/src/ast/generator-data.cc +++ b/src/ast/generator-data.cc @@ -97,6 +97,7 @@ const ag::Node ag::nodes[] = { {"ArrayType", "Type", "Represent an array", { {"Type *", "type"}, + {"uint16_t", "size"}, {"", ""} } }, diff --git a/src/lang/mugiwara/bison-parser/lexer.l b/src/lang/mugiwara/bison-parser/lexer.l index ac92a22..50db74c 100644 --- a/src/lang/mugiwara/bison-parser/lexer.l +++ b/src/lang/mugiwara/bison-parser/lexer.l @@ -53,6 +53,9 @@ makeFloat(double value); \( return LPAR; \) return RPAR; +\[ return LSB; +\] return RSB; + \{ return LBR; \} return RBR; diff --git a/src/lang/mugiwara/bison-parser/parser.y b/src/lang/mugiwara/bison-parser/parser.y index d9a4676..f4ea8b3 100644 --- a/src/lang/mugiwara/bison-parser/parser.y +++ b/src/lang/mugiwara/bison-parser/parser.y @@ -123,7 +123,7 @@ createType(const char * name) %token ADD SUB DIV STAR MOD %token OR AND XOR SHL ASHR LSHR %token NOT BANG OROR ANDAND -%token LPAR RPAR LBR RBR +%token LPAR RPAR LBR RBR LSB RSB %token GOTO CONST CAST RETURN %token IF ELSE WHILE DO FOR @@ -143,7 +143,6 @@ createType(const char * name) %type cmp_exp shift_exp add_exp mul_exp unary_exp %type call_exp %type call_exp_args call_exp_args_non_empty -%type is_const %% @@ -178,9 +177,9 @@ func_params: func_params_non_empty { $$ = $1; } func_params_non_empty: var_decl { $$ = new std::vector(); $$->push_back($1); -} | var_decl COMMA func_params_non_empty { - $$ = $3; - $$->push_back($1); +} | func_params_non_empty COMMA var_decl { + $$ = $1; + $$->push_back($3); }; block: LBR var_decls statements RBR { @@ -281,18 +280,22 @@ return_statement: RETURN SEMICOL { $$ = ret; } -type: is_const ID { - $$ = createType($2); - $$->isConst = $1; - $$->name = $2; +type: ID { + $$ = createType($1); + $$->name = $1; +} | CONST type { + $2->isConst = true; + $$ = $2; } | STAR type { ast::PointerType * type = new ast::PointerType; type->type = $2; $$ = type; -}; - -is_const: CONST { $$ = true; } -| /* espilon */ { $$ = false; }; +} | LBR NUMBER RBR type { + ast::ArrayType * type = new ast::ArrayType; + type->type = $4; + type->size = $2->number; + $$ = type; +} exp: assign_exp { assert($1); @@ -362,9 +365,9 @@ unary_exp: NUMBER { $$ = $1; } cast->type = $3; cast->exp = $5; $$ = cast; -} | STAR unary_exp { +} | unary_exp STAR { ast::DereferenceExp * exp = new ast::DereferenceExp; - exp->exp = $2; + exp->exp = $1; $$ = exp; }; diff --git a/tests/lang/mugiwara/input/pointers/double-dereference.mgw b/tests/lang/mugiwara/input/pointers/double-dereference.mgw index 909f20d..f8d195a 100644 --- a/tests/lang/mugiwara/input/pointers/double-dereference.mgw +++ b/tests/lang/mugiwara/input/pointers/double-dereference.mgw @@ -1,4 +1,4 @@ int32 main(int32 argc, **int8 argv) { - return **argv; + return argv**; } -- 2.11.4.GIT