Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an interpreter which uses the top - down recursive - descent method to parse and evaluate a very simple programming language. The tiny language's

Write an interpreter which uses the top-down recursive-descent method to parse and evaluate a very simple programming language. The tiny language's grammar is given below.
::= empty |{}
::= id = ; | print ;
::={+|-}
::={*|/}
::= id | intnum |()
The interpreter should be written in Python. It takes one input file (sample.tiny) which is a text file consisting of the statements of the above grammar. The input file name sample.tiny is given from the command line. The interpreter parser_xxxxxxx.py reads the program file sample.tiny, checks the syntax and outputs the result if the program is legitimate; otherwise, the interpreter prints "Syntax Errors".
Below are some test examples in sample.tiny:
print 2+3*4 ;
s =2+3 ;
t =9-2 ;
print s * t ;
print ( s + t )*( s - t ) ;
Please issue python3 parser_xxxxxxx.py sample.tiny on the spirit machine to test your Python program before you turnin it. Please use if __name__==__main__: in your code
Sample running results:
Command Line: python3 parser_xxxxxxx.py sample.tiny
Output:
Print 2+3*4 ;
14
s =2+3 ;
t =9-2 ;
print s * t ;
35
Print ( s + t )*( s - t ) ;
-24
There are answers to this question on chegg but they didn't work for me

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

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

02 Legislative and regulatory processes.

Answered: 1 week ago

Question

Given w2x3 -5xy3 Is xwx + ywy 3wx ? o o

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago