You are on page 1of 3

UMG VILLA NUEVA

SECION B

COMPILADORES

CATEDRATICO: ING. BRYAN DARREN

DAINER REYES CARNET: 5390-20-1263

HERBERT ARAGON CARNET: 5390-20-9660


print()
print(" PROYECTO DEL ANALISADOR COMPILADORES ")
print()

import re

file = open("read.py")

operators = {'=' : 'Assignment op','+' : 'Addition op','-' : 'Subtraction


op','/' : 'Division op','*' : 'Multiplication op','<' : 'Lessthan op','>' :
'Greaterthan op','==':'igual
a','=+':'aumentar','=-':'disminuir','=>':'mayorigual','=<':'menorigual'}
operators_key = operators.keys()

data_type = {'int' : 'integer type', 'float': 'Floating point' , 'char' :


'Character type', 'long' : 'long int' }
data_type_key = data_type.keys()

palabras_reservadas=
{'if':'si','IF':'si','else':'en_cambio','while':'talvez','for':'para','For':
'para','switch':'ciclo','return':'retorno','main':'cuerpo','&&':'and','||':'
or'}
palabras_reservadas_key= palabras_reservadas.keys()

punctuation_symbol = { ':' : 'dos puntos', ';' : 'punto_y_coma', '.' :


'punto' , ',' :
'comma','@':'arroba','#':'hastack','(':'parentesislh',')':'parentesisrh','[]
':'corchetes' }
punctuation_symbol_key = punctuation_symbol.keys()

identifier = { 'a' : 'id', 'b' : 'id', 'c' : 'id' , 'd' : 'id' }


identifier_key = identifier.keys()

##dataFlag = False

a=file.read()

count=0
program = a.split("\n")
for line in program:
count = count + 1
print("line#" , count, "\n" , line)
##separa por tokens y leer en el compilador

tokens=line.split(' ')
print("Tokens are " , tokens)
print("Line#", count, "properties \n")
for token in tokens:
if token in operators_key:
print("operator is ", operators[token])
if token in data_type_key:
print("datatype is", data_type[token])
if token in punctuation_symbol_key:
print (token, "Punctuation symbol is" ,
punctuation_symbol[token])
if token in identifier_key:
print (token, "Identifier is" , identifier[token])
if token in identifier_key:
print (token, "palabras reservadas son" ,
palabras_reservadas[token])

dataFlag=False
print("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _")

You might also like