Description
1. Your solution should be able to translate those constructs from the previous project, including integer
and float values, variables, print, assignment, and the expressions specified in the previous project.
2. For this project, your solution should be able to translate Python functions, including scope resolution
1a, return value propogation 1b and 1c.
3. In addition, your solution should translate if/else (not elif). You must also translate the six (6) relational operators: <, <=, ==, >, >=, ! =. You are not required to implement and, or, not.
4. In all cases, the oracle for correctness is a Python 2.7 interpreter; your expressions should evaluate to
the same value as a Python 2.7 interpreter, but not the same format. So, 5 is the same as 5.0; True is
the same as 1, False is the same as 0.
5. In the directory that contains your working interpreter, place a new directory titled cases that contains
test cases that adequately test your interpreter.
6. Write a test harness, test.py, and place it in your project folder so that it runs the test cases in cases.
7. Your code should be well organized, formatted, readable, leak and warning free, and exploit object
technology.
Light at the end of the tunnel:
In the final project, Project #6, we will translate actual and formal parameters and recursion.
1
d e f f ( ) :
x = 0
i f x == 0 :
p r i n t 99
x = 17
i f x :
p r i n t 1
e l s e :
p r i n t 2
f ( )
p r i n t 17
(a) Basic Scope
d e f f ( ) :
r e t u r n 7∗2
d e f g ( ) :
p r i n t 15
x = 12
d e f h ( ) :
r e t u r n x
p r i n t h ( )
r e t u r n 2∗ x
p r i n t f ( )
p r i n t g ( )
(b) Nested Functions
d e f f ( ) :
x = 0
i f x == 0 :
p r i n t 99
x = 17
i f x :
p r i n t 1
r e t u r n
e l s e :
p r i n t 2
p r i n t 101
f ( )
p r i n t 17
(c) Return Statement
Figure 1: Examples of Some Interesting Python Test Cases.
2