Ejemplo n.º 1
0
def p_assignment_leftpointer(p):
	"""
	assignment : startwithstar ASSIGN arithmeticexpr
	"""
	if(not utils.assignmentTypeCheck(p[1], p[3], "assignment")):
		print("Type mismatch at assignment")
		sys.exit()
	p[0] = ASTNode('ASGN', p[1].dtype, p[1].pointerdepth, [p[1], p[3]])
Ejemplo n.º 2
0
def p_returnstmtforfunc(p):
	"""
	returnstmtforfunc : returnstmt
	"""
	(funcRet, funcDerive, _) = funcSymDict[currentScope]
	temp = ASTNode('RETURN',funcRet ,funcDerive, [])
	if not utils.assignmentTypeCheck(temp, p[1], "return"):
		sys.exit()
	p[0] = ASTNode('RETURN', p[1].dtype, p[1].pointerdepth, [p[1]])
Ejemplo n.º 3
0
def p_assignment_leftvar(p):
	"""
	assignment : NAME ASSIGN arithmeticexpr
	"""
	global currentScope, varSymDict
	(dtype, pointerdepth) = utils.giveVarSymOutput(p[1], currentScope, varSymDict)
	nodeL = ASTNode('VAR', dtype, pointerdepth, [p[1]])
	if(not utils.assignmentTypeCheck(nodeL, p[3], "assignment")):
		print("Type mismatch at assignment")
		sys.exit()
	p[0] = ASTNode('ASGN', nodeL.dtype, nodeL.pointerdepth, [nodeL, p[3]])
Ejemplo n.º 4
0
def p_boolfromarith_def(p):
	"""
	boolfromarith   : arithmeticexpr LTE arithmeticexpr
					| arithmeticexpr GTE arithmeticexpr
					| arithmeticexpr LT arithmeticexpr
					| arithmeticexpr GT arithmeticexpr
					| arithmeticexpr COMPARENOTEQUAL arithmeticexpr
					| arithmeticexpr COMPAREEQUAL arithmeticexpr
	"""
	if not utils.assignmentTypeCheck(p[1], p[3], "comparison"):
		sys.exit()
	if(p[2] == '<='):
		p[0] = ASTNode('LE', None, None, [p[1], p[3]])
	elif(p[2] == '>='):
		p[0] = ASTNode('GE', None, None, [p[1], p[3]])
	elif(p[2] == '<'):
		p[0] = ASTNode('LT', None, None, [p[1], p[3]])
	elif(p[2] == '>'):
		p[0] = ASTNode('GT', None, None, [p[1], p[3]])
	elif(p[2] == '!='):
		p[0] = ASTNode('NE', None, None, [p[1], p[3]])
	else:
		p[0] = ASTNode('EQ', None, None, [p[1], p[3]])