For this program you will implement a very small subset of the LISP programming language using singly-linked lists. You may write your code in C or C++. In addition to correctness, programming style is also important, so please write modular, well-documented code.
LISP stands for ``list processing'' and is used to define, query and modify lists of symbols. For us, a symbol is a string of no more than 32 uppercase alphanumeric characters (A-Z, 0-9). A list is denoted by a space-separated sequence of symbols surrounded by parentheses, e.g., ( CSE 2320 SECTION 501 ), with one space between each symbol and surrounding parentheses. The empty list is denoted by ( ).
The three LISP commands you are to implement are SETF, NTH and NTHREST as described in the following table, where n is a positive integer less than 100.
( SETF var list ) |
Sets variable var to list for possible future reference. Variable var can be any valid symbol. SETF returns the list. |
( NTH n ) |
Returns the n^{th} symbol in the given list or the list stored in variable var. If the list has fewer than n elements, then NTH returns the empty list ( ). If the variable var is undefined, then NTH returns ``Error: undefined variable''. |
( NTHREST n ) |
Returns the list remaining after removing the first n symbols from the given list or the list stored in variable var. If the list has fewer than n symbols, then NTHREST returns the empty list ( ). If the variable var is undefined, then NTHREST returns ``Error: undefined variable''. |