aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/src/c_parser.y
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-03-22 16:53:48 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-03-22 16:53:48 +0000
commit561b76bdebd584d03d4e451375777651a9d74017 (patch)
treefdab95e056a212a26b65a96ae2af894e8f42b82e /c_compiler/src/c_parser.y
parentf12ccd62ecf08774ce599a2e15d9042500d2760a (diff)
downloadCompiler-561b76bdebd584d03d4e451375777651a9d74017.tar.gz
Compiler-561b76bdebd584d03d4e451375777651a9d74017.zip
Have to work on case
Diffstat (limited to 'c_compiler/src/c_parser.y')
-rw-r--r--c_compiler/src/c_parser.y53
1 files changed, 50 insertions, 3 deletions
diff --git a/c_compiler/src/c_parser.y b/c_compiler/src/c_parser.y
index c58bc75..79d8902 100644
--- a/c_compiler/src/c_parser.y
+++ b/c_compiler/src/c_parser.y
@@ -71,7 +71,7 @@ void yyerror(const char *);
AndExpression EqualityExpression RelationalExpression ShiftExpression
AdditiveExpression MultiplicativeExpression CastExpression UnaryExpression
PostfixExpression PostfixExpression2 ArgumentExpressionList PrimaryExpression
- Constant
+ Constant Initializer InitializerList
%type <type> DeclarationSpecifierList
@@ -174,7 +174,7 @@ InitDeclaratorList:
;
InitDeclarator: Declarator { $$ = $1; }
- | Declarator T_EQ AssignmentExpression { $$->setInitializer($3); delete $2; }
+ | Declarator T_EQ Initializer { $$ = $1; $$->setInitializer($3); delete $2; }
;
Declarator: DirectDeclarator { $$ = $1; }
@@ -194,6 +194,15 @@ DirectDeclarator:
IdentifierList: T_IDENTIFIER { $$ = new Declaration(); }
| IdentifierList T_CMA T_IDENTIFIER { $$ = new Declaration(); }
+Initializer: AssignmentExpression { $$ = $1; }
+ | T_LCB InitializerList T_RCB { $$ = $2; }
+ | T_LCB InitializerList T_CMA T_RCB { $$ = $2; }
+ ;
+
+InitializerList:
+ Initializer { $$ = $1; }
+ | InitializerList T_CMA Initializer { $3->linkExpression($$); $$ = $3; }
+
// Statement
StatementList:
@@ -250,7 +259,45 @@ Expression: AssignmentExpression { $$ = $1; }
AssignmentExpression:
ConditionalExpression { $$ = $1; }
- | UnaryExpression ASSIGN_OPER AssignmentExpression { $$ = new AssignmentExpression($1, $3); delete $2; }
+ | UnaryExpression ASSIGN_OPER AssignmentExpression
+ {
+ Expression* tmp;
+ if(*$2 == "=") {
+ $$ = new AssignmentExpression($1, $3);
+ } else if(*$2 == "+=") {
+ tmp = new AdditiveExpression($1, "+", $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "-=") {
+ tmp = new AdditiveExpression($1, "-", $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "*=") {
+ tmp = new MultiplicativeExpression($1, "*", $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "/=") {
+ tmp = new MultiplicativeExpression($1, "/", $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "%=") {
+ tmp = new MultiplicativeExpression($1, "%", $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "&=") {
+ tmp = new AndExpression($1, $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "^=") {
+ tmp = new ExclusiveOrExpression($1, $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "|=") {
+ tmp = new InclusiveOrExpression($1, $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else if(*$2 == "<<=") {
+ tmp = new ShiftExpression($1, "<<", $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ } else {
+ tmp = new ShiftExpression($1, ">>", $3);
+ $$ = new AssignmentExpression(tmp->getLhs(), tmp);
+ }
+
+ delete $2;
+ }
;
ASSIGN_OPER: T_ASSIGN_OPER { ; }