Lisp Assignment: Creating a Symbol Table Class, Assignments of Programming Languages

An assignment for creating a symbol table class in lisp. The assignment involves designing and implementing the class, including functions for adding and accessing elements. The provided code demonstrates the usage of these functions.

Typology: Assignments

Pre 2010

Uploaded on 04/12/2010

koofers-user-7go
koofers-user-7go 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT #5
Due Thursday, October 30, 20031
1. Design and implement a symbol table “class” in Lisp. The symbol table elements will be of
the form (name category type value) and the symbol table itself will be a list of such values.
The following functions are required:
(a) add (symboltable name category type value) - returns a symbol table with the
name, category, type, and value fields added; if name is already in the symbol table,
returns nil
(b) entry (symboltable name) - returns the category, type and value associated with
name; if name is not in the symbol table, returns nil
(c) category (symboltable name) - returns the category associated with name; if name is
not in the symbol table, returns nil
(d) type (symboltable name) - returns the type associated with name; if name is not in
the symbol table, returns nil
(e) value (symboltable name) - returns the value associated with name; if name is not in
the symbol table, returns nil
Test your class using the following sequence of calls.
(setq test2st (add nil ’h ’var ’int 0))
(setq areast (add nil ’x ’var ’int 0))
(setq areast (add areast ’y ’var ’int 1))
(setq areast (add areast ’z ’var ’int 2))
(setq test2st (add test2st ’area ’method ’int (list ’(x y) areast
’(: (= z (* 2 (+ (+ (* x y) (* x h)) (* y h)))) (return z)))))
(setq mainst (add nil ’a ’var ’int 0))
(setq mainst (add mainst ’b ’var ’int 1))
(setq mainst (add mainst ’s ’var ’int 2))
(setq test2st (add test2st ’Main ’method ’void (list ’() mainst
’(: (: (: (: (= a 3) (= b 4)) (= h 5)) (= s (apply area (@ a b)))) (print s)))))
(setq st (add nil ’Test2 ’class ’Test2 test2st))
(entry test2st ’h)
(entry test2st ’area)
(entry mainst ’b)
(entry st ’Main)
(category areast ’y)
(category mainst ’y)
(type st ’Test2)
(type st ’class)
(value mainst ’s)
(value areast ’area)
1No penalty will be assessed for turning this assignment in on Tuesday, November 4, but no assignments will be
accepted later than that.
pf2

Partial preview of the text

Download Lisp Assignment: Creating a Symbol Table Class and more Assignments Programming Languages in PDF only on Docsity!

ASSIGNMENT

Due Thursday, October 30, 2003^1

  1. Design and implement a symbol table “class” in Lisp. The symbol table elements will be of the form (name category type value) and the symbol table itself will be a list of such values. The following functions are required:

(a) add (symboltable name category type value) - returns a symbol table with the name, category, type, and value fields added; if name is already in the symbol table, returns nil (b) entry (symboltable name) - returns the category, type and value associated with name; if name is not in the symbol table, returns nil (c) category (symboltable name) - returns the category associated with name; if name is not in the symbol table, returns nil (d) type (symboltable name) - returns the type associated with name; if name is not in the symbol table, returns nil (e) value (symboltable name) - returns the value associated with name; if name is not in the symbol table, returns nil

Test your class using the following sequence of calls.

(setq test2st (add nil ’h ’var ’int 0)) (setq areast (add nil ’x ’var ’int 0)) (setq areast (add areast ’y ’var ’int 1)) (setq areast (add areast ’z ’var ’int 2)) (setq test2st (add test2st ’area ’method ’int (list ’(x y) areast ’(: (= z (* 2 (+ (+ (* x y) (* x h)) (* y h)))) (return z))))) (setq mainst (add nil ’a ’var ’int 0)) (setq mainst (add mainst ’b ’var ’int 1)) (setq mainst (add mainst ’s ’var ’int 2)) (setq test2st (add test2st ’Main ’method ’void (list ’() mainst ’(: (: (: (: (= a 3) (= b 4)) (= h 5)) (= s (apply area (@ a b)))) (print s))))) (setq st (add nil ’Test2 ’class ’Test2 test2st)) (entry test2st ’h) (entry test2st ’area) (entry mainst ’b) (entry st ’Main) (category areast ’y) (category mainst ’y) (type st ’Test2) (type st ’class) (value mainst ’s) (value areast ’area)

(^1) No penalty will be assessed for turning this assignment in on Tuesday, November 4, but no assignments will be accepted later than that.

  1. Consider the Core program below:

input n; i := 1; while (i <= n) loop i := i + 1; end loop; output i;

Assuming that the input file contains the integers 3 and 4 (i.e., the list <3, 4>), use the denotational semantics of Core to trace the interpretation of the program.