diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-17 22:38:08 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-17 22:38:08 +0000 |
commit | a9663b327230e08a6bc5cfe4f20ed8d066f33338 (patch) | |
tree | 4a47654b4fd29300ebee876fa1d9f79dac52499f /c_compiler/src/c_parser.y | |
parent | f35548ee7d4c54558c38d63df7e2572150c28d22 (diff) | |
download | Compiler-a9663b327230e08a6bc5cfe4f20ed8d066f33338.tar.gz Compiler-a9663b327230e08a6bc5cfe4f20ed8d066f33338.zip |
Creating if statement
Diffstat (limited to 'c_compiler/src/c_parser.y')
-rw-r--r-- | c_compiler/src/c_parser.y | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/c_compiler/src/c_parser.y b/c_compiler/src/c_parser.y index 7846e5d..721a6e3 100644 --- a/c_compiler/src/c_parser.y +++ b/c_compiler/src/c_parser.y @@ -69,7 +69,8 @@ void yyerror(const char *); %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 - T_MULT T_DIV T_REM T_EQUALITY_OP MultDivRemOP UnaryOperator DeclarationSpec + T_MULT T_DIV T_REM T_EQUALITY_OP T_REL_OP T_SHIFT_OP MultDivRemOP UnaryOperator + DeclarationSpec %start ROOT @@ -198,8 +199,8 @@ CompoundStatement_2: ; SelectionStatement: - T_IF T_LRB Expression T_RRB Statement { $$ = new SelectionStatement($5); } - | T_IF T_LRB Expression T_RRB Statement T_ELSE Statement { $$ = new SelectionStatement($5, $7); } + T_IF T_LRB Expression T_RRB Statement { $$ = new SelectionStatement($3, $5); } + | T_IF T_LRB Expression T_RRB Statement T_ELSE Statement { $$ = new SelectionStatement($3, $5, $7); } ; ExpressionStatement: @@ -268,12 +269,14 @@ EqualityExpression: RelationalExpression: ShiftExpression { $$ = $1; } - | RelationalExpression T_REL_OP ShiftExpression { $$ = new RelationalExpression($1, $3); } + | RelationalExpression T_REL_OP ShiftExpression + { $$ = new RelationalExpression($1, *$2, $3); delete $2; } ; ShiftExpression: AdditiveExpression { $$ = $1; } - | ShiftExpression T_SHIFT_OP AdditiveExpression { $$ = new ShiftExpression($1, $3); } + | ShiftExpression T_SHIFT_OP AdditiveExpression + { $$ = new ShiftExpression($1, *$2, $3); } ; AdditiveExpression: |