【正文】
ew Simple Data Types ? In some programming languages it is possible to define new simple types. ? typedef enum {red, green, blue} Color。 Compiler Theory Fall 2021 Jianhui Yue Structured Types ? Given a set of predefined types, new data types can be created using type constructors, such as array and struct . ? Such types are often called structured types. ? Arrays are monly allocated contiguous storage from smaller to larger indexes. Compiler Theory Fall 2021 Jianhui Yue Type Definitions ? Type definitions provides a mechanism to assign names to type expressions. ? Example: ? Type declarations cause the declared type names to be entered into the symbol table. ? Type names are associated with attributes (like scope) in the symbol table. typedef struct { double r。 int i。 } RealIntRec。 RealIntRec x。 Compiler Theory Fall 2021 Jianhui Yue Recursive Data Types ? Recursive data types include lists, trees, and other structures. ? Languages may or may not permit the direct use of recursion in type declarations. ? C allows recursion only indirectly, through pointers. struct intBST { int val。 intBST *left, *right。 }。 Compiler Theory Fall 2021 Jianhui Yue Type Equivalence ? Are two type expressions equivalent? bolean typeEqual ( TypeExp t1, TypeExp t2) – Takes two type expressions – Returns true, if they represent the same type according to the type equivalence rules of the language. – Returns false, otherwise ? How are type expressions are within a piler? – One method is to syntax tree representation. Compiler Theory Fall 2021 Jianhui Yue Example 1 ? Simple grammar for type expressions. ? No new type names are allowed. vardecls vardecls 。 vardecl | vardecl vardec id: typeexp typeexp simpletype | structtype simpletype int | bool | real | char | void structtype array [num] of typeexp | record vardecls end | pointer to typeexp |