【正文】
1 means indirect register addressing ? We assumed that the machine performs byte addressing. ? Integers occupy two bytes of memory. MOV R0, index 。 a identifier [ left bracket index identifier ] right bracket = assignment 4 number + plus sign 2 number The Parser ? Receives the source in form of tokens. ? Performs syntax analysis – determines the structure of the program – similar to performing grammatical analysis on a sentence in natural language. ? The result is represented as a parse tree or a syntax tree. Parse Tree expression assignexpression expression expression = subscriptexpression additiveexpression expression expression expression expression [ ] + identifier a identifier index number 4 number 2 Abstract Syntax Tree An abstract syntax tree is a condensation of the information contained in a parse tree. assignexpression subscriptexpression additiveexpression identifier a identifier index number 4 number 2 The Semantic Analyzer ? The semantics of a program are its “meaning”. ? The semantics of a program determine its runtime behavior. ? Most programming languages have features (called static semantics) that can be determined prior to execution. ? Typical static semantics features – Declarations – Type checking ? The extra information puted by the semantic analyzer are called attributes. – They are added to the tree as annotations, or “decorations” Annotated Tree assignexpression subscriptexpression integer additiveexpression integer identifier a array of integer identifier index integer number 4 integer number 2 integer The Source Code Optimizer ? The earliest point at which optimization steps can be performed is just after semantic analysis. ? There may be possibilities that depend only on the source code. ? Compilers exhibit a wide variation in the kind of optimization and its placement. ? The output of the source code optimizer is the intermediate representation (IR) or intermediate code. Example ? 4 + 2 can be preputed by the piler. – This optimization is known as constant folding. – This optimization can be performed on the annotated syntax tree by collapsing the right hand subtree to its constant value. assignexpression subscriptexpression integer number 6 integer identifier a array of integer identifier index integer The Code Generator ? The code generator takes the intermediate code or IR and generates code for the target machine. – We will write target code in assembly language form. Most pilers generate object code directly. ? The properties of the target machine bee important. – Use instructions of the target machine. – Data representations: how many bytes or words integer and floatingpoint data types occupy in memory. Example ? amp。a 。 value of index R0 SHL R0