diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-26 17:23:00 +0100 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-26 17:23:00 +0100 |
commit | e9657092063e786a52fefcfa4c528bac07472908 (patch) | |
tree | 01ac8abdc1ad5af82b0e48f163cd1e2b7cadced0 /c_compiler | |
parent | dec9dc403e540ef4424debfdd866c73ca93adc83 (diff) | |
download | Compiler-e9657092063e786a52fefcfa4c528bac07472908.tar.gz Compiler-e9657092063e786a52fefcfa4c528bac07472908.zip |
working printf and added ellipsis
Diffstat (limited to 'c_compiler')
-rw-r--r-- | c_compiler/src/c_lexer.flex | 1 | ||||
-rw-r--r-- | c_compiler/src/c_parser.y | 11 | ||||
-rw-r--r-- | c_compiler/src/declaration.cpp | 2 | ||||
-rw-r--r-- | c_compiler/src/expression.cpp | 7 |
4 files changed, 16 insertions, 5 deletions
diff --git a/c_compiler/src/c_lexer.flex b/c_compiler/src/c_lexer.flex index 7ed46ae..8dcef35 100644 --- a/c_compiler/src/c_lexer.flex +++ b/c_compiler/src/c_lexer.flex @@ -54,6 +54,7 @@ ALL . (default) { return T_DEFAULT; } (switch) { return T_SWITCH; } +[.][.][.] { return T_ELLIPSIS; } [;] { return T_SC; } [,] { return T_CMA; } [(] { return T_LRB; } diff --git a/c_compiler/src/c_parser.y b/c_compiler/src/c_parser.y index 1ef8d06..2c5d215 100644 --- a/c_compiler/src/c_parser.y +++ b/c_compiler/src/c_parser.y @@ -41,7 +41,7 @@ void yyerror(const char *); T_VOID T_CHAR T_SHORT T_INT T_LONG T_FLOAT T_DOUBLE T_SIGNED T_UNSIGNED T_TYPEDEF T_EXTERN T_STATIC T_AUTO T_REGISTER T_CONST T_VOLATILE T_GOTO T_BREAK T_CONTINUE - T_CASE T_DEFAULT T_SWITCH + T_CASE T_DEFAULT T_SWITCH T_ELLIPSIS %nonassoc T_RRB %nonassoc T_ELSE @@ -57,7 +57,7 @@ void yyerror(const char *); SelectionStatement ExpressionStatement JumpStatement IterationStatement LabeledStatement -%type <declaration> ParameterList Parameter DeclarationList Declaration InitDeclaratorList +%type <declaration> ParameterTypeList ParameterList Parameter DeclarationList Declaration InitDeclaratorList InitDeclarator IdentifierList Declarator DirectDeclarator @@ -104,6 +104,10 @@ FunctionDefinition: { $$ = new Function($2->getId(), $3, $2->getNext()); delete $1; } ; +ParameterTypeList: + ParameterList { $$ = $1; } + | ParameterList T_CMA T_ELLIPSIS { $$ = $1; } + ; ParameterList: Parameter { $$ = $1; } | ParameterList T_CMA Parameter { $3->linkDeclaration($$); $$ = $3; } @@ -222,7 +226,8 @@ DirectDeclarator: } | DirectDeclarator T_LSB T_RSB { $$ = $1; } | DirectDeclarator T_LRB T_RRB { $$ = $1; $$->setExternDeclaration(true); } - | DirectDeclarator T_LRB ParameterList T_RRB { $1->linkDeclaration($3); $$ = $1; $$->setExternDeclaration(true); } + | DirectDeclarator T_LRB ParameterTypeList T_RRB + { $1->linkDeclaration($3); $$ = $1; $$->setExternDeclaration(true); } | DirectDeclarator T_LRB IdentifierList T_RRB { $$ = $1; $$->setExternDeclaration(true); } ; diff --git a/c_compiler/src/declaration.cpp b/c_compiler/src/declaration.cpp index 95db2b5..a3ee5d3 100644 --- a/c_compiler/src/declaration.cpp +++ b/c_compiler/src/declaration.cpp @@ -179,7 +179,7 @@ VariableStackBindings ArrayDeclaration::localAsm(VariableStackBindings bindings, { int initializer_count = itr-initializer_vector.rbegin(); (*itr)->printAsm(bindings, label_count); - type_->store(stack_position+4*initializer_count); + type_->store(stack_position+type_->getSize()*initializer_count); } } diff --git a/c_compiler/src/expression.cpp b/c_compiler/src/expression.cpp index a323153..466d8f7 100644 --- a/c_compiler/src/expression.cpp +++ b/c_compiler/src/expression.cpp @@ -138,7 +138,12 @@ VariableStackBindings PostfixArrayElement::printAsm(VariableStackBindings bindin { stackPosition(bindings, label_count); TypePtr type_ptr = postfix_expression_->getType(bindings); - type_ptr->load(); + std::shared_ptr<Pointer> pointer_type_ptr; + pointer_type_ptr = std::dynamic_pointer_cast<Pointer>(type_ptr); + if(pointer_type_ptr != nullptr) + pointer_type_ptr->pointerLoad(); + else + type_ptr->load(); printf("\tsw\t$2,%d($fp)\n", bindings.currentExpressionStackPosition()); return bindings; } |