|
|
1 | (12) |
|
|
1 | (4) |
|
1.1.1 Advantages of High-Level Languages |
|
|
2 | (1) |
|
1.1.2 Disadvantages of High-Level Languages |
|
|
3 | (2) |
|
1.2 High-Level Language Implementation |
|
|
5 | (4) |
|
|
6 | (1) |
|
1.2.2 Compiler Complexity |
|
|
6 | (1) |
|
|
7 | (2) |
|
|
9 | (1) |
|
|
10 | (1) |
|
1.5 Conclusions and Further Reading |
|
|
11 | (2) |
|
|
12 | (1) |
|
2 Compilers and Interpreters |
|
|
13 | (24) |
|
2.1 Approaches to Programming Language Implementation |
|
|
13 | (3) |
|
2.1.1 Compile or Interpret? |
|
|
15 | (1) |
|
2.2 Defining a Programming Language |
|
|
16 | (6) |
|
|
17 | (4) |
|
|
21 | (1) |
|
|
22 | (6) |
|
|
22 | (1) |
|
|
23 | (1) |
|
|
24 | (4) |
|
2.4 Compiler and Interpreter Structure |
|
|
28 | (6) |
|
|
29 | (1) |
|
|
30 | (1) |
|
|
31 | (1) |
|
2.4.4 Machine-Independent Optimisation |
|
|
31 | (1) |
|
|
32 | (1) |
|
2.4.6 Machine-Dependent Optimisation |
|
|
32 | (1) |
|
|
33 | (1) |
|
2.4.8 Implementation Issues |
|
|
33 | (1) |
|
2.5 Conclusions and Further Reading |
|
|
34 | (3) |
|
|
35 | (2) |
|
|
37 | (38) |
|
|
38 | (7) |
|
|
38 | (1) |
|
3.1.2 Choosing the List of Tokens |
|
|
39 | (2) |
|
3.1.3 Issues with Particular Tokens |
|
|
41 | (3) |
|
3.1.4 Internal Representation of Tokens |
|
|
44 | (1) |
|
3.2 Direct Implementation |
|
|
45 | (12) |
|
3.2.1 Planning a Lexical Analyser |
|
|
46 | (1) |
|
3.2.2 Recognising Individual Tokens |
|
|
47 | (7) |
|
3.2.3 More General Issues |
|
|
54 | (3) |
|
|
57 | (4) |
|
3.3.1 Specifying and Using Regular Expressions |
|
|
57 | (1) |
|
3.3.2 Recognising Instances of Regular Expressions |
|
|
58 | (1) |
|
3.3.3 Finite-State Machines |
|
|
59 | (2) |
|
3.4 Tool-Based Implementation |
|
|
61 | (11) |
|
3.4.1 Towards a Lexical Analyser for C |
|
|
62 | (8) |
|
3.4.2 Comparison with a Direct Implementation |
|
|
70 | (2) |
|
3.5 Conclusions and Further Reading |
|
|
72 | (3) |
|
|
73 | (2) |
|
4 Approaches to Syntax Analysis |
|
|
75 | (20) |
|
|
75 | (2) |
|
4.1.1 Leftmost and Rightmost Derivations |
|
|
76 | (1) |
|
|
77 | (13) |
|
|
78 | (1) |
|
4.2.2 Parse Trees and the Leftmost Derivation |
|
|
78 | (4) |
|
4.2.3 A Top--Down Parsing Algorithm |
|
|
82 | (4) |
|
4.2.4 Classifying Grammars and Parsers |
|
|
86 | (2) |
|
|
88 | (1) |
|
|
89 | (1) |
|
|
90 | (1) |
|
4.4 Conclusions and Further Reading |
|
|
91 | (4) |
|
|
93 | (2) |
|
5 Practicalities of Syntax Analysis |
|
|
95 | (46) |
|
|
96 | (4) |
|
5.1.1 A Simple Top-Down Parsing Example |
|
|
97 | (3) |
|
5.1.2 Grammar Transformation for Top-Down Parsing |
|
|
100 | (1) |
|
|
100 | (10) |
|
5.2.1 Shift-Reduce Parsers |
|
|
101 | (2) |
|
5.2.2 Bison---A Parser Generator |
|
|
103 | (7) |
|
|
110 | (3) |
|
5.4 Syntax Analysis for DL |
|
|
113 | (19) |
|
5.4.1 A Top-Down Syntax Analyser for DL |
|
|
113 | (11) |
|
5.4.2 A Bottom-Up Syntax Analyser for DL |
|
|
124 | (7) |
|
5.4.3 Top-Down or Bottom-Up? |
|
|
131 | (1) |
|
|
132 | (2) |
|
5.6 Declarations and Symbol Tables |
|
|
134 | (2) |
|
|
136 | (1) |
|
5.8 Conclusions and Further Reading |
|
|
137 | (4) |
|
|
138 | (3) |
|
6 Semantic Analysis and Intermediate Code |
|
|
141 | (36) |
|
6.1 Types and Type Checking |
|
|
142 | (4) |
|
6.1.1 Storing Type Information |
|
|
142 | (1) |
|
|
143 | (3) |
|
|
146 | (7) |
|
6.2.1 Access to Simple Variables |
|
|
147 | (1) |
|
|
147 | (1) |
|
|
148 | (2) |
|
6.2.4 Arrays and Other Structures |
|
|
150 | (3) |
|
6.3 Syntax-Directed Translation |
|
|
153 | (1) |
|
|
153 | (1) |
|
|
154 | (7) |
|
|
155 | (3) |
|
|
158 | (3) |
|
6.5 Practical Considerations |
|
|
161 | (12) |
|
6.5.1 A Three-Address Code IR |
|
|
162 | (1) |
|
6.5.2 Translation to the IR |
|
|
163 | (8) |
|
|
171 | (2) |
|
6.6 Conclusions and Further Reading |
|
|
173 | (4) |
|
|
175 | (2) |
|
|
177 | (28) |
|
7.1 Approaches to Optimisation |
|
|
178 | (2) |
|
|
178 | (2) |
|
7.2 Local Optimisation and Basic Blocks |
|
|
180 | (7) |
|
7.2.1 Constant Folding and Constant Propagation |
|
|
181 | (1) |
|
7.2.2 Common Subexpressions |
|
|
182 | (4) |
|
7.2.3 Elimination of Redundant Code |
|
|
186 | (1) |
|
7.3 Control and Data Flow |
|
|
187 | (7) |
|
7.3.1 Non-local Optimisation |
|
|
188 | (2) |
|
7.3.2 Removing Redundant Variables |
|
|
190 | (1) |
|
|
191 | (3) |
|
|
194 | (7) |
|
|
196 | (1) |
|
7.4.2 Detecting Opportunities for Parallelism |
|
|
197 | (1) |
|
7.4.3 Arrays and Parallelism |
|
|
198 | (3) |
|
7.5 Conclusions and Further Reading |
|
|
201 | (4) |
|
|
202 | (3) |
|
|
205 | (30) |
|
|
205 | (5) |
|
|
206 | (3) |
|
|
209 | (1) |
|
8.2 Instruction Selection |
|
|
210 | (2) |
|
|
212 | (7) |
|
|
214 | (1) |
|
|
215 | (4) |
|
|
219 | (1) |
|
8.3.4 Application to DL's Intermediate Representation |
|
|
219 | (1) |
|
8.4 Function Call and Stack Management |
|
|
219 | (4) |
|
|
220 | (1) |
|
8.4.2 Call and Return Implementation |
|
|
221 | (2) |
|
|
223 | (7) |
|
8.5.1 Instruction-Level Parallelism |
|
|
223 | (3) |
|
8.5.2 Other Hardware Features |
|
|
226 | (2) |
|
8.5.3 Peephole Optimisation |
|
|
228 | (1) |
|
|
229 | (1) |
|
8.6 Automating Code Generator Construction |
|
|
230 | (1) |
|
8.7 Conclusions and Further Reading |
|
|
231 | (4) |
|
|
233 | (2) |
|
|
235 | (12) |
|
9.1 Implementation Strategies |
|
|
235 | (5) |
|
|
237 | (1) |
|
9.1.2 Implementation Languages |
|
|
237 | (2) |
|
|
239 | (1) |
|
|
240 | (2) |
|
9.3 Particular Requirements |
|
|
242 | (1) |
|
|
243 | (1) |
|
9.5 Conclusions and Further Reading |
|
|
243 | (4) |
|
|
245 | (2) |
Appendix A The DL Language |
|
247 | (4) |
Index |
|
251 | |