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 haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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