Skip to content

Commit

Permalink
Fix if statement parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Eli Skeggs <skeggse@gmail.com>
  • Loading branch information
skeggse committed Nov 19, 2015
1 parent 35161c4 commit 2e8eb9f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion parse.c
Expand Up @@ -607,6 +607,7 @@ expression *parse_operation_expression(parse_state *state) {
return NULL;
}

// TODO: precedence and associativity of '=' and '?:' incorrect
for (;;) {
const token *t = parse_peek(state);

Expand Down Expand Up @@ -998,13 +999,28 @@ statement *parse_statement(parse_state *state) {
statement *first = expect_statement(state), *second = consume(state, L_ELSE)
? expect_statement(state) : NULL;

result = s_if(condition, ensure_block(first), ensure_block(second));
result = s_if(condition, NULL, NULL);

if (first) {
if (first->type != S_BLOCK) {
first = s_block(first);
((block_statement*) first)->body->parent = first;
}

first->parent = result;
((if_statement*) result)->first = (block_statement*) first;
}

if (second) {
if (second->type != S_BLOCK) {
second = s_block(second);
((block_statement*) second)->body->parent = second;
}

second->parent = result;
((if_statement*) result)->second = (block_statement*) second;
}

return result;
}
case L_LET: {
Expand Down

0 comments on commit 2e8eb9f

Please sign in to comment.