aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/src/c_parser.y
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-03-16 21:24:02 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-03-16 21:24:02 +0000
commit4858aa179ddc6044c55c8ae8708a76af3e287b05 (patch)
treef9bcc54ed13720c8a74a5dd726ecfdea083a7e28 /c_compiler/src/c_parser.y
parentf7b531ebaaa784a0dcebb877ec7b831b324f3510 (diff)
downloadCompiler-4858aa179ddc6044c55c8ae8708a76af3e287b05.tar.gz
Compiler-4858aa179ddc6044c55c8ae8708a76af3e287b05.zip
function calls now work completely
Diffstat (limited to 'c_compiler/src/c_parser.y')
-rw-r--r--c_compiler/src/c_parser.y25
1 files changed, 10 insertions, 15 deletions
diff --git a/c_compiler/src/c_parser.y b/c_compiler/src/c_parser.y
index 4a9f929..1ee7966 100644
--- a/c_compiler/src/c_parser.y
+++ b/c_compiler/src/c_parser.y
@@ -57,6 +57,7 @@ void yyerror(const char *);
%type <declaration> ParameterList Parameter DeclarationList Declaration InitDeclaratorList
InitDeclarator
IdentifierList
+ Declarator DirectDeclarator
%type <expression> Expression AssignmentExpression ConditionalExpression LogicalOrExpression
LogicalAndExpression InclusiveOrExpression ExclusiveOrExpression
@@ -67,8 +68,6 @@ void yyerror(const char *);
%type <type> DeclarationSpec
-%type <string> Declarator DirectDeclarator
-
%type <number> T_INT_CONST
%type <string> T_IDENTIFIER ASSIGN_OPER T_ASSIGN_OPER T_EQ T_AND T_ADDSUB_OP T_TILDE T_NOT
@@ -97,19 +96,14 @@ ExternalDeclaration:
// FUNCTION DEFINITION
FunctionDefinition:
- DeclarationSpec T_IDENTIFIER T_LRB ParameterList T_RRB CompoundStatement {
- if($4->getId() == "")
- $$ = new Function(*$2, $6);
- else
- $$ = new Function(*$2, $6, $4);
- delete $2;
- }
+ DeclarationSpec Declarator CompoundStatement {
+ $$ = new Function($2->getId(), $3, $2->getNext()); }
;
ParameterList:
%empty { $$ = new Declaration(); }
| Parameter { $$ = $1; }
- | ParameterList T_CMA Parameter { $3->linkDeclaration($$); $$ = $3;}
+ | ParameterList T_CMA Parameter { $3->linkDeclaration($$); $$ = $3; }
;
Parameter: DeclarationSpec T_IDENTIFIER { $$ = new Declaration(*$2); delete $2; }
@@ -146,12 +140,12 @@ DeclarationSpec:
;
InitDeclaratorList:
- InitDeclarator { $$ = new Declaration(*$1); delete $1;}
+ InitDeclarator { $$ = $1; }
| InitDeclaratorList T_CMA InitDeclarator { $3->linkListDeclaration($$); $$ = $3; }
;
-InitDeclarator: Declarator { $$ = new Declaration(*$1); delete $1; }
- | Declarator T_EQ AssignmentExpression { $$ = new Declaration(*$1, $3); delete $1; }
+InitDeclarator: Declarator { $$ = $1; }
+ | Declarator T_EQ AssignmentExpression { $$->setInitializer($3); }
;
Declarator: DirectDeclarator { $$ = $1; }
@@ -159,11 +153,12 @@ Declarator: DirectDeclarator { $$ = $1; }
;
DirectDeclarator:
- T_IDENTIFIER { $$ = $1; }
+ T_IDENTIFIER { $$ = new Declaration(*$1); delete $1; }
| T_LRB Declarator T_RRB { $$ = $2; }
| DirectDeclarator T_LSB ConditionalExpression T_RSB { $$ = $1; }
| DirectDeclarator T_LSB T_RSB { $$ = $1; }
- | DirectDeclarator T_LRB ParameterList T_RRB { $$ = $1; }
+ | DirectDeclarator T_LRB T_RRB { $$ = $1; }
+ | DirectDeclarator T_LRB ParameterList T_RRB { $1->linkDeclaration($3); $$ = $1; }
| DirectDeclarator T_LRB IdentifierList T_RRB { $$ = $1; }
;