330 likes | 340 Views
This comprehensive guide covers the theory and practice of scanning, parsing, and code generation in compiler design. Topics include LL(1) parsing, lex and yacc, semantic processing, symbol tables, run-time storage organization, and global optimization. It also explores static and stack allocation, heap allocation, program layout in memory, and processing declarations, expressions, control structures, and subprograms.
E N D
Contents • Introduction • A Simple Compiler • Scanning – Theory and Practice • Grammars and Parsing • LL(1) Parsing • Lex and yacc • LR Parsing • Semantic Processing • Symbol Tables • Run-time Storage Organization • Code Generation and Local Code Optimization • Global Optimization
Static Allocation • In many early languages, notably assembly and FORTRAN, all storage allocation is static. • Space for data objects is allocated in a fixed location for the lifetime of a program. • The number and size of all objects to be allocated is known at compile-time. • Static allocation is used both for global variables and constants. • Static allocation is also used for local variables, e.g., static and extern in C • Disadvantage • Wasteful of space
Stack Allocation (Cont’d.) • Recursive procedures, a feature that requires dynamic allocation. • Each recursive call requires the allocation of a new copy of a procedure’s local variables. • The number of data objects required during program execution is not known at compile-time. • Activation record (AR) • An AR is used to store all the data space required for a procedure or function. • An AR is pushed onto a run-time stack when the procedure or function is called • When is subporgram returns, the AR is popped.
Stack Allocation (Cont’d.) • Dynamic arrays • The bounds of dynamic arrays are determined at run-time rather than compile-time, hence these arrays cannot be allocated within an AR. • Dynamic arrays can be allocated as soon as their associated declarations are elaborated.
Heap Allocation (Cont’d.) • Three methods for deallocation • No deallocation • Explicit deallocation
Chapter 10 Processing Declarations • Declaration Processing Fundamentals • Action Routines for Simple Declarations • Action Routines for Advanced Features
Chapter 11 Processing Expressions and Data Structure References • Action Routines for Simple Names, Expressions, and Structures • Array References and Records • Action Routines for Advantage Features
Chapter 12 Translating Control Structures • if Statements • loops • while loops • for loops • The case Statement • Short-circuit Boolean Expressions
Chapter 13 Translating Procedures and Functions • Simple Subprograms • Passing Parameters to Subprograms • Processing Subprogram Calls and Parameter Lists • Subprogram Invocation