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 1 test cases more than 21 lines.

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

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

Step: 3

blur-text-image

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

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

5. Discuss the role of the Web in career management.

Answered: 1 week ago

Question

4. Design a career management system.

Answered: 1 week ago