0
def interpretDTREE(d) :
"""pre: d is a declaration represented as a DTREE:
DTREE ::= ["int", ID, ETREE]
post: heap is updated with d
"""
operator = d[0]
if operator == "int" : # declaration ["int", ID, ETREE]
id = d[1]
typeID = ["int", id]
etree = d[2]
rval = interpretETREE(etree)
declare (activeNS(), typeID, rval)
else : # error
crash("invalid DTREE")
加入typeID = ["int", id]
後,我得到的錯誤我應該在堆結構中保存「int」類型?
TypeError: unhashable type: 'list'
堆結構:
heap : { (HANDLE : NAMESPACE)+ }
其中HANDLE
=一個字符串,如'h1'
和NAMESPACE
=該變種名稱映射到詞典整理或處理。還包含更多全球變量的「父母」鏈接。
爲什麼我想在typeID中添加「int」? 因爲我想聲明變量類型爲「int」,但是,我不知道應該在堆中存儲「int」。
目前尚不清楚這些應該做什麼或者你的數據結構應該是什麼樣子。你在執行口譯員嗎?聽起來這個問題需要你的程序的其他部分有如此多的背景,以至於你是唯一有足夠信息來回答它的人。 – user2357112 2014-09-20 21:57:13