From 3f9a0c9e8c084e5cbb85bcaac53e532c8345c42c Mon Sep 17 00:00:00 2001 From: Nicholas Hogan Date: Mon, 2 Jul 2012 10:44:42 -0400 Subject: [PATCH 01/21] test --- textbook/08-code-generation.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index e69de29..16fd0a5 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -0,0 +1,5 @@ +What is code generation? + +Code generation is the final compiler phase. It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. + +The code generator is distinct from the parser and the translator. \ No newline at end of file From 847ae14b5ea7a6698eaefde20de926aabbba3448 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 11:52:03 -0300 Subject: [PATCH 02/21] Update textbook/03-parsing.md Added intoduction, filler text and some facts. --- textbook/03-parsing.md | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/textbook/03-parsing.md b/textbook/03-parsing.md index fca4a68..53f5ca3 100644 --- a/textbook/03-parsing.md +++ b/textbook/03-parsing.md @@ -1,4 +1,3 @@ - \pagebreak >TODO : The next step of the compilation process is parsing. @@ -58,23 +57,20 @@ Parsing ======= ### 3.1 Parsing Overview -Syntax Analysis also known as parsing is the process of analyzing tokens and -recombining them into a syntax tree. - +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. - +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. +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. +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 @@ -84,13 +80,16 @@ during lexical analysis. ###### 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.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.1 Traversing a Parse Tree +Not surprisingly, the parse tree is traversed from the top down in top-down parsing. ##### 3.2.1.1 Definition From 241b7e91331ffce77357d543ad0a80199323feb4 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 11:57:35 -0300 Subject: [PATCH 03/21] Extended introduction, "filler text" and parsing --- textbook/03-parsing.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/textbook/03-parsing.md b/textbook/03-parsing.md index 53f5ca3..68b099c 100644 --- a/textbook/03-parsing.md +++ b/textbook/03-parsing.md @@ -94,7 +94,7 @@ Not surprisingly, the parse tree is traversed from the top down in top-down pars ##### 3.2.1.1 Definition ##### 3.2.1.2 Example - +LL parsers are examples of top-down parsing (diagram here?) #### 3.2.2 Backus-Naur Form Production Rules #### 3.2.3 LL Parser @@ -108,11 +108,13 @@ Not surprisingly, the parse tree is traversed from the top down in top-down pars ##### 3.2.4.3 Proceeds "Down" the Parse Tree ### 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 - +LR parsers are examples of bottom-up parsing. (diagram here?) #### 3.3.2 Process ##### 3.3.2.1 Identify Terminal Symbols First From b4bb432de70dd75eed6b164f124d1435a0bccb26 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:18:57 -0300 Subject: [PATCH 04/21] Testing --- textbook/08-code-generation.md | 125 +++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 45 deletions(-) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index 0db05f2..3f3abfa 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -1,13 +1,9 @@ -<<<<<<< HEAD -<<<<<<< HEAD -What is code generation? Code generation is the final compiler phase. It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. The code generator is distinct from the parser and the translator. ======= ======= -\pagebreak @@ -72,12 +68,51 @@ TOPICS: Code generation =============== +###8.1 Overview +####8.1.1 Produces Machine-Executable Code +####8.1.2 Input Parse Tree +####8.1.3 Output Machine Code +####8.1.4 Includes Some Optimization Techniques +###8.2 Process +####8.2.1 Instruction Selection +#####8.2.1.1 Transforms Middle-Level IR to Low-Level IR +######8.2.1.1.1 Middle Level IR +#######8.2.1.1.1.1 Tree-Based +#######8.2.1.1.1.2 Intermediate Representation +######8.2.1.1.2 Low Level IR +#######8.2.1.1.2.1 Reduced From Tree +#######8.2.1.1.2.2 Close to Target Language (Machine Code) +#####8.2.1.2 Templates and Tiles +######8.2.1.2.1 Tiles +#######8.2.1.2.1.1 Template That Matches a Portion of IR Tree +#######8.2.1.2.1.2 Implemented with a Single Target Instruction +######8.2.1.2.2 Templates +#######8.2.1.2.2.1 Convert Code from IR to Target Language +#######8.2.1.2.2.2 Open to Optimization +######8.2.1.2.3 Implementation +#######8.2.1.2.3.1 Backward Dynamic Programming +8.2.1.2.3.2 Greedy Algorithms +8.2.2 Instruction Scheduling +8.2.2.1 Optimization Technique +8.2.2.1.1 Reorders Instructions for Optimal Processing +8.2.2.1.2 Avoid Data Stalls and Code Structure Hazards +8.2.2.2 Types of Scheduling Algorithms +8.2.3 Register Allocation +8.2.3.1 Multiplexes Program Variables to CPU Registers +8.2.3.1.1 Maximize Program Execution Time +8.2.3.1.2 Occurrences +8.2.3.1.2.1 Local +8.2.3.1.2.2 Global +8.2.3.1.2.3 Interprocedural +8.2.3.2 NP-Complete Optimization Problem +8.2.4 Non-Standard Compilers +8.2.4.1 Just-In-Time Compilation +8.2.4.2 Profiling ### What is code generation? Code generation is the final [compiler phase](#what-are-the-phases-of-a-compiler). It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. The code generator is distinct from the [parser](#what-is-a-parser) and the [translator](#what-is-a-translator). -<<<<<<< HEAD >>>>>>> 834e59cdc23433988ce06729e5c192b9e30bc2c5 ======= From c55362165523714a0759bc85606b5e8c860a3758 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:19:27 -0300 Subject: [PATCH 05/21] Update textbook/08-code-generation.md --- textbook/08-code-generation.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index 3f3abfa..553a65d 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -1,4 +1,3 @@ - Code generation is the final compiler phase. It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. The code generator is distinct from the parser and the translator. @@ -68,7 +67,7 @@ TOPICS: Code generation =============== -###8.1 Overview +##8.1 Overview ####8.1.1 Produces Machine-Executable Code ####8.1.2 Input Parse Tree ####8.1.3 Output Machine Code From 8feb77b7c831a69b74c5435319e40afc5240aa51 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:20:00 -0300 Subject: [PATCH 06/21] Update textbook/08-code-generation.md --- textbook/08-code-generation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index 553a65d..a093b1a 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -67,7 +67,7 @@ TOPICS: Code generation =============== -##8.1 Overview +#8.1 Overview ####8.1.1 Produces Machine-Executable Code ####8.1.2 Input Parse Tree ####8.1.3 Output Machine Code From 255f11152f98017aaf3a59905c025fee5c21e9d5 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:23:30 -0300 Subject: [PATCH 07/21] Organized Chapter 8, added headings --- textbook/08-code-generation.md | 72 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index a093b1a..dc956cd 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -67,7 +67,15 @@ TOPICS: Code generation =============== -#8.1 Overview +###8.1 Overview +Code generation is the final [compiler phase](#what-are-the-phases-of-a-compiler). +It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. + +The code generator is distinct from the [parser](#what-is-a-parser) and the [translator](#what-is-a-translator). + +Code generators try to optimize the generated code by doing several different things including using faster instructions, using fewer instructions, +exploit available registers, and avoid redundant computations. + ####8.1.1 Produces Machine-Executable Code ####8.1.2 Input Parse Tree ####8.1.3 Output Machine Code @@ -76,46 +84,40 @@ Code generation ####8.2.1 Instruction Selection #####8.2.1.1 Transforms Middle-Level IR to Low-Level IR ######8.2.1.1.1 Middle Level IR -#######8.2.1.1.1.1 Tree-Based -#######8.2.1.1.1.2 Intermediate Representation +######8.2.1.1.1.1 Tree-Based +######8.2.1.1.1.2 Intermediate Representation ######8.2.1.1.2 Low Level IR -#######8.2.1.1.2.1 Reduced From Tree -#######8.2.1.1.2.2 Close to Target Language (Machine Code) +######8.2.1.1.2.1 Reduced From Tree +######8.2.1.1.2.2 Close to Target Language (Machine Code) #####8.2.1.2 Templates and Tiles ######8.2.1.2.1 Tiles -#######8.2.1.2.1.1 Template That Matches a Portion of IR Tree -#######8.2.1.2.1.2 Implemented with a Single Target Instruction +######8.2.1.2.1.1 Template That Matches a Portion of IR Tree +######8.2.1.2.1.2 Implemented with a Single Target Instruction ######8.2.1.2.2 Templates -#######8.2.1.2.2.1 Convert Code from IR to Target Language -#######8.2.1.2.2.2 Open to Optimization +######8.2.1.2.2.1 Convert Code from IR to Target Language +######8.2.1.2.2.2 Open to Optimization ######8.2.1.2.3 Implementation -#######8.2.1.2.3.1 Backward Dynamic Programming -8.2.1.2.3.2 Greedy Algorithms -8.2.2 Instruction Scheduling -8.2.2.1 Optimization Technique -8.2.2.1.1 Reorders Instructions for Optimal Processing -8.2.2.1.2 Avoid Data Stalls and Code Structure Hazards -8.2.2.2 Types of Scheduling Algorithms -8.2.3 Register Allocation -8.2.3.1 Multiplexes Program Variables to CPU Registers -8.2.3.1.1 Maximize Program Execution Time -8.2.3.1.2 Occurrences -8.2.3.1.2.1 Local -8.2.3.1.2.2 Global -8.2.3.1.2.3 Interprocedural -8.2.3.2 NP-Complete Optimization Problem -8.2.4 Non-Standard Compilers -8.2.4.1 Just-In-Time Compilation -8.2.4.2 Profiling -### What is code generation? -Code generation is the final [compiler phase](#what-are-the-phases-of-a-compiler). -It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. +######8.2.1.2.3.1 Backward Dynamic Programming +######8.2.1.2.3.2 Greedy Algorithms +####8.2.2 Instruction Scheduling +#####8.2.2.1 Optimization Technique +######8.2.2.1.1 Reorders Instructions for Optimal Processing +######8.2.2.1.2 Avoid Data Stalls and Code Structure Hazards +#####8.2.2.2 Types of Scheduling Algorithms +####8.2.3 Register Allocation +#####8.2.3.1 Multiplexes Program Variables to CPU Registers +######8.2.3.1.1 Maximize Program Execution Time +######8.2.3.1.2 Occurrences +######8.2.3.1.2.1 Local +######8.2.3.1.2.2 Global +######8.2.3.1.2.3 Interprocedural +#####8.2.3.2 NP-Complete Optimization Problem +####8.2.4 Non-Standard Compilers +#####8.2.4.1 Just-In-Time Compilation +#####8.2.4.2 Profiling -The code generator is distinct from the [parser](#what-is-a-parser) and the [translator](#what-is-a-translator). ->>>>>>> 834e59cdc23433988ce06729e5c192b9e30bc2c5 -======= -Code generators try to optimize the generated code by doing several different things including using faster instructions, using fewer instructions, -exploit available registers, and avoid redundant computations. +>>>>>>> 834e59cdc23433988ce06729e5c192b9e30bc2c5 +======= >>>>>>> 6e5fd0d4c08f37c452ae8d1647391a2575390bc2 From 8bf8cc507a272d10cb7470c88ffd87af098dc4a9 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:27:04 -0300 Subject: [PATCH 08/21] Added headings and general formatting --- textbook/08-code-generation.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index dc956cd..e024e98 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -1,6 +1,4 @@ -Code generation is the final compiler phase. It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. -The code generator is distinct from the parser and the translator. ======= ======= @@ -62,12 +60,13 @@ TOPICS: 8.2.4.2 Profiling --> +#Code generation ->>>>>>> 6e5fd0d4c08f37c452ae8d1647391a2575390bc2 -Code generation -=============== ###8.1 Overview +Code generation is the final compiler phase. It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. + +The code generator is distinct from the parser and the translator. Code generation is the final [compiler phase](#what-are-the-phases-of-a-compiler). It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. From f1709947962d2ee5d519e587a5edec4fde901bf4 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:33:17 -0300 Subject: [PATCH 09/21] Added headings and general formatting --- textbook/07-optimization.md | 49 ++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/textbook/07-optimization.md b/textbook/07-optimization.md index f3a94c6..6415301 100644 --- a/textbook/07-optimization.md +++ b/textbook/07-optimization.md @@ -1,4 +1,3 @@ - \pagebreak -Introduction -============ - -## 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 +#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.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 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 From fdc177a5e3ea52bf6da563850bbe5f3256287ec0 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:43:35 -0300 Subject: [PATCH 13/21] Added headings and general formatting --- textbook/01-overview.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/textbook/01-overview.md b/textbook/01-overview.md index 1e796f4..342876d 100644 --- a/textbook/01-overview.md +++ b/textbook/01-overview.md @@ -1,5 +1,3 @@ -\pagebreak - -Lexical Analysis -================ +#Lexical Analysis -###2.1 Grammars +##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.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 +###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)? From a5704cf718f4d5d552b4e78493d97b56d7e9983f Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:46:34 -0300 Subject: [PATCH 15/21] Added headings and general formatting --- textbook/03-parsing.md | 56 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/textbook/03-parsing.md b/textbook/03-parsing.md index 68b099c..a9953ec 100644 --- a/textbook/03-parsing.md +++ b/textbook/03-parsing.md @@ -1,5 +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. @@ -53,73 +51,75 @@ TOPICS: 3.3.2.2 Combine Terminal Symbol to Produce Nonterminals --> -Parsing -======= +#Parsing -### 3.1 Parsing Overview +## 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 +### 3.1.1 Function Syntactic analysis will verify that the input`s syntax is valid. -##### 3.1.1.1 Input: Tokens from Lexical Analysis +#### 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 +#### 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 +## 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.1 Traversing a Parse Tree +### 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.1 Definition +#### 3.2.1.1 Definition -##### 3.2.1.2 Example +#### 3.2.1.2 Example LL parsers are examples of top-down parsing (diagram here?) -#### 3.2.2 Backus-Naur Form Production Rules -#### 3.2.3 LL Parser +### 3.2.2 Backus-Naur Form Production Rules + +### 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.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.1 Definition -##### 3.3.1.2 Examplel +#### 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? From 72cb00a3897843484bee879d1d3ab6c9a154cd36 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Wed, 25 Jul 2012 12:47:34 -0300 Subject: [PATCH 16/21] Added headings and general formatting --- textbook/03-parsing.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/textbook/03-parsing.md b/textbook/03-parsing.md index a9953ec..c28b33d 100644 --- a/textbook/03-parsing.md +++ b/textbook/03-parsing.md @@ -105,6 +105,8 @@ LL parsers are examples of top-down parsing (diagram here?) #### 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. From 1906c67cdd1de839b7f124b54f4c20b700591051 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Fri, 27 Jul 2012 14:32:13 -0300 Subject: [PATCH 17/21] Added headings and general formatting --- textbook/04-ast-and-symbol-tables.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/textbook/04-ast-and-symbol-tables.md b/textbook/04-ast-and-symbol-tables.md index dae59ce..abf6267 100644 --- a/textbook/04-ast-and-symbol-tables.md +++ b/textbook/04-ast-and-symbol-tables.md @@ -1,6 +1,3 @@ - -\pagebreak - +#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 ======================================= From 68c75eafff3653402a0de650c25535bb5a78fe73 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Fri, 27 Jul 2012 14:39:05 -0300 Subject: [PATCH 18/21] Added headings and general formatting --- textbook/05-semantic-analysis.md | 35 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/textbook/05-semantic-analysis.md b/textbook/05-semantic-analysis.md index e3d767f..c19d08d 100644 --- a/textbook/05-semantic-analysis.md +++ b/textbook/05-semantic-analysis.md @@ -1,6 +1,3 @@ - -\pagebreak - - - -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? +#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 From e8cd3ce5e0a6b94b84165a8b761bb953f4604338 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Fri, 27 Jul 2012 14:41:49 -0300 Subject: [PATCH 20/21] Added headings and general formatting --- textbook/08-code-generation.md | 80 +++++++++++++++++----------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index e024e98..ca26d13 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -1,4 +1,3 @@ - ======= ======= @@ -75,46 +74,45 @@ The code generator is distinct from the [parser](#what-is-a-parser) and the [tra Code generators try to optimize the generated code by doing several different things including using faster instructions, using fewer instructions, exploit available registers, and avoid redundant computations. -####8.1.1 Produces Machine-Executable Code -####8.1.2 Input Parse Tree -####8.1.3 Output Machine Code -####8.1.4 Includes Some Optimization Techniques -###8.2 Process -####8.2.1 Instruction Selection -#####8.2.1.1 Transforms Middle-Level IR to Low-Level IR -######8.2.1.1.1 Middle Level IR -######8.2.1.1.1.1 Tree-Based -######8.2.1.1.1.2 Intermediate Representation -######8.2.1.1.2 Low Level IR -######8.2.1.1.2.1 Reduced From Tree -######8.2.1.1.2.2 Close to Target Language (Machine Code) -#####8.2.1.2 Templates and Tiles -######8.2.1.2.1 Tiles -######8.2.1.2.1.1 Template That Matches a Portion of IR Tree -######8.2.1.2.1.2 Implemented with a Single Target Instruction -######8.2.1.2.2 Templates -######8.2.1.2.2.1 Convert Code from IR to Target Language -######8.2.1.2.2.2 Open to Optimization -######8.2.1.2.3 Implementation -######8.2.1.2.3.1 Backward Dynamic Programming -######8.2.1.2.3.2 Greedy Algorithms -####8.2.2 Instruction Scheduling -#####8.2.2.1 Optimization Technique -######8.2.2.1.1 Reorders Instructions for Optimal Processing -######8.2.2.1.2 Avoid Data Stalls and Code Structure Hazards -#####8.2.2.2 Types of Scheduling Algorithms -####8.2.3 Register Allocation -#####8.2.3.1 Multiplexes Program Variables to CPU Registers -######8.2.3.1.1 Maximize Program Execution Time -######8.2.3.1.2 Occurrences -######8.2.3.1.2.1 Local -######8.2.3.1.2.2 Global -######8.2.3.1.2.3 Interprocedural -#####8.2.3.2 NP-Complete Optimization Problem -####8.2.4 Non-Standard Compilers -#####8.2.4.1 Just-In-Time Compilation -#####8.2.4.2 Profiling - +###8.1.1 Produces Machine-Executable Code +###8.1.2 Input Parse Tree +###8.1.3 Output Machine Code +###8.1.4 Includes Some Optimization Techniques +##8.2 Process +###8.2.1 Instruction Selection +####8.2.1.1 Transforms Middle-Level IR to Low-Level IR +#####8.2.1.1.1 Middle Level IR +#####8.2.1.1.1.1 Tree-Based +#####8.2.1.1.1.2 Intermediate Representation +#####8.2.1.1.2 Low Level IR +#####8.2.1.1.2.1 Reduced From Tree +#####8.2.1.1.2.2 Close to Target Language (Machine Code) +####8.2.1.2 Templates and Tiles +#####8.2.1.2.1 Tiles +#####8.2.1.2.1.1 Template That Matches a Portion of IR Tree +#####8.2.1.2.1.2 Implemented with a Single Target Instruction +#####8.2.1.2.2 Templates +#####8.2.1.2.2.1 Convert Code from IR to Target Language +#####8.2.1.2.2.2 Open to Optimization +#####8.2.1.2.3 Implementation +#####8.2.1.2.3.1 Backward Dynamic Programming +#####8.2.1.2.3.2 Greedy Algorithms +###8.2.2 Instruction Scheduling +####8.2.2.1 Optimization Technique +#####8.2.2.1.1 Reorders Instructions for Optimal Processing +#####8.2.2.1.2 Avoid Data Stalls and Code Structure Hazards +####8.2.2.2 Types of Scheduling Algorithms +###8.2.3 Register Allocation +####8.2.3.1 Multiplexes Program Variables to CPU Registers +#####8.2.3.1.1 Maximize Program Execution Time +#####8.2.3.1.2 Occurrences +#####8.2.3.1.2.1 Local +#####8.2.3.1.2.2 Global +#####8.2.3.1.2.3 Interprocedural +####8.2.3.2 NP-Complete Optimization Problem +###8.2.4 Non-Standard Compilers +####8.2.4.1 Just-In-Time Compilation +####8.2.4.2 Profiling >>>>>>> 834e59cdc23433988ce06729e5c192b9e30bc2c5 From b4100863f542f444e08b72c82bf06dbad571dd52 Mon Sep 17 00:00:00 2001 From: nhogan11 Date: Fri, 27 Jul 2012 14:42:15 -0300 Subject: [PATCH 21/21] Added headings and general formatting --- textbook/08-code-generation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbook/08-code-generation.md b/textbook/08-code-generation.md index ca26d13..27f2104 100644 --- a/textbook/08-code-generation.md +++ b/textbook/08-code-generation.md @@ -62,7 +62,7 @@ TOPICS: #Code generation -###8.1 Overview +##8.1 Overview Code generation is the final compiler phase. It produces code in the target language, which is typically a machine language (e.g., x86, arm), but may be assembly or even a high-level language. The code generator is distinct from the parser and the translator.