Question
fname = input('Enter the file name: ') file = open(fname) operators = {'=' : 'operator','+' : 'operator','-' : 'operator','/' : 'operator','==' : 'operator','%' : 'operator'
fname = input('Enter the file name: ') file = open(fname)
operators = {'=' : 'operator','+' : 'operator','-' : 'operator','/' : 'operator','==' : 'operator','%' : 'operator' ,'*' : 'operator','<' : 'operator','>' : 'operator', '<=' : 'operator', '>=' : 'operator', '+=' : 'operator', '-=': 'operator'} operators_key = operators.keys()
keyword = ['for','while','False','await','else','if','import','pass','None','break','except','in','raise','True' ,'class','finally','is','return','and','continue','lambda','try','as','def','from','nonlocal','assert','del' ,'global','not','with','async','elif','or','yield','endwhile','forend','ifend','range','print']
punctuation_symbol = { ':' : 'colon', ';' : 'semi-colon', '.' : 'dot' , ',' : 'comma' } punctuation_symbol_key = punctuation_symbol.keys()
separator = { '(' : 'separator', ')' : 'separator',' ':'space' } separator_key = separator.keys()
dataFlag = False
a=file.read()
program = a.split(" ") print("lexems ---------- token ") for line in program: tokens=line.split(' ') for token in tokens: if token in operators_key: print(token ,"----------", operators[token]) elif token in keyword: print(token ,"---------- keyword") elif token in punctuation_symbol_key: print (token ,"----------", punctuation_symbol[token]) elif token in separator_key: print (token ,"----------", separator[token]) else: try: variable = int(token) variable = float(token) except ValueError: variable = None if variable: print (token ,"---------- real") elif token == ' ': pass else: print (token ,"---------- identifier") dataFlag=False
Find at least 1 test cases more than 21 lines. (The math Problem has to be more than 21 lines of python)
It has to be amount of lines to analyze not the tokens analyzed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started