示例#1
0
def p_fun_scope(p):
	'''fun : FUN ID'''
	p[0] = Node('',[],[p[2]])
	p[0].name = p[2]
	p[0].typ = "int"
	# Miro si el nombre de la funcion ya esta en current
	re=symtab.redeclaration(p[2])
	if re:
		print "#Error# redeclaracion de funcion '%s' en linea %i" % (re.name,re.lineno)
	else: #Sino esta redefinido lo agrega a la tabla
		symtab.baf(p[2],"int")
	
	funcstack.append(p[2])
	
	#Creo un nuevo scope
	symtab.new_scope()
示例#2
0
    else:
        print "Caracter ilegal '%s'" % t.value[0]
        t.lexer.skip(1)

# Funcion principal
def run_lexer():
    """
	Funcion principal, lee un archivo desde la entrada estardar y devuelve los tokens
    """

    import sys
    file = open(sys.argv[1])
    lines = file.readlines()
    file.close()
    strings='''
    '''
    for i in lines:
        strings += i
    lex.input(strings)
    while 1:
        token = lex.token()       # Get a token
        if not token: break        # No more tokens
        print "(%s,'%s',%d)" % (token.type, token.value, token.lineno-1)

lex.lex()
symtab.new_scope()

if __name__ == '__main__':
    run_lexer()

def p_fundecl(p):
	'fundecl : FUN'
	# Crea una nueva tabla de simbolos
	symtab.new_scope()
示例#4
0
        print "Caracter ilegal '%s'" % t.value[0]
        t.lexer.skip(1)


# Funcion principal
def run_lexer():
    """
	Funcion principal, lee un archivo desde la entrada estardar y devuelve los tokens
    """

    import sys
    file = open(sys.argv[1])
    lines = file.readlines()
    file.close()
    strings = '''
    '''
    for i in lines:
        strings += i
    lex.input(strings)
    while 1:
        token = lex.token()  # Get a token
        if not token: break  # No more tokens
        print "(%s,'%s',%d)" % (token.type, token.value, token.lineno - 1)


lex.lex()
symtab.new_scope()

if __name__ == '__main__':
    run_lexer()