Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Parsing 在yacc/bison中传递多个属性_Parsing_Attributes_Bison_Yacc - Fatal编程技术网

Parsing 在yacc/bison中传递多个属性

Parsing 在yacc/bison中传递多个属性,parsing,attributes,bison,yacc,Parsing,Attributes,Bison,Yacc,为了处理语法规则: type : ARRAY '[' integer_constant RANGE integer_constant ']' OF stype { $$ = $8 } | stype { $$ = $1 } ; 我需要向上传递type属性(正如我现在所做的),但我还需要向上传递数组的范围,以便检查数组边界。 为了实现以下目标,我尝试了各种方法来使用struct: type

为了处理语法规则:

type            : ARRAY '[' integer_constant RANGE integer_constant ']' OF stype { $$ = $8 }
                | stype { $$ = $1 }
                ;
我需要向上传递type属性(正如我现在所做的),但我还需要向上传递数组的范围,以便检查数组边界。 为了实现以下目标,我尝试了各种方法来使用struct:

type            : ARRAY '[' integer_constant RANGE integer_constant ']' OF stype { $$.type = $8; $$.range[0] = $3; $$.range[1] = $5; }
                | stype { $$.type = $1 }
                ;
但是每件事都会导致错误,我很难找到正确的方法来处理这个问题

谁能给我指出正确的方向吗? 提前谢谢


parse.y:

类型
stype
被声明为联合体的
attr
成员,该联合体的类型为
节点*
。因此,在这些非终端的操作上下文中,
$$
将被类似于
x.attr
的内容所取代(这只是一个示例,不要太直截了当)。类似地,在第一个操作中,
$8
将被替换为类似于
yystack[top-8].attr的内容,因为$8还有标签
attr
,是一个
stype

因此,
$$。type
(或者实际上,
$$。
)必须是语法错误
attr
是一个指针,因此它可能是
$$->
正确的,但是如果没有看到
节点的定义,我就无法判断

另外,在
stype
规则中,您设置了,例如,
$$=“INT”
,但是
$$
类型是
节点*
,而不是
字符*
(当然,除非
节点
字符
的typedef,但这似乎是错误的。)似乎最终会导致segfault,稍后将该值视为指向
节点的指针时


我真的不清楚你认为的
$$范围可能是什么意思。也许您需要显示更多的标题。

除了rici的答案和更直接地回答标题中的问题外,多个属性通常通过
结构传递,因此如果您将与
类型
非终端相关的值更改为例如
ctype
%type类型
)和
stype
type
%type stype
)(我认为这是您的意图),然后将以下内容添加到您的
%union

struct { int is_array, low, high; char * type; } ctype;
然后,您可以将
类型的定义更改为

type
:    ARRAY '[' integer_constant RANGE integer_constant ']' OF stype
     { $$.is_array = 1; $$.low = $3; $$.high = $5; $$.type = $8; }
|    stype
     { $$.is_array = 0; $$.low = $$.high = -1; $$.type = $1; }
;
当然,为了正确处理新的
ctype
,还需要进行更多的更改,但这通常是将多个属性向上传播到解析器堆栈的方法