(1.1.2)--Samuel's Ch1编译原理与实践英文版.ppt
《(1.1.2)--Samuel's Ch1编译原理与实践英文版.ppt》由会员分享,可在线阅读,更多相关《(1.1.2)--Samuel's Ch1编译原理与实践英文版.ppt(30页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Chapter 1 Chapter 1 Introduction Introduction Bootstrapping and PortingBootstrapping and PortingThere is a strong interaction between the algorithms used by the phases of a compiler and the data structures that support these phases.Algorithms need to be implemented in efficient manner.The choice of
2、data structures is importantCompilerS2Major Data Structures in CompilerMajor Data Structures in CompilerCompilerS3Temporary FilesTemporary FilesIntermediate CodeIntermediate CodeThe Literal TableThe Literal TableThe Symbol TableThe Symbol TableThe Syntax TreeThe Syntax TreeTokensTokensData Structure
3、sData StructuresWhen a scanner collects characters into a token,it represents the token symbolically as a value of an enumerated data type representing a set of tokens of the source languageSometimes,it is necessary to preserve the character string itself or other information derived from itThe name
4、 associated with an identifier tokenThe value of a number tokenIn most languages the scanner needs to generate one token at a time(single symbol single symbol lookaheadlookahead)A single global variable can be used to hold the token information.CompilerS4TokensTokensThe syntax tree is constructed as
5、 a standard pointer-based structure that is dynamically allocated as parsing proceeds.The tree can be kept as a single variable pointing to the root node.Each node is a record.Its fields represent the information collected by the parser and the semantic analyzer.Sometimes these fields are dynamicall
6、y allocatedCompilerS5The Syntax TreeThe Syntax TreeThis data structure keeps information associated with identifiers,functions,variables,constants,and data types.The symbol table interacts with almost every phase of the compiler.The insertion,deletion access operations need to be efficient.A standar
7、d data type for this purpose is the hash table.CompilerS6The Symbol TableThe Symbol TableStores constants and strings used in the program.Quick insertion and lookup are essential.Need not allow deletions.CompilerS7The Literal TableThe Literal TableDepending on the kind of intermediate code,it may be
8、 kept as An array of text stringsA temporary text fileLinked list of structuresCompilerS8Intermediate CodeIntermediate CodeComputers did not possess enough memory for an entire program to be kept in memory during compilation.This was solved by using temporary files to hold the products of intermedia
9、te steps.Memory constrains are now much smaller problem.Occasionally,compilers generate intermediate files during some of the steps.CompilerS9Temporary FilesTemporary FilesPasses Language DefinitionError HandlingCompilerS10Other Issues in Compiler StructureOther Issues in Compiler StructureA compile
10、r often processed the entire source program several times before generating code.These repetitions are referred as passespasses.Passes may or may not correspond to phases.Depending on the language,a compiler may be one pass.Efficient compilation,but not efficient target code.Examples:Pascal and C.Mo
11、st compilers with optimizations use more than one pass:1.Scanning and parsing2.Semantic analysis and source-level optimization3.Code generation and target code optimizationCompilerS11Passes Passes The description of the lexical,syntactic,and semantics of a programming language is collected in a lang
12、uage reference manuallanguage reference manual,or language definitionlanguage definition.With a new language,a language definition and compiler are often developed together.More common situation is when a compiler is written for well-known language which has an existing language definition.CompilerS
13、12Language DefinitionLanguage DefinitionOne of the most important functions of a compiler.Errors can be detected during almost every phase of compilation.Error reported by a compiler are static(or static(or compile-time)errorscompile-time)errors.It is important to generate meaningful error messages.
14、Error handlerError handler contains different operations for a specific compiler phase and situationCompilerS13Error HandlingError HandlingThe implementation(or hosthost)language has to be machine language.This was how the first compilers were written.Another approach is to write the compiler in ano
15、ther language for which a compiler already exists.We need only to compile the new compiler using the existing compiler to get a running program.What if the existing compiler runs on a machine different from the target machine?Compilation produces a cross compilercross compiler a compiler that genera
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 1.1.2-Samuel's Ch1编译原理与实践英文版 1.1 Samuel Ch1 编译 原理 实践 英文
限制150内