本文整理汇总了Python中node.Node.mem方法的典型用法代码示例。如果您正苦于以下问题:Python Node.mem方法的具体用法?Python Node.mem怎么用?Python Node.mem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类node.Node
的用法示例。
在下文中一共展示了Node.mem方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: p_vaciaList
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_vaciaList(p):
'vaciaList : ID idCheck_Add POINT VACIA LPAR RPAR'
global pila_Oz
global temp_cont
global mem_temp
global list_temp
#TEMP de lenght
largo = Node()
nombreL = "t" + str(temp_cont)
largo.name = nombreL
largo.mem = mem_temp
aux = pila_Oz.pop()
largo.value = len(aux.lista)
#pila_Oz.append(largo)
list_temp.append(largo)
temp_cont += 1
mem_temp += 1
#Si la lista esta vacia -> PASA
if not aux.lista:
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
temp.value = False
else:
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
temp.value = True
cte_memoryAssign(0)
ctememory = cte_list[0]
createCuad('LEN', aux.mem, None, nombreL)
createCuad('>', nombreL, ctememory, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
示例2: p_call
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_call(p):
'''call : ID id_call LPAR par_call RPAR par_call2
| ID id_call LPAR par_call params RPAR par_call2
'''
global pila_Oz
global cont
global param_cont
global temp_cont
global mem_temp
global list_temp
#Check for ")"
item = pila_Oz.pop()
if item == ")":
#Take elements out of stack until no params
while item != "(":
item = pila_Oz.pop()
if item != "(":
param = "param" + str(param_cont)
#IF ID
if isinstance(item, str):
var = variableFetch(item)
if isinstance(var, Node):
op1 = var.mem
#IF TMP
elif isinstance(item, Node):
op1 = item.name
#IF CTE
else:
cte_memoryAssign(item)
item = cte_list[item]
op1 = item
#PARAMS
cuadruplo_temp = Cuadruplo()
cuadruplo_temp.set_cont(cont)
cuadruplo_temp.set_operator("param")
cuadruplo_temp.set_operand1(op1)
cuadruplo_temp.set_result(param)
cuadruplos_list.append(cuadruplo_temp)
cont += 1
param_cont += 1
#POPS name
subname = pila_Oz.pop()
#GO SUB
createCuad("goSub", subname, None, None)
#TEMPORAL output
func = functionFetch(subname)
if func.ret:
temp = Node()
tname = subname
temp.name = tname
temp.mem = mem_temp
temp.value = func.ret.value
list_temp.append(temp)
pila_Oz.append(temp)
temp_cont += 1
mem_temp += 1
param_cont = 0
示例3: p_varsGlobal
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_varsGlobal(p):
'''varsGlobal : type ID'''
global variables_globales
global var_list
global mem_int
global mem_float
global mem_boolean
global mem_global
if any(x.name == p[2] for x in variables_globales):
p[0] = {}
print "Existing variable VGlob", p[2]
else:
#print "Var declarada"
var = Node()
var.name = p[2]
var.type = p[1]
var.scope = "global"
if p[1] == "int":
var.mem = mem_int
#pila_Oz = mem_int
mem_int += 1
if p[1] == "float":
var.mem = mem_float
#pila_Oz = mem_float
mem_float += 1
if p[1] == "bool":
var.mem = mem_boolean
#pila_Oz = mem_boolean
mem_boolean += 1
variables_globales.append(var)
#var_list.append(var)
p[0] = var
示例4: p_vars
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_vars(p):
'''vars : type ID'''
global vartemp_list
global variables_globales
global funcName
#global pila_Oz
global mem_int
global mem_float
global mem_boolean
global mem_global
if any(x.name == p[2] for x in vartemp_list) or any(x.name == p[2] for x in variables_globales):
p[0] = {}
print "Existing variable Var", p[2]
else:
#print "Var declarada"
var = Node()
var.name = p[2]
var.type = p[1]
var.scope = funcName
if p[1] == "int":
var.mem = mem_int
#pila_Oz = mem_int
mem_int += 1
if p[1] == "float":
var.mem = mem_float
#pila_Oz = mem_float
mem_float += 1
if p[1] == "bool":
var.mem = mem_boolean
#pila_Oz = mem_boolean
mem_boolean += 1
#print var
vartemp_list.append(var)
paramtemp_list.append(var)
p[0] = var
示例5: p_remove
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_remove(p):
'''remove : ID idCheck_Remove POINT REMOVE LPAR RPAR '''
global cont
global cuadruplos_list
global temp_cont
global mem_temp
global pila_Oz
global list_temp
global temp
theList = pila_Oz.pop()
#print theList, "LA LISTA"
largo = len(theList.lista)
cuadruplo_temp = Cuadruplo()
if largo >= 0:
#catch = theList.lista.pop()
#Temporal
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
#temp.value = catch
pila_Oz.append(temp)
list_temp.append(temp)
#theList.lista.append(catch)
memory = theList.get_mem()
#Cuadruple creation
cuadruplo_temp.set_cont(cont)
cuadruplo_temp.set_operator("rm")
cuadruplo_temp.set_operand1(temp.name)
cuadruplo_temp.set_result(memory)
cuadruplos_list.append(cuadruplo_temp)
cont += 1
mem_temp += 1
temp_cont += 1
else:
cuadruplo_temp.set_cont(-1)
cuadruplo_temp.set_operator("EMPTY LIST")
cuadruplos_list.append(cuadruplo_temp)
print "Empty list"
p[0] = p[1]
示例6: p_termino
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_termino(p):
'''termino : factor
| factor MULTIPLY op_val termino
| factor DIVIDE op_val termino
'''
global cont
global pila_Operador
global pila_temp
global temp_cont
global mem_cte
global mem_temp
global cte_list
pos_ops = ['*', '/']
if pila_Operador and pila_Operador[-1] in pos_ops:
# print pila_Oz, "checa", pila_Operador
#print pila_Oz, "poz"
operator = pila_Operador.pop()
operand2 = pila_Oz.pop() #4
operand1 = pila_Oz.pop() #3
op1_name = ""
op2_name = ""
#****** VALUES *****
#IF CTE - MEMORY DIRECTIONS
if isinstance(operand2, Node) == False and verify(operand2) != "string":
op2_name = cte_list[operand2] #80808
if isinstance(operand1, Node) == False and verify(operand1) != "string":
op1_name = cte_list[operand1]
#IF ID
if verify(operand1) == "string":
varx = variableFetch(operand1)
operand1 = varx.value
op1_name = varx.mem
if verify(operand2) == "string":
vary = variableFetch(operand2)
operand2 = vary.value
op2_name = vary.mem
#IF TEMPORAL
if isinstance(operand1, Node):
op1_name = operand1.name
operand1 = operand1.value
if isinstance(operand2, Node):
op2_name = operand2.name
operand2 = operand2.value
term2 = verify(operand2) #int, float, str, bool
term1 = verify(operand1)
#print term1, term2, "CURE"
if semantic_cube[term1][term2][operator] != 'error':
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
if operator == "*":
total = operand1 * operand2
cte_memoryAssign(total)
temp.value = total
#SET CUADRUPLE -op, tmp, tmp, tmp
createCuad(operator, op1_name, op2_name, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
p[0] = p[1]
if operator == "/":
total = operand1 / operand2
cte_memoryAssign(total)
temp.value = total
#SET CUADRUPLE -op, tmp, tmp, tmp
createCuad(operator, op1_name, op2_name, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
p[0] = p[1]
else:
print "Semantic Error EXP"
p[0] = p[1]
示例7: p_exp
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_exp(p):
'''exp : termino
| termino PLUS op_val exp
| termino MINUS op_val exp
'''
global pila_Operador
global pila_temp
global temp_cont
global mem_cte
global mem_temp
global cte_list
global list_temp
pos_ops = ['+', '-']
if pila_Operador and pila_Operador[-1] in pos_ops:
operator = pila_Operador.pop()
operand2 = pila_Oz.pop() #4
operand1 = pila_Oz.pop() #3
op1_name = ""
op2_name = ""
#****** VALUES *****
#IF CTE - MEMORY DIRECTIONS
if isinstance(operand2, Node) == False and verify(operand2) != "string":
op2_name = cte_list[operand2] #80808
if isinstance(operand1, Node) == False and verify(operand1) != "string":
op1_name = cte_list[operand1]
#IF TEMPORAL
if isinstance(operand1, Node):
op1_name = operand1.name
operand1 = operand1.value
if isinstance(operand2, Node):
op2_name = operand2.name
operand2 = operand2.value
#IF ID
if verify(operand1) == "string":
varx = variableFetch(operand1)
operand1 = varx.value
op1_name = varx.mem
if verify(operand2) == "string":
vary = variableFetch(operand2)
operand2 = vary.value
op2_name = vary.mem
term2 = verify(operand2) #int, float, str, bool
term1 = verify(operand1)
if semantic_cube[term1][term2][operator] != 'error':
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
if operator == "+":
total = operand1 + operand2
cte_memoryAssign(total)
temp.value = total
#SET CUADRUPLE -op, tmp, tmp, tmp
createCuad(operator, op1_name, op2_name, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
p[0] = p[1]
if operator == "-":
total = operand1 - operand2
cte_memoryAssign(total)
temp.value = total
#SET CUADRUPLE -op, tmp, tmp, tmp
createCuad(operator, op1_name, op2_name, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
p[0] = p[1]
else:
print "Semantic Error EXP", pila_Oz
p[0] = p[1]
示例8: p_expression
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_expression(p):
'''expression : exp
| exp COMPARISON op_val expression
'''
global pila_Operador
global pila_temp
global temp_cont
global mem_cte
global mem_temp
global cte_list
global list_temp
pos_ops = ['>', '<', '>=', '<=', '==', '!=','&&', '||']
if pila_Operador and pila_Operador[-1] in pos_ops:
operator = pila_Operador.pop()
operand2 = pila_Oz.pop() #4
operand1 = pila_Oz.pop() #3
op1_name = ""
op2_name = ""
#****** VALUES *****
#IF CTE - MEMORY DIRECTIONS
if isinstance(operand2, Node) == False and verify(operand2) != "string":
op2_name = cte_list[operand2] #80808
if isinstance(operand1, Node) == False and verify(operand1) != "string":
op1_name = cte_list[operand1]
#IF ID
if verify(operand1) == "string":
varx = variableFetch(operand1)
operand1 = varx.value
op1_name = varx.mem
if verify(operand2) == "string":
vary = variableFetch(operand2)
operand2 = vary.value
op2_name = vary.mem
#IF TEMPORAL
if isinstance(operand1, Node):
op1_name = operand1.name
operand1 = operand1.value
if isinstance(operand2, Node):
op2_name = operand2.name
operand2 = operand2.value
term2 = verify(operand2) #int, float, str, bool
term1 = verify(operand1)
#print operand1, operand2, "EXP"
if semantic_cube[term1][term2][operator] != 'error':
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
if operator == "<":
total = operand1 < operand2
cte_memoryAssign(total)
temp.value = total
#SET CUADRUPLE -op, tmp, tmp, tmp
createCuad(operator, op1_name, op2_name, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
p[0] = p[1]
if operator == ">":
total = operand1 > operand2
cte_memoryAssign(total)
temp.value = total
#SET CUADRUPLE -op, tmp, tmp, tmp
createCuad(operator, op1_name, op2_name, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
p[0] = p[1]
if operator == "<=":
total = operand1 <= operand2
cte_memoryAssign(total)
temp.value = total
#SET CUADRUPLE -op, tmp, tmp, tmp
createCuad(operator, op1_name, op2_name, tname)
pila_Oz.append(temp)
list_temp.append(temp)
temp_cont += 1
mem_temp += 1
p[0] = p[1]
if operator == ">=":
total = operand1 >= operand2
cte_memoryAssign(total)
#.........这里部分代码省略.........
示例9: p_return
# 需要导入模块: from node import Node [as 别名]
# 或者: from node.Node import mem [as 别名]
def p_return(p):
'''return : RETURN LPAR par_call expression RPAR par_call2
| RETURN LPAR par_call call RPAR par_call2
'''
global pila_Oz
global funcName
global temp_cont
global mem_temp
global list_temp
print pila_Oz, "RETURN"
func_temp = functionFetch(funcName)
print pila_Oz, ""
#Check for ")"
item = pila_Oz.pop()
if item == ")":
#Take elements out of stack until no params
while item != "(":
item = pila_Oz.pop()
if item != "(":
#IF ID
if isinstance(item, str):
var = variableFetch(item)
if isinstance(var, Node):
op1 = var.mem
func_temp.ret = var
#IF TMP
elif isinstance(item, Node):
op1 = item.mem
#TEMP CUAD
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
list_temp.append(temp)
#Add as return
func_temp.ret = temp
#IF CTE
else:
cte_memoryAssign(item)
item = cte_list[item]
op1 = item
#TEMP CUAD
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
list_temp.append(temp)
#Add as return
func_temp.ret = temp
#RETURN CUAD
createCuad("RETURN", op1, None, None)
#TEMP CUAD
temp = Node()
tname = "t" + str(temp_cont)
temp.name = tname
temp.mem = mem_temp
#CHECAR*************** * * ** * *!!!!1
#pila_Oz.append(temp)
#list_temp.append(temp)
mem_temp += 1
temp_cont += 1