CPSC 388 – Compiler Design and Construction

Download Report

Transcript CPSC 388 – Compiler Design and Construction

CPSC 388 – Compiler Design
and Construction
Midterm Review
History and Basics of Programming
Languages









Advances in Programming languages
Imperative and Declarative Languages
Static/Dynamic Distinction
Environments and States
Static Scope and Block Structure
Explicit Access Control
Dynamic Scope
Parameter Passing
Aliasing
Software
 Make
 JLex
 Java_cup
 Java
 Javac
Structure of Compiler
 Compilers Translate Source Language to Target
Language
 Compilers have several steps
 Scanner
 Parser
 Semantic Analyzer
 Intermediate Code Generator
 Optimizer
 Code Generator
 Symbol Table Used To Keep Track of Names Used in
Program
 Front End and Back End Simplify Compiler Design
 Introduction of new languages
 Introduction of new hardware
Scanning
 General: what does a scanner do; how does
it fit into the design of a compiler?
 Underlying Model: Finite-State Machines
 Implementing a Scanner using a transition
table
 Specification of a scanner:
 Regular Expressions
 JLex Specifications
Finite State Machines
 Deterministic Finite State Machine
 Non-deterministic Finite State
Machine
 Conversion from NFA to DFA
Regular Expressions, Regular
Definitions, and JLex
 Syntax and semantics of RE
 Base operators and extended operators
 Character Classes
 Conversion from RE to NFA
 JLex specification




Use of RE
Associated Action
Macros
Matching rules
Context-Free Grammars
 Leftmost, Rightmost derivations
 Parse Trees
 Expression Grammars
 Precedence
 Associativity
 List Grammars
 Ambiguous Grammars
 Recursive Grammars (left recursive, right
recursive)
Syntax-Directed Translation
 “plain” translations
 Writing rules of the form S1.trans=…
 Java_cup translations
 Using “:xx” to name the translation
associated with a symbol defining
translations by assigning to RESULT
Parsing, LL(1) and LALR(1)
grammars
 General: what does a parser do; how does
it fit into the design of a compiler?
 Top-Down Parsing
 predictive parsing (using a stack and a parse
table)
 left factoring
 removing left recursion
 First and Follow sets (how to compute and why
they are important)
 building the parse table
Textbook Sections Covered
 Chapter 1 Introduction
 Chapter 3 Lexical Analysis
 3.1, 3.3, 3.6, 3.7.1, 3.7.4
 Chapter 4 Syntax Analysis
 4.1, 4.2, 4.3, 4.4, 4.8,
 Chapter 5 Syntax-Directed Translation
 5.1, 5.2, 5.3