Skip to content

Instantly share code, notes, and snippets.

@siscia
Created February 16, 2017 18:29
Show Gist options
  • Save siscia/86c776015326eb2deff2270258abdf76 to your computer and use it in GitHub Desktop.
Save siscia/86c776015326eb2deff2270258abdf76 to your computer and use it in GitHub Desktop.
| exp IF exp ELSE exp {
if ($3.expression_type == IMMEDIATE){
if ($3.value) {
$$ = $1;
} else {
$$ = $5;
}
} else {
t_axe_label* exit = newLabel(program);
t_axe_label* else_branch = newLabel(program);
gen_andb_instruction(program, $3.value, $3.value, $3.value, CG_DIRECT_ALL);
gen_beq_instruction(program, else_branch, 0);
$$ = $1;
gen_bt_instruction(program, exit, 0);
assignLabel(program, else_branch);
$$ = $5;
assignLabel(program, exit);
}
}
int b;
int a = 33;
int c = 44;
b = 3 if a > 0 else 0;
write(b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment