Professional Documents
Culture Documents
SECION B
COMPILADORES
import re
file = open("read.py")
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()
##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("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _")