Docsity

Implementing an Interpreter for Jam (CS 360 Term Project), Study Guides, Projects, Research of Programming Languages

Toggle sidebar
bg1
Programming Language Concepts (CS 360)
Term Project: Implementing an Interpreter for Jam
Part 2: ASTs and the Runtime Environment
Due: Sat June 4, 2005 at 11:59:59pm NO LATE ASSIGNMENTS ACCEPTED
Overview: For this assignment, you will finish implementing the Jam interpreter. The interpreter
will consist of an interactive interface, where a user can type in expressions that will be evaluated
by the interpreter. In addition, there will be an option to load a file to be interpreted. You will
continue to use your scanner and parser from the previous assignment.
Teamwork: Continue to work with the teams you selected for Part I.
The project: To implement an interpreter for Jam, we need to extend the parser to build an AST.
Once the AST is constructed, you will want to build a runtime environment that will process and
evaluate the AST. The runtime environment needs to maintain a symbol table like structure where
values of identifiers can be stored.
The following are some example Jam programs, each with varying degree of difficulty that
your interpreter should handle:
Arithmetic Expressions
Jam 0.1> 3 + 4
===> 7
Jam 0.1> ((7 - 12 / 6 * 2) * (2 + 3 * 5))
===> 51
Jam 0.1> let a := 5; in 3 * a
===> 15
List construction and manipulation
Jam 0.1> let l := (cons( 4, (cons(3, null)))); in (first(rest( l)))
===> 3
Jam 0.1> let l := (cons(4, (cons( 3, null)))); in rest(l)
===> [3 null] // You can print a list with [ ] to signify the difference
// between non-list entities
Nested Structures
Jam 0.1> let z := 4; in
let x := if z < 5 then (cons(3, null)) else (cons(4, null));
in cons (first(x) + 6, null)
===> [18 nulll]
1
pf3

Partial preview of the text

Download Implementing an Interpreter for Jam (CS 360 Term Project) and more Study Guides, Projects, Research Programming Languages in PDF only on Docsity!

Programming Language Concepts (CS 360) Term Project: Implementing an Interpreter for Jam Part 2: ASTs and the Runtime Environment

Due: Sat June 4, 2005 at 11:59:59pm NO LATE ASSIGNMENTS ACCEPTED

Overview : For this assignment, you will finish implementing the Jam interpreter. The interpreter will consist of an interactive interface, where a user can type in expressions that will be evaluated by the interpreter. In addition, there will be an option to load a file to be interpreted. You will continue to use your scanner and parser from the previous assignment.

Teamwork : Continue to work with the teams you selected for Part I.

The project : To implement an interpreter for Jam, we need to extend the parser to build an AST. Once the AST is constructed, you will want to build a runtime environment that will process and evaluate the AST. The runtime environment needs to maintain a symbol table like structure where values of identifiers can be stored. The following are some example Jam programs, each with varying degree of difficulty that your interpreter should handle:

Arithmetic Expressions

Jam 0.1> 3 + 4 ===> 7

Jam 0.1> ((7 - 12 / 6 * 2) * (2 + 3 * 5)) ===> 51

Jam 0.1> let a := 5; in 3 * a ===> 15

List construction and manipulation

Jam 0.1> let l := (cons( 4, (cons(3, null)))); in (first(rest( l))) ===> 3

Jam 0.1> let l := (cons(4, (cons( 3, null)))); in rest(l) ===> [3 null] // You can print a list with [ ] to signify the difference // between non-list entities

Nested Structures

Jam 0.1> let z := 4; in let x := if z < 5 then (cons(3, null)) else (cons(4, null)); in cons (first(x) + 6, null)

===> [18 nulll]

Input Language Specification

The following paragraphs define the Jam subset that your interpreter should handle. Your interpreter should accept the Jam language except:

  • the unary operators + (leaving - and ˜), and
  • the binary operators >, >=, !=

The following are still part of the language:

+, -, /, *, =, <,<=,&, |.

If you encounter an unsupported operator, you may raise an evaluation exception/error. The primitive Jam operations, that are still part of the language include:

null? number?, function?, list?, cons, first, and rest

The supported operators have exactly the same meaning as their Scheme counterparts with three exceptions:

  • / means the integer division,

  • = and != means equality on arbitrary objects. If either value contains a function, then return false. By default, equality means structural equality, which is what is meant here.

The meanings of the primitive functions are as follows:

null? p -> whether p is null. number? p -> whether p is a number function? p -> whether p is a function (ie a map or a primitive op)

list? p -> whether p is a list (anything constructed by cons(), or null) cons p, q -> a cons (a list entry). p can be anything. q must be a list (something created by cons() or null); Evaluation error otherwise. first p -> The first element of list p Evaluation error if p was not created by cons()