From fc6c46c8b8d9aabd8b0f3a0ca6bf56a514500751 Mon Sep 17 00:00:00 2001 From: Riley Smith Date: Thu, 14 Nov 2024 11:12:37 -0800 Subject: [PATCH] mathematical expression --- lab-5/expr.c | 1 + lab-5/parser.bison | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lab-5/expr.c b/lab-5/expr.c index c9c1733..1c690b0 100644 --- a/lab-5/expr.c +++ b/lab-5/expr.c @@ -149,6 +149,7 @@ void stmt_print(struct stmt *s) { break; // we haven't implemented sections yet case STMT_SECTION: + printf("section\n"); break; } diff --git a/lab-5/parser.bison b/lab-5/parser.bison index 3b76da2..5830e55 100644 --- a/lab-5/parser.bison +++ b/lab-5/parser.bison @@ -145,14 +145,20 @@ term : mathmaticalexpr {$$ = $1;} ; math_op : TOKEN_ADD + {$$ = expr_create(EXPR_ADD, NULL, NULL);} | TOKEN_SUB + {$$ = expr_create(EXPR_SUBTRACT, NULL, NULL);} | TOKEN_MULTIPLY + {$$ = expr_create(EXPR_MULTIPLY, NULL, NULL);} | TOKEN_DIVIDE + {$$ = expr_create(EXPR_DIVIDE, NULL, NULL);} | TOKEN_EXPONENTIAL + {$$ = expr_create(EXPR_EXPONENTIAL, NULL, NULL);} ; mathmaticalexpr : type_expr {$$ = $1;} | mathmaticalexpr math_op term + {$$ = expr_create($2->kind, $1, $3);} | container_expr {$$ = $1;} | type_expr container_expr @@ -161,8 +167,11 @@ mathmaticalexpr : type_expr container_expr : TOKEN_LEFT_PARENTHESIS mathmaticalexpr TOKEN_RIGHT_PARENTHESIS ; booleanexpr : mathmaticalexpr TOKEN_LESS_THAN term + {$$ = expr_create(EXPR_LESS_THAN, $1, $3);} | mathmaticalexpr TOKEN_GREATER_THAN term + {$$ = expr_create(EXPR_GREATER_THAN, $1, $3);} | mathmaticalexpr TOKEN_EQUAL term + {$$ = expr_create(EXPR_EQUAL, $1, $3);} ; type_expr : TOKEN_IDENT {$$ = expr_create_name(yytext);}