Help in programming languages class

Price: $5 USD

Question description

Book for this course:

Question 1:

Write an interpreter for the LETREC language with the following extensions:

Expression ::= proc ({Identifier}*(,)) Expression

Expression ::= (Expression (Expression)*)

Here are some examples:

proc() -(5,2) %% no bound variables

proc (x,y, z) -(-(x,y), z) %% three bound variables

(proc() -(5,2)) %% call with no parameters

(proc(x,y,z) -(-(x,y),z) 5 2 1) %% call with 3 parameters


You must use the SLLGEN parsing system to create a scanner and parser. The scanner specification is as follows:

‘((white-sp (whitespace) skip)

(identifier (letter (arbno (or letter digit))) symbol)

(number ((or “-” digit) (arbno digit)) number)


Hence you have to create the grammar specification for the LETREC language and the extensions required for the problems. You obtain the abstract syntax for your program via the make-string-parser procedure of SLLGEN:

(define scan&parse

(sllgen: make-string-parser <scanner-spec> <grammar-spec>))

where scanner-spec and grammar-spec are your specifications (names).

A program is interpreted by calling value-of-program. This should be encapsulated in the run procedure:

(define run

(lambda (string)

(expval->num (value-of-program (scan&parse string)))))

Where expval->num is your expressed value to denoted value function.

You must implement your interpreter of the boolean operators in the actual LETREC language except for less? which is to be implemented using the < operator in Scheme.

Similarly all of the arithmetic operators except the difference operator must be written in the LETREC language Example:

(define value-of

(lambda (exp, env)

(cases Expression exp

(minus-exp (exp1)

(value-of (diff-exp (const-exp 0) exp1)) env))

Question 2:

  • Extend the LETREC language so that a let declaration can declare an arbitrary number of variables, using the grammar:
  • Extend the LETREC language with a let* expression that works like Schemes let* so that
  • Extend the LETREC language to allow the declaration of any number of mutually recursive unary procedures, for example:

Expression ::= let {Identifier = Expression}* in Expression

As with Schemes let, each of the right-hand sides is evaluated in the current environment, and the body is evaluated with each new variable bound to the value of its associated right-hand side. For example:

let x 30

in let x = -(x, t)

y = -(x,2)

in -(x, y)

should evaluate to 1. The lets are not nested just evaluated with the same environment.

let x 30

in let* x = -(x ,1) y = (x ,2)

in (x,y)

should evaluate to 2. That is the lets are nested.


even (x) = if zero?(x) then 1 else (odd -(x,1))

odd (x) = if zero? (x) then 0 else (even -(x,1))

in (odd 13)


As in Question 1 you must use the SLLGEN parsing system to create a scanner and parser for these language extensions.

Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1824 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors