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

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

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

1、,1,编译原理与实践,Compiler Principle and Implementation,中英双语版,张菁 著 / 黄维通 Baikunth nath 审,Chapter 6 Symbol Table Manager and Type Checking,Zhang Jing, Wang HaiLing College of Computer Science & Technology Harbin Engineering University,,3,some symbols must be collected and be put together into tablesSymbol T

2、able. There are two functions in symbol table, the first one is to help check if the semantic is correct, the second one is to assist generating the code. To sum up, this chapter would introduce the functions, content, structure and operation of symbol table.,,4,6.1 The Functions of Symbol Tables,Th

3、e functions of symbol table are: (1) Store information (2)Types Checking (3) Data Address,,5,Store information: Before store information, we firstly should divided the data into different types, then put them into the corresponded tables. Sometimes information is stored in table during lexical analy

4、sis, sometimes it is done in semantic analysis. . If the data is an identifier, it would be stored in an identifier table,else if the data is a constant, it will be put into a constant table.,,6,Types Checking A compiler uses a symbol table to keep track of the type and binding information about nam

5、es. The symbol table is searched every time by a name that is encountered in the source text. If a new name or new information about an existing name is discovered, the table is changed.,,7,Data Address: When a data was stored, the datas address in the table was also recorded as an attribute of the

6、table. In the period of code generation in compiler, the data address can be obtained from the symbol table and can be used directly. .,,8,6.2 The Attribute of Symbol Table,Symbol table is created according to symbols name, so the keyword of the symbol table is symbols name. Except name attribute, t

7、here are also six attributes of a symbol in symbol table using for semantic checking. .,,9,The six attributes of a symbol as follow:,Attribute of kind Attribute of dimension or size Attribute of parameter Attribute of address Attribute of level in program Attribute of line position in source program

8、,,10,Attribute of kind Kind can describe the characteristics of a symbol. Every symbol has its own type, such as constant, variable and procedure. . Attribute of dimension or size If an identifier is a name of an array, then we should store the dimension and boundary of identifier value as an attrib

9、ute of it. .,,11,Attribute of parameter If an identifier is a name of a procedure, the parameters of the procedure should be recorded as an attribute. . Attribute of address In source program, an identifier or a constant are often related with a unit address to accomplish some operation. So the addr

10、esses of them are put in symbol table as an attribute. .,,12,Attribute of level in program Symbol in program or subprogram, the level of its position in program should be written as an attribute in symbol table. In some source languages, identifiers can have same name in different level of program,

11、so attribute of level in program could help recognize them. . Attribute of line position in source program Sometimes the line position of symbol in source program is needed to be stored as an attribute in symbol table in order to obtain the correct semantic checking. .,,13,Attribute of constant valu

12、e If the symbol is a constant, then the value of it should been stored as a value attribute in symbol table. . Attributes above are not all the attributes a symbol table has, some symbols used for special may has particular attributes. To sum up, the function of symbol table is for checking up if th

13、e semantic in source program is correct.,,14,Example 6.1,The definition of constants is: Const pi=3.14 r=10 Its symbol table is: NameKindValuepireal3.14rint10,Name,pi,r,Kind,real,int,Value,3.14,10,,15,Example 6.2,The definition of variables is: Var i, j: integer; x, y: real; Its symbol table is,,16,

14、Example 6.3,The definition of procedure is: Procedure Max;Var h , l: integer; 2 in size attribute means there are two parameters in the procedure,,17,6.3 The Design of Symbol Table,This section, we begin to discuss the storage and the scope of symbols in various parts of a program. Then we study how to design the structure of a symbol attribute in local symbol table. .,,18,In 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 o

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

当前位置:首页 > 高等教育 > 大学课件

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