Constructing an interpreter for a simplified lisp

Assignment Help Programming Languages
Reference no: EM132978145

COMP3000 Programming Languages - Macquarie University

Assignment - Interpreter

Overview
The assignment code bundle provides a Scala skeleton program for constructing an interpreter for a simplified LISP-like language. For example, the input:

(+ 3 5) produces 8
(* (+ 3 4) 5) produces 35 ( = 7 * 5)
(setq x (+ 3 5)) assigns the value 8 to the variable x
(quote (a b c)) produces the list (a b c)
(car (quote (a b c))) gets the head of the list (a b c), producing a
(cdr (quote (a b c))) gets the tail of the list (a b c), giving the list (b c) (If you want to see more about LISP then visit clisp.org.)
Language basics
As can be seen above, the language has a very simple syntax that relies heavily on brackets and prefix notation (i.e. the function/operator comes before the arguments).

In our simplified language, the only things to be manipulated are:
• symbols, e.g. +, setq, x, quote, car, cdr
• numbers, e.g. 3, -5; these are always only integers (without +; e.g. +4 not allowed)
• lists

In the language, expressions and statements are lists and data items can also be lists. In the fourth example line above, the list (a b c) was produced. It might seem that we could write just:

(a b c)

and it would give us that list; but whenever the language is given a list to evaluate, it treats the first thing in the list as a function name or operator, e.g.

(+ 3 5) + is the operator
(car (quote (a b c))) car is the function

To override this default behaviour, the special form quote is used which treats its argument literally rather than trying to evaluate it; e.g.
(quote (+ 3 5)) produces the list (+ 3 5) We have two special symbols in the language:
• nil which always evaluates to nil
• t which always evaluates to t nil is equivalent to the empty list.
In the language, if a condition evaluates to nil then it is considered to be false; any other value means true and t is conventionally used to represent true.

Language functionality
You will need to implement the following.

Usually in the language, if an expression has the form:

(a b) or (a b c) [where b, c could also be expressions] then a is interpreted as the function and b, c are interpreted as the arguments.
It will be evaluated by:
1. evaluating the argument expressions
2. passing the values of the evaluated arguments to the function

Functional programming
While the aim of the programming is write the interpreter, you will also be assessed on how well your program is written in the style of functional programming. For example:
• use val instead of var for variable declarations
• try to avoid iterative loops (for/while); use map, filter, reduce, ...
• use match instead of multiple Ifs; in particular, use a single match in eval with a case for each of the different kinds of expressions

Running the program
The skeleton for this assignment is designed to be run from within sbt. In the command prompt for sbt, there are four relevant commands:
• test - runs the test suite (tests are in src/test/scala/iInterpretTests.scala
• run - executes the main function in src/main/scala/Main.scala which repeatedly prompts you to enter an expression to be executed; an empty input line will terminate it
• compile - compiles any changed source files; there is no need to separately compile because the run and test commands always do any required compilation
• console - this is used for impromptu testing (after you have done a compile); it will bring up a "scala>" prompt; then enter:
import org.mq.interpret.Interpret._
now you will be able to access the Scala functions and classes in Interpret.scala; e.g.
LSymbol("fred")
or:
eval(LSymbol("nil"))

What you must hand in and how
A zip file containing:
• Interpret.scala
• InterpretTests.scala

Your submission should include all of the tests that you have used to make sure that your program is working correctly. Note that just testing one or two simple cases is not enough for many marks. You should test as comprehensively as you can.

Attachment:- Programming Languages.rar

Reference no: EM132978145

Questions Cloud

When would each type of prevention be appropriate : When would each type of prevention be appropriate? How do public health policies and interventions affect your daily life? Use examples.
Future growth of international hotels : What were my challenges for reaching the SLOs in this chapter: (What was holding me back?)
How much is the amount of total share premium : The entity used cost method of accounting for treasury shares. How much is the amount of total Share premium on treasury transaction
Why an organization mission are significant to nurse : Explain why an organization's mission, vision, and values are significant to nurse engagement and patient outcomes. Examines the significance of an organization
Constructing an interpreter for a simplified lisp : Provide a Scala skeleton program for constructing an interpreter for a simplified LISP-like language - expressions and statements are lists and data items
Does the media show us an example of intersectionality : Does the media show us an example of intersectionality, sisterhood, sexism, the male gaze, etc.? Or does it subvert these tripes in different ways?
Discuss attributes of success or lack thereof : Critique an example of a professional organization's use of media to promote a health policy agenda. Discuss attributes of success or lack thereof.
Describe one external method for the dissemination : Describe one internal and one external method for the dissemination of your evidence-based change proposal. For example, an internal method may be the hospital.
Discuss the type of questions will be asking the patient : The five elements of the nursing process are all incorporated, Discuss the type of questions you will be asking this patient in relation to her chest pain.

Reviews

len2978145

8/31/2021 10:27:04 PM

Scala Assignment (comp3000-interpret1.zip) using sbt. There is 45 tests need to be passed and also have to write my own test cases (at least 10). So in total at least 55 tests need to be passed. Please use VS Code to do the assignment. Run the code in VS Code terminal using sbt command and then using test command

Write a Review

Programming Languages Questions & Answers

  Write a main program to call a procedure

Write a main program to call a procedure that converts the Fahrenheit temperature value stored in the location labeled TdegF to its Celsius equivalent. The range of temperatures is 32°F to 212°F

  Write a program using c coding for microcontroller

Write a program using C coding for your MSP430 microcontroller so that it: When push button is pressed 4 times the red LED is on.

  Calculate resistance value

Develop a PROLOG program that prompts the user for the colors of Band 1, Band 2, Band 3, and Band 4 and then displays the resistance in Kilo-ohms.

  Determine the total resistance of a number of resistors

Prepare a function that will determine the total resistance of a number of resistors that are connected in parallel.

  Creating session by granting needed privilege

Make sure that Bob can't create objects greater than 512K in size in USERS01 tablespace. And now that user is created, ensure that Bob can create session, by granting needed privilege.

  Benefits from the cloud first policy

Cloud computing enables IT systems to be scalable and elastic. End users do not need to determine their exact computing resource requirements upfront. Instead, they provision computing resources as required, on-demand. Using cloud computing services,..

  One-dimensional as array of counters to solve problem

Write program which determines how many salespeople earned salaries in each of following ranges. Use the one-dimensional as the array of counters in solving this problem

  Design a language for the problem domain of E-commerce

ITECH5403 Comparative Programming Languages Assignment- Language Design Essay, Federation University Australia. Design language for problem domain of E-commerce

  Write application for university admissions office

Write an application for a university admissions office. Prompt the user for a student's High School Grade Point (for example 3.2) and an admission test score (value from 0 to 100).

  Implement assignment using procedural programming

CSCI251 - Advanced Programming - This assignment is to be implemented using procedural programming. The overall program should follow the progress of students

  Research security vulnerability tools using kali

Research Security vulnerability tools using Kali - explain the syntax of commands you use. Your presentation must include at least 6 screenshots

  Determine recursive procedure and iterative procedure

Determine the example or recursive procedure and represent it as iterative procedure. Also, select the iterative procedure which you would re-write as recursive.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd