📜  门| GATE CS 2019 |简体中文第45章

📅  最后修改于: 2021-06-28 21:07:17             🧑  作者: Mango

考虑以下语法和语义操作,以支持继承的类型声明属性。令X 1 ,X 2 ,X 3 ,X 4 ,X 5和X 6为下表中非端子D,T,L或L 1的占位符: Which one of the following are the appropriate choices for X 1 , X 2 , X 3 and X 4 ?

(A) X 1 = L,X 2 = T,X 3 = L 1 ,X 4 = L
(B) X 1 = L,X 2 = L,X 3 = L 1 ,X 4 = T
(C) X 1 = T,X 2 = L,X 3 = L 1 ,X 4 = T
(D) X 1 = T,X 2 = L,X 3 = T,X 4 = L 1答案: (A)
说明:根据继承的属性定义,如果从其父级和同级的属性值确定解析树节点的属性值,则该属性将被继承。

因此,语义规则应如下所示:

D → TL {L.idtype = T.stype}
T → int {T.stype = int}
T → float {T.stype = float}
L → L1, id {L1.itype = L.itype}
           addtype(id.entry, L.itype)
L → id addtype(id.entry, L.itype) 

选项(A)是正确的。
这个问题的测验