【发布时间】:2023-08-17 21:52:01
【问题描述】:
我的bison语法的一部分如图
head: OPEN statement CLOSE
{
$$=$2;
}
;
statement: word
{
$$=$1;
}
| statement word
{
$$=$1;
printf("%s",$$);
}
;
现在,如果我的输入是 [hai hello] 其中 [ 是 OPEN & ] 分别是 CLOSE,那么在 printf 语句中我得到的输出是“hai hello”本身..但是在 $$ 的 head 我得到“喂喂]”。其他语法也会发生同样的情况。即,如果我尝试打印 $1 的值,也会打印 $2,$3,... 的值。为什么会这样。
【问题讨论】:
标签: return-value bison semantics