CSC 415: Translators and Compilers Spring 2009

Download Report

Transcript CSC 415: Translators and Compilers Spring 2009

CSC 415: Translators and Compilers
Spring 2009
Final Review
Final Exam Review

Final Exam is comprehensive in that:
–
–

Essay questions will cover Chapters 5, 6, 7, 9
Problem oriented questions require knowledge from
the entire semester
Exam Structure
–
Four questions

Two essay questions
–
Discuss
– Describe

– Compare & contrast
– Evaluate
Two problems
–
Develop code template for new language construct
– Determine identification table for given program
– Calculate size and address for given type(s)
Chart 2
Final Exam Review
Chapter 5 – Contextual Analysis

Contextual analysis checks that the program conforms to
the source language’s contextual constraints
–
–

Block Structure
–
–
–

–
–
–
Chart 3
Monolithic
Flat
Nested
Type Checking
–

Scope rules
Type rules
Literal
Identifier
Unary operator application
Binary operator application
Standard Environment
Final Exam Review
Chapter 6 – Run-Time Organization

Key Issues
–
–
–
–

Fundamental Principles of Data Representation
–
–
Chart 4
Data representation
Expression evaluation
Storage allocation
Routines
Non-confusion: different values of a given type should
have different representation
Uniqueness: each value should always have same
representation
Final Exam Review
Chapter 6 – Run-Time Organization

Types
–
Primitive types: cannot be decomposed



–
–
–
–
–

Chart 5
Boolean
Character
Integer
Records
Disjoint unions
Static arrays
Dynamic arrays
Recursive types
For various types be able to determine size (storage
required) and address (how to locate)
Final Exam Review
Chapter 6 – Run-Time Organization

Expression Evaluation
–
–
–
Stack machine
Register machine
Static storage allocation

–
Stack storage allocation

Chart 6
Global variables
Local variables
Final Exam Review
Chapter 7 – Code Generation

Translation of the source program to object code
–

Target Machines
–
–
–
Chart 7
Dependent on source language and target machine
Registers, or stack, or both for intermediate results
Instructions with zero, one, two, or three operands, or a
mixture
Single addressing mode, or many
Final Exam Review
Chapter 7 – Code Generation



Chart 8
Code selection: which sequence of target
machine instructions will be the object code for
each phrase
Storage allocation: deciding the storage address
of each variable in source program
Register allocation: should be used to hold
intermediate results during expression evaluation
Final Exam Review
Chapter 9 – Programming Language Life-Cycle
Design
Specification
Prototype
Compilers
Manuals,
textbooks
Chart 9
Final Exam Review
Chapter 9 – Programming Language Life-Cycle


Strive for simplicity and regularity
Design Principles
–
–
–



Specifications
Prototype
Error Reporting
–
–
Chart 10
Type completeness: no operation should be arbitrarily restricted in
the types of its operands
Abstraction: for phrase that specifies some kind of computation,
should be a way to abstract that phrase and parameterize it
Correspondence: for each form of declaration there should be
corresponding parameter mechanism
Compile-time
Run-time
Final Exam Review
Structure of a Compiler
Lexical
Analyzer
Source code
tokens
Parser
Semantic
Analyzer
Symbol
Table
parse tree
Intermediate Code
Generation
Semantic Analyzer
intermediate representation
Optimization
Identification
intermediate representation
Assembly code
Chart 11
Assembly Code
Generation
Type checking