Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 3 test cases (< 10 , < 21, > 21 source lines)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Question Can plan participants borrow from a VEBA?

Answered: 1 week ago

Question

Question What is an educational benefit trust and how is it used?

Answered: 1 week ago

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago