implemented if statement parsing
This commit is contained in:
parent
d6d2230f14
commit
c34bea6fff
3 changed files with 19 additions and 4 deletions
4
lc.c
4
lc.c
|
|
@ -151,7 +151,9 @@ void print_ast(ast_node *node, int depth) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NODE_IF:
|
case NODE_IF:
|
||||||
printf("IfStmt (Fields missing in struct)\n");
|
printf("If:\n");
|
||||||
|
print_ast(node->expr.whle.condition, depth + 1);
|
||||||
|
print_ast(node->expr.whle.body, depth + 1);
|
||||||
break;
|
break;
|
||||||
case NODE_VAR_DECL:
|
case NODE_VAR_DECL:
|
||||||
printf("VarDecl: %.*s: %.*s\n", (int)node->expr.var_decl.name_len, node->expr.var_decl.name, (int)node->expr.var_decl.type_len, node->expr.var_decl.type);
|
printf("VarDecl: %.*s: %.*s\n", (int)node->expr.var_decl.name_len, node->expr.var_decl.name, (int)node->expr.var_decl.type_len, node->expr.var_decl.type);
|
||||||
|
|
|
||||||
14
parser.c
14
parser.c
|
|
@ -676,6 +676,17 @@ static ast_node *parse_while(parser *p)
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ast_node *parse_if(parser *p)
|
||||||
|
{
|
||||||
|
ast_node *condition = parse_expression(p);
|
||||||
|
ast_node *body = parse_compound(p);
|
||||||
|
ast_node *node = arena_alloc(p->allocator, sizeof(ast_node));
|
||||||
|
node->type = NODE_IF;
|
||||||
|
node->expr.whle.body = body;
|
||||||
|
node->expr.whle.condition = condition;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
static ast_node *parse_struct(parser *p);
|
static ast_node *parse_struct(parser *p);
|
||||||
static member *parse_member(parser *p)
|
static member *parse_member(parser *p)
|
||||||
{
|
{
|
||||||
|
|
@ -874,6 +885,9 @@ static ast_node *parse_statement(parser *p)
|
||||||
return parse_while(p);
|
return parse_while(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (match(p, TOKEN_IF)) {
|
||||||
|
return parse_if(p);
|
||||||
|
}
|
||||||
else if (match_peek(p, TOKEN_IDENTIFIER) && p->tokens->next && p->tokens->next->type == TOKEN_IDENTIFIER)
|
else if (match_peek(p, TOKEN_IDENTIFIER) && p->tokens->next && p->tokens->next->type == TOKEN_IDENTIFIER)
|
||||||
{
|
{
|
||||||
/* Variable declaration. */
|
/* Variable declaration. */
|
||||||
|
|
|
||||||
5
test.c
5
test.c
|
|
@ -1,4 +1,3 @@
|
||||||
struct {
|
if a == x {
|
||||||
union { u32 x, u32 y } a,
|
printf("hello");
|
||||||
u32 b,
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue