我正在尝试制作一个可以处理if else语句的解析器。我目前为我的bison.y文件编写了以下代码:
ifstate: IF_TOKEN LPARENT compare RPARENT statement ENDIF_TOKEN
| IF_TOKEN LPARENT compare RPARENT statement else
;
else: ELSE_TOKEN statement ENDIF_TOKEN
| ELSEIF_TOKEN LPARENT compare RPARENT statement ENDIF_TOKEN
| ELSEIF_TOKEN LPARENT compare RPARENT statement else
;这里我比较了返回true或false字符串。and语句是任何语句(从赋值到更多的if语句)。然而,当if为真时,我不知道如何只做语句。
发布于 2015-12-07 09:28:00
if语句被编译成如下形式的伪代码:
; set up the condition
TEST
BRANCH FALSE $1
; body of 'if' statement
$1: ; next statement一条if/else语句:
; set up the condition
TEST
BRANCH FALSE $1
; body of 'if' statement
BRANCH $2
$1: ; // body of 'else' statement
$2: ; next statementhttps://stackoverflow.com/questions/34124771
复制相似问题