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

Also, send output

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago