Starting from:

$25

Comp301 - Project 2  - Solved

In this project, you will define a language named MYLET that is similar to the simple LET language covered in the class. The syntax for the MYLET language is given below.

Program ::= Expression a-program (exp1)

Expression ::= Number const-exp (num)

Expression ::= String str-exp (str)

Expression ::= op(Expression, Expression, Number) op-exp (exp1, exp2, num)

Expression ::= zero? (Expression) zero?-exp (exp1)

Expression ::= if Expression then Expression {elif Expression then Expression}* else Expression

if-exp (exp1 exp2 conds exps exp3)

Expression ::= Indetifier var-exp (var)

Expression ::= let Indetifier = Expression in Expression

let-exp (var exp1 body)
Figure 1. Syntax for the MYLET language

Part A. This part will prepare you for the following parts of the project. (15 pts)

(1)    Write the 5 components of the language[1]:

(2)    For each component, specify where or which racket file (if it applies) we define and handle them.

Part B. In this part, you will create an initial environment for programs to run. (10 pts)

(1)    Create an initial environment that contains 3 different variables (x, y, and z).

(2)    Using the environment abbreviation shown in the lectures, write how environment changes at each variable addition.

Part C. Specify expressed and denoted values for MYLET language. (5 pts)

Part D. This is the main part of the project where you implement the MYLET language given in the Figure 1 by adding the missing expressions.

(1)    Add str-exp to the language. Strings are defined as any text starting and ending with ', e.g. 'comp301', 'program'; strings are stored with ' symbols. (15 pts)

Hint: String is an expression that is similar to Number, understanding the addition and implementation of Number may be helpful to complete this step.

(2)    Add op-exp to the language. (15 pts) op-exp is similar to the diff-exp of the LET language; however, in LET language, the only possible operation was subtraction. op-exp enables you to do 4 arithmetic operations via its third input (Number), when third input is:

•    1: perform addition (exp1 + exp2)

•    2: perform multiplication (exp1 * exp2)

•    3: perform division (exp1 / exp2)

•    any other number: perform subtraction (exp1 - exp2)

(3)    Add if-exp to the language. Unlike if-exp of the LET language, you can add multiple conditions to be checked through elif-then extension. Starting from the condition of if, conditions will be checked until a true condition is found, and expression corresponding to the true condition will be evaluated as a result. If none of the if/elif conditions are correct, the expression in the else statement will be evaluated. (15 pts)

(4)    Add a custom expression to the language. The expression can be simple, but you need to clearly explain what it does and how it works. You also need to provide the syntax of the expression. (15 pts)

Note that the implementation of the other expressions, that are same with the LET language, are already given in the .rkt file provided. We deleted the former implementations of if and diff-exp.

Part E. Create the following test cases. (10 pts)

(1) custom expression: Write test cases that controls if the expression works according to your explanation of the expression.



 
[1] Hint: review Lecture 10 slides

More products