The following productions need to be added to the Cflat grammar:
typedef → TYPEDEF STRUCT ID ID SEMICOLON type → ID varDeclList → varDeclList typedef
The first production permits typedefs to be used with struct types. The second production permits a declaration that uses a new type name. The third production permits a typedef to occur anywhere that a local variable declaration can occur.
Each symbol table entry should include "kind" (variable, function, struct,or typedef) information, as well as "type" information. For a typedef, the "type" information is the built-in type or struct type for which the typedef defines a new name. (Note: It is also possible to let the "type" field be a typedef name, but that complicates type checking. Note also that if the "kind" field is not needed for type checking, then it is OK just to have a flag that says whether or not this is a typedef name.)
To process typedef T xxx:
Processing a variable/function/parameter declaration T xxx is the same as processing typedef T xxx except that when xxx is added to the symbol table, its kind is var/function/parameter (as appropriate) instead of "typedef".
To process a use of name xxx in a statement:
Here is the symbol table after processing the given declarations: