Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!