确定下列声明序列中各个标识符的类型和相对地址。
float x; record {float x; float y;} p; record {int tag; float x; float y;} q;
SDT
S -> {top = new Evn(); offset = 0;} D D -> T id; {top.put(id.lexeme, T.type, offset); offset += T.width} D1 D -> ε T -> int {T.type = interget; T.width = 4;} T -> float {T.type = float; T.width = 8;} T -> record '{' {Evn.push(top), top = new Evn(); Stack.push(offset), offset = 0;} D '}' {T.type = record(top); T.width = offset; top = Evn.top(); offset = Stack.pop();}
标识符类型和相对地址
line id type offset Evn 1) x float 0 1 2) x float 0 2 2) y float 8 2 2) p record() 8 1 3) tag int 0 3 3) x float 4 3 3) y float 12 3 3) q record() 24 1
将图 6-18 对字段名的处理方法扩展到类和单继承的层次结构。
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8