📅  最后修改于: 2020-12-06 07:31:16             🧑  作者: Mango
如果将元素存储在连续位置的块中,则可以快速访问数组的元素。数组可以是一维或二维的。
A: array[low..high] of the ith elements is at:
base + (i-low)*width → i*width + (base - low*width)
行专业或列专业表格
Limit(array,j)返回nj = highj-lowj + 1
地点:临时变量
offset:与基准的偏移量,如果不是数组引用,则为null
生产:
S → L := E
E → E+E
E → (E)
E → L
L → Elist ]
L → id
Elist → Elist, E
Elist → id[E
数组元素的合适过渡方案是:
Production Rule | Semantic Action |
---|---|
S → L := E | {if L.offset = null then emit(L.place ‘:=’ E.place) else EMIT (L.place'[‘L.offset ‘]’ ‘:=’ E.place); } |
E → E+E | {E.place := newtemp; EMIT (E.place ‘:=’ E1.place ‘+’ E2.place); } |
E → (E) | {E.place := E1.place;} |
E → L | {if L.offset = null then E.place = L.place else {E.place = newtemp; EMIT (E.place ‘:=’ L.place ‘[‘ L.offset ‘]’); } } |
L → Elist ] | {L.place = newtemp; L.offset = newtemp; EMIT (L.place ‘:=’ c(Elist.array)); EMIT (L.offset ‘:=’ Elist.place ‘*’ width(Elist.array); } |
L → id | {L.place = lookup(id.name); L.offset = null; } |
Elist → Elist, E | {t := newtemp; m := Elist1.ndim + 1; EMIT (t ‘:=’ Elist1.place ‘*’ limit(Elist1.array, m)); EMIT (t, ‘:=’ t ‘+’ E.place); Elist.array = Elist1.array; Elist.place := t; Elist.ndim := m; } |
Elist → id[E | {Elist.array := lookup(id.name); Elist.place := E.place Elist.ndim := 1; } |
ndim表示维数。
limit(array,i)函数返回上限以及数组的维数
width(array)返回数组一个元素的字节数。