mathematical expression
This commit is contained in:
parent
2855f404a3
commit
fc6c46c8b8
|
|
@ -149,6 +149,7 @@ void stmt_print(struct stmt *s) {
|
||||||
break;
|
break;
|
||||||
// we haven't implemented sections yet
|
// we haven't implemented sections yet
|
||||||
case STMT_SECTION:
|
case STMT_SECTION:
|
||||||
|
printf("section\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,14 +145,20 @@ term : mathmaticalexpr
|
||||||
{$$ = $1;}
|
{$$ = $1;}
|
||||||
;
|
;
|
||||||
math_op : TOKEN_ADD
|
math_op : TOKEN_ADD
|
||||||
|
{$$ = expr_create(EXPR_ADD, NULL, NULL);}
|
||||||
| TOKEN_SUB
|
| TOKEN_SUB
|
||||||
|
{$$ = expr_create(EXPR_SUBTRACT, NULL, NULL);}
|
||||||
| TOKEN_MULTIPLY
|
| TOKEN_MULTIPLY
|
||||||
|
{$$ = expr_create(EXPR_MULTIPLY, NULL, NULL);}
|
||||||
| TOKEN_DIVIDE
|
| TOKEN_DIVIDE
|
||||||
|
{$$ = expr_create(EXPR_DIVIDE, NULL, NULL);}
|
||||||
| TOKEN_EXPONENTIAL
|
| TOKEN_EXPONENTIAL
|
||||||
|
{$$ = expr_create(EXPR_EXPONENTIAL, NULL, NULL);}
|
||||||
;
|
;
|
||||||
mathmaticalexpr : type_expr
|
mathmaticalexpr : type_expr
|
||||||
{$$ = $1;}
|
{$$ = $1;}
|
||||||
| mathmaticalexpr math_op term
|
| mathmaticalexpr math_op term
|
||||||
|
{$$ = expr_create($2->kind, $1, $3);}
|
||||||
| container_expr
|
| container_expr
|
||||||
{$$ = $1;}
|
{$$ = $1;}
|
||||||
| type_expr container_expr
|
| type_expr container_expr
|
||||||
|
|
@ -161,8 +167,11 @@ mathmaticalexpr : type_expr
|
||||||
container_expr : TOKEN_LEFT_PARENTHESIS mathmaticalexpr TOKEN_RIGHT_PARENTHESIS
|
container_expr : TOKEN_LEFT_PARENTHESIS mathmaticalexpr TOKEN_RIGHT_PARENTHESIS
|
||||||
;
|
;
|
||||||
booleanexpr : mathmaticalexpr TOKEN_LESS_THAN term
|
booleanexpr : mathmaticalexpr TOKEN_LESS_THAN term
|
||||||
|
{$$ = expr_create(EXPR_LESS_THAN, $1, $3);}
|
||||||
| mathmaticalexpr TOKEN_GREATER_THAN term
|
| mathmaticalexpr TOKEN_GREATER_THAN term
|
||||||
|
{$$ = expr_create(EXPR_GREATER_THAN, $1, $3);}
|
||||||
| mathmaticalexpr TOKEN_EQUAL term
|
| mathmaticalexpr TOKEN_EQUAL term
|
||||||
|
{$$ = expr_create(EXPR_EQUAL, $1, $3);}
|
||||||
;
|
;
|
||||||
type_expr : TOKEN_IDENT
|
type_expr : TOKEN_IDENT
|
||||||
{$$ = expr_create_name(yytext);}
|
{$$ = expr_create_name(yytext);}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue