1 contents. 2 run-time storage organization 3 static allocation in many early languages, notably...
Post on 22-Dec-2015
220 views
TRANSCRIPT
1
ContentsContents
IntroductionIntroduction A Simple CompilerA Simple Compiler Scanning – Theory and PracticeScanning – Theory and Practice Grammars and ParsingGrammars and Parsing LL(1) ParsingLL(1) Parsing Lex and yaccLex and yacc LR ParsingLR Parsing Semantic ProcessingSemantic Processing Symbol TablesSymbol Tables Run-time Storage OrganizationRun-time Storage Organization Code Generation and Local Code OptimizationCode Generation and Local Code Optimization Global OptimizationGlobal Optimization
3
Static AllocationStatic Allocation
In many early languages, notably assembly In many early languages, notably assembly and FORTRAN, all storage allocation is and FORTRAN, all storage allocation is static.static.
Space for data objects is allocated in a fixed Space for data objects is allocated in a fixed location for the lifetime of a program.location for the lifetime of a program.
The number and size of all objects to be The number and size of all objects to be allocated is known at compile-time.allocated is known at compile-time.
Static allocation is used both for global Static allocation is used both for global variables and constants.variables and constants.
Static allocation is also used for local Static allocation is also used for local variables, e.g., static and extern in C variables, e.g., static and extern in C
DisadvantageDisadvantage Wasteful of spaceWasteful of space
4
Stack Allocation Stack Allocation (Cont’d.)(Cont’d.)
Recursive procedures, a feature that requires Recursive procedures, a feature that requires dynamic allocation.dynamic allocation.
Each recursive call requires the allocation of Each recursive call requires the allocation of a new copy of a procedure’s local variables.a new copy of a procedure’s local variables. The number of data objects required during The number of data objects required during
program execution is not known at compile-time.program execution is not known at compile-time. Activation record (AR)Activation record (AR)
An AR is used to store all the data space required An AR is used to store all the data space required for a procedure or function.for a procedure or function.
An AR is pushed onto a run-time stack when the An AR is pushed onto a run-time stack when the procedure or function is calledprocedure or function is called
When is subporgram returns, the AR is popped.When is subporgram returns, the AR is popped.
7
Stack Allocation Stack Allocation (Cont’d.)(Cont’d.)
Dynamic arraysDynamic arrays The bounds of dynamic arrays are determined at The bounds of dynamic arrays are determined at
run-time rather than compile-time, hence these run-time rather than compile-time, hence these arrays cannot be allocated within an AR.arrays cannot be allocated within an AR.
Dynamic arrays can be allocated as soon as their Dynamic arrays can be allocated as soon as their associated declarations are elaborated.associated declarations are elaborated.
18
Heap Allocation Heap Allocation (Cont’d.)(Cont’d.)
Three methods for deallocationThree methods for deallocation No deallocationNo deallocation Explicit deallocationExplicit deallocation
30
Chapter 10 Processing DeclarationsChapter 10 Processing Declarations
Declaration Processing FundamentalsDeclaration Processing Fundamentals Action Routines for Simple DeclarationsAction Routines for Simple Declarations Action Routines for Advanced FeaturesAction Routines for Advanced Features
31
Chapter 11 Processing Expressions and Chapter 11 Processing Expressions and Data Structure ReferencesData Structure References Action Routines for Simple Names, Action Routines for Simple Names,
Expressions, and StructuresExpressions, and Structures Array References and RecordsArray References and Records
Action Routines for Advantage FeaturesAction Routines for Advantage Features
32
Chapter 12 Translating Control StructuresChapter 12 Translating Control Structures
if Statementsif Statements loopsloops
while loopswhile loops for loopsfor loops
The case StatementThe case Statement Short-circuit Boolean ExpressionsShort-circuit Boolean Expressions
33
Chapter 13 Translating Procedures and Chapter 13 Translating Procedures and FunctionsFunctions
Simple SubprogramsSimple Subprograms Passing Parameters to SubprogramsPassing Parameters to Subprograms Processing Subprogram Calls and Parameter Processing Subprogram Calls and Parameter
ListsLists Subprogram InvocationSubprogram Invocation