我正在编写一个编译器,并且我有用于处理无限嵌套 if 语句的工作代码,但这有点像 hack。我不知道这样做是否安全?
con_statement:
IF exp DO
{
$1 = ifNum++;
if($2 == BOOLEAN_TYPE || $2 == INTEGER_TYPE)
{
utstring_printf(code, "\tpop\teax\n");
utstring_printf(code, "\tcmp\teax, 0\n");
utstring_printf(code, "\tje\tIF_END_%d\n", $1);
}
if($2 == FLOAT_TYPE)
{
utstring_printf(code, "\tnop\n");
}
}
program FI
{
utstring_printf(code, "IF_END_%d:\n", $1);
}
;