In lecture we have seen (or will see) several attribute grammar extensions, including:
Use these new features to rewrite your semantic analyzer for Cool. You should also ensure that your semantic analyzer handles all of Cool. (Undergraduates need not check for any additional errors; graduate students should find all the errors that coolc finds.)
Not all of the extensions are available with the static scheduler, and
thus you will need to use the dynamic scheduler (omit the -S
option to apscpp).
The dynamic scheduler will not warn you about undefined attributes at
compile-time; the problem will not be discovered until run-time.
You will need to use the -G option to apscpp to generate
tracing information, and the -s option to the driver to turn on
the trace.
As before we have provided a partial attribute grammar to get you started. You cannot start this homework until you are done working on Homework #3, since the part we provide you is for the cases you handled in the previous homework. We also provide a driver and a Makefile.
APS has other features (such as procedures, polymorphic attributes, for-loops, and pattern matching) but the apscpp compiler does not currently implement them, so they cannot be used. Adding more features to apscpp or making more things available for static scheduling is a good master's project or thesis possibility.
For this assignment, we encourage you to use the TABLE module.
This module provides rapid lookup but has some extra requirements to
ensure declarativeness.
The TABLE module takes two parameters: the key type (which must
be ordered) and the value type (which must be combinable).
The value type is usually a bag or set type.
All the values assigned for a key in the table are combined together
without regard to the order in which they were entered.
Assuming we have a collection (or occurrence of a collection
attribute)
of type
, then if you write
then an entry for key![]()
:>$table_entry(,);
caseThe result of$select(
,
) begin
match$table_entry(?,?v) begin
- use v
end;
end;
select will always be of this form: if the
key has never been entered in the table, the initial value of the
combinable value type (for instance {}) is the result.
As usually in APS, the value of the table cannot be used until the table is complete. In particular, it is useless to write:
if not in_table(The current implementation of) then - Don't do this!
:>
$table_entry(...);
endif;
TABLE is somewhat fragile.
Don't call the combination
function yourself: only use a table type as the type of a collection
(or collection attribute).
Make a directory for your assignment, go into it and then copy over the APS files:
grid.cs: make -f /afs/cs.uwm.edu/users/classes/cs754/src/homework4/MakefileThis will get several files including
messages).
You will get a link error when you first start because the functions
type_lub, type_leq and find_class have empty
bodies, and the current APS compiler assumes they are
``native'' functions (with bodies written in C++). You should start
the assignment by writing (first drafts of) these functions.
When you are finished with the homework, please answer the questions in the README.