编译原理与实践(中英双语版)下ppt224

上传人:jiups****uk12 文档编号:46059679 上传时间:2018-06-21 格式:PPT 页数:224 大小:2.67MB
返回 下载 相关 举报
编译原理与实践(中英双语版)下ppt224_第1页
第1页 / 共224页
编译原理与实践(中英双语版)下ppt224_第2页
第2页 / 共224页
编译原理与实践(中英双语版)下ppt224_第3页
第3页 / 共224页
编译原理与实践(中英双语版)下ppt224_第4页
第4页 / 共224页
编译原理与实践(中英双语版)下ppt224_第5页
第5页 / 共224页
点击查看更多>>
资源描述

《编译原理与实践(中英双语版)下ppt224》由会员分享,可在线阅读,更多相关《编译原理与实践(中英双语版)下ppt224(224页珍藏版)》请在金锄头文库上搜索。

1、编译原理与实践Compiler Principle and Implementation中英双语版张菁 著 / 黄维通 Baikunth nath 审 Chapter 6 Symbol Table Manager and Type Checking Zhang Jing, Wang HaiLing College of Computer Science x, y: real;Its symbol table is Name Kind Address i int 100j int 102x real 104y real Example 6.3 nThe definition of procedu

2、re is:Procedure Max;Var h , l: integer;n2 in size attribute means there are two parameters in the procedureName Kind Level Address SizeMaxHlP6.3 The Design of Symbol TablenThis section, we begin to discuss the storage and the scope of symbols in various parts of a program. Then we study how to desig

3、n the structure of a symbol attribute in local symbol table. . nIn order to obtain high running efficient and save the storage of symbol table, we should take into account a lot of things. Firstly, what are the features of program language? How many parts are in program? Which one should be checked

4、by semantic? Secondly, we should discuss the running environment, , nfor example, target machine performance, what kind of target code it will produce. Thirdly, we should think of the operation system that offer the way of storage and management. Finally, how many passes and how many tables accordin

5、g to the passes we should pay attention to. To sum up, if we want to design a symbol table, we should take all those elements into account in order to build a reasonable symbol table. . nThere are two steps to build the symbol table:(1)Build the attribute of symbol table. (2)Design the organization

6、of symbol table. The first one we will discuss in this section, the second one would be introduced in next section. In the part of attribute of symbol table, we mainly introduce the attribute of name, attribute of type and the identifier of array type. (1)The attribute of name nThere are three ways

7、to store identifiers name in symbol table. nthe first way is shown by Table 6.1, it means we put the name with all letters in name attribute, the name length is 10 that is a definite. nThe second way is expressed in Fig 6.1(a), letters of name are stored in chain table, namely, in name attribute the

8、re are length of the name and the name address of connect table. nThe third way is denoted by Fig.6.1(b), you can only see name address in name attribute, the name length and name letters are written in its chain table. . nIf a length of identifiers name is 2 bites, using symbol table in first way t

9、o store it needs 8 bites, on the other hand storing it by symbol table in second or third way would save the space, but it spends a lot of searching time. Totally, using which way is up to you. . (2)The attribute of typenThere are also three ways to represent the type attribute. . nThe first way is

10、putting the type directly into the type attribute, shown in Table 6.1. . nThe second way is creating a 4 bites table that is shown in Fig. 6.2, the first bite in Table 6.2 is 1, the type is integer, the second bite is 1, it is real, the third bite 1 means logic type and fourth one represent characte

11、r type. . nThe third way to store the type is shown in Fig 6.3, in this way, there are only three bites that can represent the four bites type by the second way. (3)Array type in symbol tablenDifferent identifier need different attribute to store its information. nfor example, an identifier of array

12、 type needs to be described its dimension, scope etc., a procedure identifier should save the number of its parameters, their type if they are recursive. We often use chain table to store some special attributes and the chain table address would be as an attribute in symbol table. . 6.4 The Structur

13、e of Symbol Table n6.4.1. The operation of symbol table nThe operation of symbol table includes search, find, insert, deleting and update. nAs a structure definition program, there are two ways to do the operation: (1) If a symbol table is unordered, the operation of insert is simple.nBecause it does not need to find a definite insert position, but it should be searched in the symbol table to be sure if there is no same symbol, the running time of search is not little. . (2) If a symbol table is ordered, we

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号