Part 3 50 Simple Lisp Interpreter Bison Flex Programming 1
Part 3 (50%) – Simple Lisp Interpreter (Bison & Flex Programming)
1. Design and implement the language for the following simple Lisp interpreter.
2. Language design and implementation
2.1 number (of type double)
2.2 variable (atom)
Variable - the length of a variable-name can be up to 40 characters long
Support a symbol table to handle many variable entries (at least 100)
A variable is either undefined or to set for a number (type double).
2.3 list expression, for example,
(+ 1 2)
(+ 1.0 2.5)
(+ 1 2 3 4)
(+ (* 1 2) (- 3 4) )
2.4 setq statement to set a variable with a number (to be converted to double), for example,
(setq x 1.5)
2.5 lisp functions for basic arithmetic (+, -, *, /, 1+)
2.6 print function, for example, (print (+ a 10.2))
2.7 (exit) to terminate the program
3. Try your program with the sample test cases.
1
2.5
(+ 1 2)
(+ 1.0 2.5)
(+ 1 2 3 4)
(+ (* 2 3) 1 (- 5 4))
(setq x 3)
(setq y 4)
(+ x y)
(setq z123456789 100.0)
Solution
As per chegg policy I will be answering only tp 3 questions:
1)
(setq y 34.567)
(print y)
2)
(write-line (string \"Hello boy\"))
3)
(write (+ 1 2))
(terpri)
(write (+ 1.0 2.5))
(terpri)
(write ( + 1 2 3 4)
(terpri)
(write ( +(* 1 2) (- 3 4))

