Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3f9a0c9
test
nhogan11 Jul 2, 2012
cd097a8
erge branch 'master' of github.com:nhogan11/CompilerDesign
nhogan11 Jul 25, 2012
63b6f1c
Merge branch 'master' of https://github.com/lawrancej/CompilerDesign
nhogan11 Jul 25, 2012
847ae14
Update textbook/03-parsing.md
nhogan11 Jul 25, 2012
241b7e9
Extended introduction, "filler text" and parsing
nhogan11 Jul 25, 2012
b4bb432
Testing
nhogan11 Jul 25, 2012
c553621
Update textbook/08-code-generation.md
nhogan11 Jul 25, 2012
8feb77b
Update textbook/08-code-generation.md
nhogan11 Jul 25, 2012
255f111
Organized Chapter 8, added headings
nhogan11 Jul 25, 2012
8bf8cc5
Added headings and general formatting
nhogan11 Jul 25, 2012
f170994
Added headings and general formatting
nhogan11 Jul 25, 2012
1fcaf46
Added headings and general formatting
nhogan11 Jul 25, 2012
5fa646e
Added headings and general formatting
nhogan11 Jul 25, 2012
996f7dc
Added headings and general formatting
nhogan11 Jul 25, 2012
fdc177a
Added headings and general formatting
nhogan11 Jul 25, 2012
7eff3db
Added headings and general formatting
nhogan11 Jul 25, 2012
a5704cf
Added headings and general formatting
nhogan11 Jul 25, 2012
72cb00a
Added headings and general formatting
nhogan11 Jul 25, 2012
1906c67
Added headings and general formatting
nhogan11 Jul 27, 2012
68c75ea
Added headings and general formatting
nhogan11 Jul 27, 2012
41ab272
Added headings and general formatting
nhogan11 Jul 27, 2012
e8cd3ce
Added headings and general formatting
nhogan11 Jul 27, 2012
b410086
Added headings and general formatting
nhogan11 Jul 27, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions textbook/01-overview.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

\pagebreak

<!---
DO NOT REMOVE THIS COMMENT OR TOPICS LISTED HERE.

Expand Down Expand Up @@ -53,10 +50,42 @@ TOPICS:
1.2.2.2.1.3 Code Generation
-->

Introduction
============

## Overview
#Overview

##1.1 Introduction
###1.1.1 Definition of a Compiler
###1.1.2 History and Purpose
####1.1.2.1 Grace Hopper
####1.1.2.2 Purpose
#####1.1.2.2.1 Translate Source Language to Target Language
#####1.1.2.2.2 Object Code and Executables
#####1.1.2.2.3 Platform Independent Compilers
###1.1.3 Comparison between Compiler and Interpreter
###1.1.4 Hardware Compilation
##1.2 Compiler Design
###1.2.1 One-Pass vs Multi-Pass
####1.2.1.1 One Pass
#####1.2.1.1.1 Simple to Implement
#####1.2.1.1.2 Limited Optimization
####1.2.1.2 Multi-Pass
#####1.2.1.2.1 Enhanced Optimization
#####1.2.1.2.2 Easier to Prove Correctability
#####1.2.1.2.3 Source-to-Source Compilation Possible (Translators)
#####1.2.1.2.4 Source-Bytecode-Native Code
###1.2.2 Structure
#####1.2.2.1 Front End
#####1.2.2.1.1 Create Intermediate Representation
#####1.2.2.1.2 Manages Symbol Table
#####1.2.2.1.3 Steps
######1.2.2.1.3.1 Preprocessing
######1.2.2.1.3.2 Lexical Analysis
######1.2.2.1.3.3 Syntax Analysis
######1.2.2.1.3.4 Semantic Analysis
####1.2.2.2 Back End
#####1.2.2.2.1 Steps
######1.2.2.2.1.1 Analysis
######1.2.2.2.1.2 Optimization
######1.2.2.2.1.3 Code Generation

### What is a compiler?
<!---
Expand Down
30 changes: 26 additions & 4 deletions textbook/02-lexical-analysis.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

\pagebreak

<!---
Expand Down Expand Up @@ -42,12 +41,35 @@ TOPICS:
2.2.4.2 Produces a Value
-->

Lexical Analysis
================
### What is a regular language?
#Lexical Analysis

##2.1 Grammars
[Regular expressions](#what-is-a-regular-expression) define the regular languages.
[Regular grammars](#what-is-a-regular-grammar) and [finite automata](#what-is-a-finite-automaton) recognize regular languages.

###2.1.1 Defined in Language Specification
###2.1.2 Tokens and Lexemes
####2.1.2.1 Defined in Specification
####2.1.2.2 Described Set of Valid Character Sequences
##2.2 Components
###2.2.1 Tokens
####2.2.1.1 Structured Text
####2.2.1.2 Categorized
####2.2.1.3 Example
#####2.2.1.3.1 int x = 3;
#####2.2.1.3.2 Tokens
######2.2.1.3.2.1 int (variable type)
######2.2.1.3.2.2 x (variable)
######2.2.1.3.2.3 = (operator)
######2.2.1.3.2.4 3 (value)
###2.2.2 Tokenizer
###2.2.3 Scanner
####2.2.3.1 Finite State Machine
####2.2.3.2 Contains Information What Constitutes a Valid Token
###2.2.4 Evaluator
####2.2.4.1 Works with Lexemes
####2.2.4.2 Produces a Value

#### Follow-up questions
- [What is a regular expression](#what-is-a-regular-expression)?
- [How can you tell if a language is regular](#how-can-you-tell-if-a-language-is-regular)?
Expand Down
83 changes: 43 additions & 40 deletions textbook/03-parsing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

\pagebreak

>TODO : The next step of the compilation process is parsing.
Parsing takes input from the Lexical Analysis step and builds a parse tree, which will be used in future steps to develop the machine code.
In this unit, we will define parsing and identify its uses.
Expand Down Expand Up @@ -54,71 +51,77 @@ TOPICS:
3.3.2.2 Combine Terminal Symbol to Produce Nonterminals
-->

Parsing
=======

### 3.1 Parsing Overview
Syntax Analysis also known as parsing is the process of analyzing tokens and
recombining them into a syntax tree.
#Parsing

## 3.1 Parsing Overview
The concept of parsing has been around since the advent of written language millenia ago. More formally known as syntactic analysis, parsing is the process of analyzing tokens in order to
determine its grammatical structure. While it is used to diagram languages such as Latin, it also has extremely important implications for computing.
Compilers and interpreters use syntactic analysis to make sense of all programming languages, and without it there would be no internal representation of a given language.
While we take parsing for granted, it is a vital part of any computing system.

#### 3.1.1 Function
Syntax analysis will verify that the input`s syntax is valid.
### 3.1.1 Function
Syntactic analysis will verify that the input`s syntax is valid.

#### 3.1.1.1 Input: Tokens from Lexical Analysis
Lexical analysis splits input into tokens which the syntax analyzer then recombines into a syntax tree.

##### 3.1.1.1 Input: Tokens from Lexical Analysis
Lexical analysis splits input into tokens which the syntax analyzer then
recombines into a syntax tree.
#### 3.1.1.2 Output: Program Parse Tree
Recombining of a syntax parse tree during lexical analysis is done according to the syntax specification.
The leaves of the parse tree are the tokens generated during lexical analysis.

##### 3.1.1.2 Output: Program Parse Tree
Recombining of a syntax parse tree during lexical analysis is done according to
the syntax specification.
The leaves of the parse tree are the tokens generated
during lexical analysis.
### 3.1.2 Examples

#### 3.1.2 Examples
#### 3.1.2.1 Given an Arbitrary Function

##### 3.1.2.1 Given an Arbitrary Function
#### 3.1.2.2 Produce:

##### 3.1.2.2 Produce:
##### 3.1.2.2.1 Parser Input

###### 3.1.2.2.1 Parser Input
##### 3.1.2.2.2 Parse Tree

###### 3.1.2.2.2 Parse Tree
### 3.1.3 Context-Free Grammar

#### 3.1.3 Context-Free Grammar
## 3.2 Top-Down Parsing
A parser can determine the derived input of a language in two ways. The first of these ways is known as top-down parsing.
In top-down parsing, tokens are read from left to right. The parse tree is traversed from the highest level (top-down).

### 3.2 Top-Down Parsing
### 3.2.1 Traversing a Parse Tree
Not surprisingly, the parse tree is traversed from the top down in top-down parsing.

#### 3.2.1 Traversing a Parse Tree
#### 3.2.1.1 Definition

##### 3.2.1.1 Definition
#### 3.2.1.2 Example
LL parsers are examples of top-down parsing (diagram here?)

##### 3.2.1.2 Example
### 3.2.2 Backus-Naur Form Production Rules

#### 3.2.2 Backus-Naur Form Production Rules
### 3.2.3 LL Parser

#### 3.2.3 LL Parser
### 3.2.4 Process

#### 3.2.4 Process
#### 3.2.4.1 Starts at Left-most Symbol Yielded from Production Rule

##### 3.2.4.1 Starts at Left-most Symbol Yielded from Production Rule
#### 3.2.4.2 Continues to Next Production Rule for Each Non-Terminal Symbol

##### 3.2.4.2 Continues to Next Production Rule for Each Non-Terminal Symbol
#### 3.2.4.3 Proceeds "Down" the Parse Tree

##### 3.2.4.3 Proceeds "Down" the Parse Tree
## 3.3 Bottom-Up

### 3.3.1 Bottom-Up Parsing
The second method of parsing is known as bottom-up parsing. Using this method, a parser begins with the input and makes
an attempt to identify the simplest elements of the language by working backwards.

##### 3.3.1.1 Definition

##### 3.3.1.2 Examplel
#### 3.3.1.1 Definition

#### 3.3.1.2 Examplel
LR parsers are examples of bottom-up parsing. (diagram here?)
#### 3.3.2 Process

##### 3.3.2.1 Identify Terminal Symbols First
#### 3.3.2.1 Identify Terminal Symbols First

#### 3.3.2.2 Combine Terminal Symbol to Produce Nonterminals


##### 3.3.2.2 Combine Terminal Symbol to Produce Nonterminals


### What is a context-free language?
Expand Down
17 changes: 14 additions & 3 deletions textbook/04-ast-and-symbol-tables.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

\pagebreak

<!---
DO NOT REMOVE THIS COMMENT OR TOPICS LISTED HERE.

Expand Down Expand Up @@ -30,6 +27,20 @@ TOPICS:
5.2.2.3.1 Used by Linker to Resolve References
5.2.2.3.2 Kept in Object Files for Debug Builds
-->
#Ast and Symbol Tables

##5.2 Symbols
###5.2.1 Definition
###5.2.2 Symbol Table
####5.2.2.1 Gives Information about an Identifier
#####5.2.2.1.1 Declaration Information
#####5.2.2.1.2 Scope
#####5.2.2.1.3 Type
#####5.2.2.1.4 Memory Address
####5.2.2.2 Implemented as a Hash Table
####5.2.2.3 Contained within the Object File
#####5.2.2.3.1 Used by Linker to Resolve References
#####5.2.2.3.2 Kept in Object Files for Debug Builds

Abstract Syntax Trees and Symbol Tables
=======================================
Expand Down
35 changes: 28 additions & 7 deletions textbook/05-semantic-analysis.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

\pagebreak

<!---
DO NOT REMOVE THIS COMMENT OR TOPICS LISTED HERE.

Expand Down Expand Up @@ -46,10 +43,34 @@ TOPICS:
4.3 Time/Space Complexity

-->


Semantic Analysis
=================
#Semantic Analysis
##4.1 Overview
###4.1.1 Relation to Parse Tree
####4.1.1.1 Input from Parser
####4.1.1.2 Adds Semantic Information to Parse Tree
###4.1.2 Output to Code Generation Phase
##4.2 Process
###4.2.1 Type Checking
####4.2.1.1 Verify Type Constraints
####4.2.1.2 Static Checking
#####4.2.1.2.1 Done at Compile Time
#####4.2.1.2.2 Dynamic Checking Done at Runtime
#####4.2.1.2.3 Example Languages
######4.2.1.2.3.1 Ada
######4.2.1.2.3.2 C++
######4.2.1.2.3.3 Java
####4.2.1.3 Type Safety
####4.2.1.4 Types Specified by the Language Specification
###4.2.2 Object Binding
####4.2.2.1 Associates Variable with its Definition
####4.2.2.2 Resolve Object References
###4.2.3 Assignment Operations
####4.2.3.1 Data Flow Analysis
####4.2.3.2 Definite Assignment Analysis
#####4.2.3.2.1 Ensures Variable are Assigned Before Used
#####4.2.3.2.2 Allows Potential Optimization
###4.2.4 Produce Errors/Warnings
##4.3 Time/Space Complexity

### What is semantics?
<!---
Expand Down
26 changes: 23 additions & 3 deletions textbook/06-intermediate-representation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

\pagebreak

<!---
DO NOT REMOVE THIS COMMENT OR TOPICS LISTED HERE.

Expand Down Expand Up @@ -40,6 +37,29 @@ TOPICS:
5.3.2.1 Debugging vs Release
5.3.2.2 Runtime Exceptions
-->
#Intermediate Representation
##5.1 Types
###5.1.1 Types of Types
####5.1.1.1 Primitive
####5.1.1.2 Reference
####5.1.1.3 Null
####5.1.1.4 Object
####5.1.1.5 Function
###5.1.2 Type Checking
####5.1.2.1 Static Typing
####5.1.2.2 Dynamic Typing
####5.1.2.3 Strong Typing
####5.1.2.4 Weak Typing
##5.3 Runtime Organization
###5.3.1 Storage
####5.3.1.1 Allocation
#####5.3.1.1.1 Static
#####5.3.1.1.2 Dynamic
####5.3.1.2 Local references
####5.3.1.3 Global References
###5.3.2 Runtime
####5.3.2.1 Debugging vs Release
####5.3.2.2 Runtime Exceptions

###### Types

Expand Down
49 changes: 46 additions & 3 deletions textbook/07-optimization.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

\pagebreak

<!---
Expand Down Expand Up @@ -67,11 +66,55 @@ This means that the code will run more quickly and use up less resources than it

Optimization
============

### What is optimization?
###7.1 Overview
Optimization is the penultimate [compiler phase](#what-are-the-phases-of-a-compiler).
Optimizers improve code performance, size, and efficiency toward an optimum.

####7.1.1 Manipulate Execution Parameters to Maximize Performance
#####7.1.1.1 Program Runtime
#####7.1.1.2 Memory Footprint
####7.1.2 Complexity
#####7.1.2.1 Many Optimizations Are NP-Complete
#####7.1.2.2 Memory Major Limitation in Other
####7.1.3 Effectiveness
#####7.1.3.1 What is the Target Architecture?
######7.1.3.1.1 The Machine on which the Program Will Run
######7.1.3.1.2 What are the Factors that affect Effectiveness?
######7.1.3.1.2.1 What are CPU Registers?
######7.1.3.1.2.2 What is Pipelining?
######7.1.3.1.2.3 What is a Cache?
######7.1.3.1.2.4 What is Hardware Design?
#####7.1.3.2 Host Architecture
######7.1.3.2.1 The Machine Doing the Compilation
######7.1.3.2.2 Factors
######7.1.3.2.2.1 CPU Speed
######7.1.3.2.2.2 Pipelining
######7.1.3.2.2.3 Memory Capacity and Architecture
######7.1.3.2.3 Program Usage
######7.1.3.2.4 Release vs Debugging
######7.1.3.2.4.1 Release Is Often Optimized for Performance
######7.1.3.2.4.2 Debug Program Contain Debugging Symbols which Slow the Execution
###7.2 Optimization Categories
Optimization is the process of modifying a software to make an aspect of it work more efficiently.
This means that the code will run more quickly and use up less resources than it already does.
####7.2.1 Peephole
####7.2.2 Local
####7.2.3 Loop
#####7.2.3.1 Act upon Loops
#####7.2.3.2 Potentially High Impact
#####7.2.3.3 Reduce Dependence on Memory and Time-intensive Looping
####7.2.4 Language Dependent
#####7.2.4.1 Optimize Functions Unique to a Specific Language
#####7.2.4.2 Some Optimizations May Be General across Multiple Languages
####7.2.5 Machine Dependent
###7.3 Optimization Techniques
####7.3.1 Exploit Properties of the "Common Case"
####7.3.2 Reduce Redundancy
####7.3.3 Reduce Branching
####7.3.4 Parallelize Operations When Available
####7.3.5 Maximize Memory Efficiency
####7.3.6 Decrease Special Memory Reference Distance

#### Example optimizations:

- [Peephole optimization](#what-is-peephole-optimization)
Expand Down
Loading