【正文】
piler Theory Fall 2021 Jianhui Yue Data Type ? Data type is set of values with certain operations on those values. ? Example: – integer refers to a subset of the mathematical integers, together with the arithmetic operations that are provided by the language definition. ? Data types are described by a type expressions, which is – A type name (such as integer) or – A structured expressions (such as array[10] ) – Operations are assumed or implied Compiler Theory Fall 2021 Jianhui Yue Type Expressions ? Type expressions can occur in several places in a program. ? Explicit type information – int x。 associates a type to a variable name – class Car { …} – defines a new type name ? Implicit type information – const greeting = “Hello!”。 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。 } RealIntRec。 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。 }。 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 | proc(typee