【正文】
ts an identifier into the symbol table and associates a type to it. ? The associated type is constructed according to the grammar rules for typeexp. Compiler Theory Fall 2021 Jianhui Yue Statements ? Statements do not have types, but substructures will need to be checked for type correctness. ? Conditional expression stmt if exp then stmt must have Boolean type. if not typeEqual(, boolean) then typeerror(stmt) ? In case of assignment statement stmt id := exp, the variable being assigned must have the same type as the expression whose value to is to receive. ? This depends on the type equivalence algorithm. Compiler Theory Fall 2021 Jianhui Yue Expressions ? Constant expressions (numbers and Boolean values) have integer or boolean types. ? Types for variable names are determined by lookup in the symbol table. Compiler Theory Fall 2021 Jianhui Yue array ? The array node is : ? makeTypeNode( array ,size ,type ) ? exp1exp2[exp3] ? if isArrayType(exp2,type) amp。 typeEqual( ,integer ) ? then = ? else typeerror( exp1) array (size) type Compiler Theory Fall 2021 Jianhui Yue Overloading ? An operator is overloaded of the same operator is used for two different operations. ? 2+3 represents integer additions ? + represents floatingpoint addition ? Overloading can be extended to user–defined functions. int max (int x, int y) double max ( double x, double y) ? The type checker can decide which function is meant based on the types of parameters (C++, Ada). Compiler Theory Fall 2021 Jianhui Yue Type Conversion and Coercion ? A mon extension of the type rules of a language is to allow arithmetic expressions of mixed type, such as + 3 ? A mon type must be found that is patible with all the types of the subexpression. ? One of the possibility is for a type checker to supply the conversion operation automatically (C). ? The other possibility is to require a programmer supply a conversion function +double (3) (Modula2)