1 / 33

Compiler Design: Scanning, Parsing, and Code Generation

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.

eferguson
Télécharger la présentation

Compiler Design: Scanning, Parsing, and Code Generation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Run-Time Storage Organization

  3. 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

  4. 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.

  5. Stack Allocation (Cont’d.)

  6. Stack Allocation (Cont’d.)

  7. 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.

  8. Stack Allocation (Cont’d.)

  9. Stack Allocation (Cont’d.)

  10. Stack Allocation (Cont’d.)

  11. Stack Allocation (Cont’d.)

  12. Stack Allocation (Cont’d.)

  13. Stack Allocation (Cont’d.)

  14. Stack Allocation (Cont’d.)

  15. Stack Allocation (Cont’d.)

  16. Stack Allocation (Cont’d.)

  17. Heap Allocation

  18. Heap Allocation (Cont’d.) • Three methods for deallocation • No deallocation • Explicit deallocation

  19. Heap Allocation (Cont’d.)

  20. Program Layout in Memory

  21. Program Layout in Memory (Cont’d.)

  22. Static and Dynamic Chains

  23. Static and Dynamic Chains (Cont’d.)

  24. Formal Procedures

  25. Formal Procedures (Cont’d.)

  26. Formal Procedures (Cont’d.)

  27. Formal Procedures (Cont’d.)

  28. Formal Procedures (Cont’d.)

  29. Formal Procedures (Cont’d.)

  30. Chapter 10 Processing Declarations • Declaration Processing Fundamentals • Action Routines for Simple Declarations • Action Routines for Advanced Features

  31. 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

  32. Chapter 12 Translating Control Structures • if Statements • loops • while loops • for loops • The case Statement • Short-circuit Boolean Expressions

  33. Chapter 13 Translating Procedures and Functions • Simple Subprograms • Passing Parameters to Subprograms • Processing Subprogram Calls and Parameter Lists • Subprogram Invocation

More Related