[SOLVED] Comp301-Project 2

30.00 $

Category:

Description

5/5 - (1 vote)

To create your group, use the Google Sheet file in the following link:

Link to Google Sheets for Choosing Group Members

Note: You need to self-enroll to your Project2 group on BlackBoard (please only enroll to the same group number as your group in the Sheets), please make sure that you are enrolled to Project 2 – Group #YourGroup.

This project contains a bonus component specified at the end and there are two code boilerplates provided to you: use Project2MYLET for the project and Project2BONUS for the bonus. Submit a report containing your answers to the written questions in PDF format and Racket files for the coding questions to Blackboard as a zip. Include a brief explanation of your team’s workload breakdown in the pdf file. If you attempt to solve the bonus question, make sure that your zip includes both Project2MYLET and Project2BONUS folders separately. Name your submission files as p2_member1IDno_member1username_member2IDno_member2username.zip Example: p2_0011221_galtintas17_0011222_mkarakas16.zip.

 

Table 1. Grade Breakdown for Project 2

Problem Definition: To evaluate the programs, you need to understand the expressions of the language. It is the same for computers; therefore, you saw in the lecture how you can invent a language and define it for the computer to understand and evaluate.

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)

  • Write the 5 components of the language[1]:
  • 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)

  • Create an initial environment that contains 3 different variables (x, y, and z).
  • 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.

  • 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.

  • 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)
  • Add if-exp to the language. Unlike if-exp of the LET language, you can add multiple conditions to be checked through elif-then 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)
  • 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.

Note: We provided several test cases for you to try your implementation. Uncomment corresponding test cases and run tests.rkt to test your implementation.

Bonus. Here is an alternative datatype ropes that allows manipulation of sequence of characters instead of the most commonly used strings. You can try to implement ropes instead of strings as a bonus challenge.

 

Hint: Define your rope datatype similar to the way you did in the project, clearly define your grammar and feel free to use any helper procedures.

[1] Hint: review Lecture 10 slides