A type checker for Lotus

Check user's program if there is any type error and print out the symbol tables of his program.
This project will use the lexical analyzer, the parser and the architecture of the pretty printer.

Description

The type checker shall read input from stdin, writes output to stdout, and writes errors to stderr.
The type checker should be able to print the symbol tables by using the option ¡§-x¡¨.
The type checker needs to handle type errors and print error messages.


The frame of this program is shown in the following figure.



A sample for input the Lotus program

-- A program to sum 1 to n
int g;
int main( )
{
    int n;
    int s;
    int s;

    read n;
    if (n < 0) {
    write -1;
    exit;
    } else {
        s = sum(n);
    }
    write t;
    return 0;
}

int sum(int n)
{
    int s;
    int n;

    s = 0;
    while (n > 0) {
        s = s + n;
        n = n - 1;
    }
    s = sum(s, n);
    return s;
}


The output for this sample

type error: line 7: identifier s is redeclared.
type error: line 14: identifier sum is not declared
type error: line 16: identifier t is not declared
type error: line 23: identifier n is redeclared.
type error: line 30: the arity of function sum is not matched
*** The global symbol table begins ***
sum: FUNCTION, 1
*** The symbol table for function sum begins ***
n: PARAMETER
s: VARIABLE
*** The symbol table for function sum ends ***
main: FUNCTION, 0
*** The symbol table for function main begins ***
n: VARIABLE
s: VARIABLE
*** The symbol table for function main ends ***
g: VARIABLE
*** The global symbol table ends ***