(40 points) Build symbol tables to keep track of identifiers and their types for Tiny-Ada programs. Types are restricted to integer and boolean. Local declarations hide non-local declarations of the same name. Only one declaration for an identifier is allowed in each scope. You may use my definition for a symbol table in http://www.ics.uci.edu/~klefstad/s/142/src//symtab.*.
(60 points) Write and test a program to do expression type checking for Tiny-Ada programs. Here is an example input program:
declare
i: integer;
b: boolean;
begin
get(i);
b := false;
b := i<10 and not b;
declare
b: integer;
begin
b := 5;
i := 2*(i+b);
end;
b := 1<i and i<35 and not b;
put(i);
put(b);
end;
Here are the type system rules for Tiny-Ada:
"<" - arguments must be the same type, result is boolean
"and", "not" - arguments must be boolean, result is boolean
"+", "*" - arguments must be integer, result is integer
integer literals are of type integer
true and false are of type boolean (they are not reserved words!)
the type of a parenthesized expression is unaffected
the arguments of an assignment statement must be the same type
variables have their declared type
I/O, i.e., get and put, are defined for both boolean and integer variables
Submit your program source and and a test execution on one complex correct and one complex incorrect Tiny-Ada program to show it detects type mismatches. Print the the contents of the symbol tables before exiting any declare block.