listp( e ) - returns 1 if e is a list, 0 otherwise
to allow construction and access to lists.
These functions can be implemented using list functions from your implementation language.
Finally, you should introduce an operator,
denoted by two consecutive vertical bars, ||, for list concatenation.
Note that not all operators can be applied to integers or lists. E.G. +, -, and * only
apply to integers, while || only applies to lists. Similarly, car, cdr, and null?
require lists as inputs, while cons(x,L) can have x as either an integer or a list, but
L must be a list. This error checking can be performed at runtime (i.e. when the program
is interpreted).
This assignment may be written in any of the following languages: C, C++, java, python,
and their corresponding parser generators,
though the current mini language interpreter provided from me is written in C++ and
bison(there is some java code but that code does not suppport the extension of the mini
language to allow procedures).
Background Information
Background information is available in lectures
1 and 2.
What to do
Extend the mini language and interpreter from
Lecture 2c to:
- Allow variables to be either integers or lists.
- to support list constants denoted by comma separated
lists surrounded by "[" and "]". You may use the grammar from
Assignment 1 with "(" and ")" replaced by "["
and "]".
- to support the list functions cons(e,L), car(L), cdr(L), nullp(L),
intp(e), and listp(e).
- to support a list concatenation operator denoted by ||
Use the extended language to write and call a function to compute the length of a list
(implement this function iteratively and recursively). Execute programs that define
and call these functions using your interpreter.
How to submit
Students should submit their solution electronically using webct.
Only one submission is required per group. The group leader for the
assignment should submit the assignment.
Submit a gzipped tar file, called A2.tar.gz (the tar file should contain
a directory called A2 which contains the files). The tar file should
contain source code, instructions how to run your programs, sample input
and output files, and a README file. The README file should describe all
files that are included, contain instructions how to build and use the
code, and outline how the code works. The README file should also contain
a list of all group members and the group leader for the submitted assignment.
You should also indicate how you
tested your code. If your program is not working, you
should clearly state this in the README file. Code should be
documented (clear specifications and comments for any tricky parts of the code).