Skip to content

Commit

Permalink
Fix bug of calc expr with + - * /
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Jun 13, 2021
1 parent 234229b commit 4c07353
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions input.one
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ fn test {
_ 1
_ 2, 4, 6, 8
_ 5+8
_ (2 + 15 * ( 25 - 13 ) / 1 - 4) + 10 / 2
}
/*
fn main {
Expand Down
2 changes: 1 addition & 1 deletion src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ AstExpression *parser_parse_expression_term()
{
TokenType op = PARSER_CURRENT->type;
parser_next();
expr = ast_make_expression_2(op, -1, expr, parser_parse_expression_term());
expr = ast_make_expression_2(op, -1, expr, parser_parse_expression_factor());
}
return expr;
}
Expand Down
20 changes: 13 additions & 7 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,31 +157,37 @@ void tree_show_statement_expression(FILE* f, AstStatement* stmt)

void tree_show_expression(FILE* f, AstExpression* expr)
{
tree_show_ident();
if(expr->operator == TOKEN_OPERATOR_NONE) {
if (expr->operator== TOKEN_OPERATOR_NONE)
{
tree_show_ident();
print_tree(f, BOLDBLUE TREE_PREFIX "Expression Direct: %s\n" RESET, expr->vstring == NULL ? "" : expr->vstring);
// tree_show_ident();
// print_tree(f, BOLDBLUE TREE_PREFIX "Expression Direct: %d\n" RESET, expr->vint);
}
else {
else
{
tree_show_ident();
print_tree(f, BOLDBLUE TREE_PREFIX "Expression %s\n" RESET, token_name(expr->operator));

ident++;
if(expr->left != NULL) {
if (expr->left != NULL)
{
tree_show_ident();
print_tree(f, BOLDBLUE TREE_PREFIX "Expression Left\n" RESET);
ident++;
tree_show_expression(f, expr->left);
ident--;
}
if(expr->right != NULL) {
if (expr->right != NULL)
{
tree_show_ident();
print_tree(f, BOLDBLUE TREE_PREFIX "Expression Right\n" RESET );
print_tree(f, BOLDBLUE TREE_PREFIX "Expression Right\n" RESET);
ident++;
tree_show_expression(f, expr->right);
ident--;
}
ident--;
}

}

void tree_show_expressions(FILE* f, AstExpressions exprs)
Expand Down

0 comments on commit 4c07353

Please sign in to comment.