【文章內(nèi)容簡(jiǎn)介】
proc(typeexps) typeexp typeexps typeexps , typeexp | typeexp Compiler Theory Fall 2021 Jianhui Yue Example 1 (cont) record x: pointer to real。 y: array [10] of int end record var (x) var (y) pointer real array (10) int Compiler Theory Fall 2021 Jianhui Yue Structural Equivalence ? The only one available in the absence of names for types. ? Two types are the same if and only if they have the same structure. ? If syntax trees are used to represent types, two types are the same if and only if they have syntax trees that are identical in structure. ? Two array are not equivalent unless they have the same size and ponent type. ? Two records are not equivalent unless they have the same ponents with the same name and the same order. ? . Compiler Theory Fall 2021 Jianhui Yue Type expressions with type declarations. vardecls vardecls 。 vardecl | vardecl vardec id: simpletypeexp typedecls typedecls 。 typedecl | typedecl typedecl id = typeexp typeexp simpletypeexp | structtype simpletypeexp simpletype | id simpletype int | bool | real | char | void structtype array [num] of typeexp | record vardecls end | pointer to typeexp | proc(typeexps) typeexp typeexps typeexps , simpletypeexp | simpletypeexp Example 2 Example 2 Compiler Theory Fall 2021 Jianhui Yue Example 2 (cont) record x: pointer to real。 y: array [10] of int end t1 = pointer to real。 t2 = array [10] of int t3 = record x: t1 y: t2 end Compiler Theory Fall 2021 Jianhui Yue Name Equivalence ? Two type expressions are equivalent if and only if they are either the same simple type or are the same type name. ? t1 and t2 are not equivalent. ? Actual type names are entered into the symbol table. ? It is possible to retain structural equivalence . – When a name is encountered, its corresponding type expression m