This is your fourth milestone assignment.
You may develop your code
any procedural language,
but you must ensure it runs correctly on a stock linux
Your task is to write a environment system for holding
information about which variables are in scope and what there
environment can be thought of as linked list of tables,
each table (from front to back) holds the variables and
their values for ever increasingly outer scopes.
An environment can also be used during parsing to determine
if a variable has been defined before use and to detect
type errors in statically typed languages.
You should implement the following environment functions:
Start be reading this.
placing an identifier and value into the most local table; returns the value
looking up a variable; all tables are searched from most local to most
outer; the value of the first occurrence of the variable is returned
setting the value of a variable; all tables are searched from most local
to most outer; the value of the first occurrence of the variable is
changed; returns either the new value or the old value
making an empty environment; the environment consists of one empty table
in the list of tables; the newly created environment is returned
extending the given environment with a list of variables and a list of
values; a new environment is returned with the
variables and values placed in a table at the head of the given
environment; the given environment is unmodified
displaying the environment; this function should have two forms;
one form displays only the local table, the other all tables
you are to write a environment class or module.
One should be able to exercise the environment by
typing in the command:
The output of the program should be text of the form:
Creating a new environment
The environment is: ...
Adding variable x with value 3
The environment is: ...
Extending the environment with y:4 and z:"hello"
The local environment is: ...
The environment is:...
Grading the assignment
Grading will proceed exactly as the previous milestone assignment.
You should provide a makefile that responds to the commands:
Submitting the assignment
To submit your assignment,
delete all object or class files from your
leaving only source code,
a readme file,
and any test
cases you may have.
while in your working directory,
submit proglan lusth environment
The submit program will bundle up all the files in your current
directory and ship them to me.
This includes subdirectories as well
since all the files
in any subdirectories will also be shipped to me.
You may submit as many times as you want before the deadline; new
submissions replace old submissions.