Knowledge

Multi-pass compiler

Source 📝

63: 111:
takes the representation made from syntax analysis and applies semantic rules to the representation to make sure that the program meets the semantic rules requirements of the language. For example, in the example below at the stage of semantic analysis if the language required that conditions on
74:
This stage of a multi-pass compiler is to remove irrelevant information from the source program that syntax analysis will not be able to use or interpret. Irrelevant information could include things like comments and white space. In addition to removing the irrelevant information, the lexical
186:
Other passes of compiler include intermediate code generation phase which takes place before code generation and code optimization phase which can take place when the source program is written, or after intermediate code generation phase, or after code generation phase.
39:, which traverses the program only once. Each pass takes the result of the previous pass as the input, and creates an intermediate output. In this way, the (intermediate) code is improved pass by pass, until the final pass produces the final code. 204:: Multiple passes obviate the need for forward declarations, allowing mutual recursion to be implemented elegantly. The prime examples of languages requiring forward declarations due to the requirement of being compilable in a single pass include 79:
is generally not necessary if a multi-pass compiler is used. This phase is focused on breaking a sequence of characters into tokens with attributes such as kind, type, value, and potentially others, as well.
46:, referring to the greater scope of the passes: they can "see" the entire program being compiled, instead of just a small portion of it. The wider scope thus available to these compilers allows better 198:: Since the multiple passes include a modular structure, and the code generation decoupled from the other steps of the compiler, the passes can be reused for different hardware/machines. 50:(e.g. smaller code size, faster code) compared to the output of one-pass compilers, at the cost of higher compiler time and memory consumption. In addition, some 92:), and building some intermediate representation of the language. An example of this intermediate representation could be something like an 261: 242: 175:
of a typical compiler converts the intermediate representation of program into an executable set of instructions (often
271: 180: 209: 108: 213: 172: 47: 205: 179:). This last stage is the only stage in compilation that is machine dependent. There can also be 97: 93: 89: 51: 32: 8: 76: 294: 88:
Syntax analysis is responsible for looking at syntax rules of the language (often as a
233:
Grune, Dick; van Reeuwijk, Kees; Bal, Henri; Jacobs, Ceriel; Langendoen, Koen (2012).
267: 238: 176: 36: 160:
In addition to performing semantic analysis at this stage of compilation, often
257: 288: 161: 75:
analysis determines the lexical tokens of the language. This step means that
120:
would be type-checked to make sure it would be a valid boolean expression.
28: 183:
done at this stage of compilation that make the program more efficient.
237:(Second ed.). Amsterdam, the Netherlands: Springer. p. 27. 62: 24: 54:
cannot be compiled in a single pass, as a result of their design.
263:
Understanding and Writing Compilers: A Do It Yourself Guide
232: 190: 35:
of a program several times. This is in contrast to a
280:, Department of Computer Science, Aalborg University 164:are created in order to assist in code generation. 286: 57: 278:Languages and Compilers SProg og Overseattere 42:Multi-pass compilers are sometimes called 116:statements were boolean expressions the 61: 287: 216:does not have forward declarations. 103: 69: 13: 191:Advantages of multi-pass compilers 167: 83: 14: 306: 266:, Macmillan Publishing, 1979. 226: 1: 219: 7: 58:Typical multi-pass compiler 10: 311: 202:More Expressive Languages 16:Software development tool 122: 235:Modern Compiler Design 98:directed acyclic graph 66: 65: 94:abstract syntax tree 90:context-free grammar 33:abstract syntax tree 196:Machine Independent 77:forward declaration 27:that processes the 21:multi-pass compiler 67: 244:978-1-4939-4472-9 109:Semantic analysis 104:Semantic analysis 37:one-pass compiler 302: 249: 248: 230: 173:This final stage 156: 153: 150: 147: 144: 141: 138: 135: 132: 129: 126: 70:Lexical analysis 310: 309: 305: 304: 303: 301: 300: 299: 285: 284: 283: 258:Bornat, Richard 253: 252: 245: 231: 227: 222: 193: 170: 168:Code generation 158: 157: 154: 151: 148: 145: 142: 139: 136: 133: 130: 127: 124: 106: 86: 84:Syntax analysis 72: 60: 48:code generation 17: 12: 11: 5: 308: 298: 297: 282: 281: 276:Bent Thomsen, 274: 254: 251: 250: 243: 224: 223: 221: 218: 192: 189: 169: 166: 123: 105: 102: 85: 82: 71: 68: 59: 56: 44:wide compilers 15: 9: 6: 4: 3: 2: 307: 296: 293: 292: 290: 279: 275: 273: 272:0-333-21732-2 269: 265: 264: 259: 256: 255: 246: 240: 236: 229: 225: 217: 215: 211: 207: 203: 199: 197: 188: 184: 182: 178: 174: 165: 163: 162:symbol tables 121: 119: 115: 110: 101: 99: 95: 91: 81: 78: 64: 55: 53: 49: 45: 40: 38: 34: 30: 26: 23:is a type of 22: 277: 262: 234: 228: 201: 200: 195: 194: 185: 181:optimization 171: 159: 117: 113: 107: 87: 73: 43: 41: 20: 18: 29:source code 220:References 212:, whereas 295:Compilers 52:languages 289:Category 177:assembly 25:compiler 270:  241:  210:Pascal 96:or a 268:ISBN 239:ISBN 214:Java 208:and 146:else 131:cond 118:cond 152:... 140:... 31:or 291:: 260:, 125:if 114:if 100:. 19:A 247:. 206:C 155:} 149:{ 143:} 137:{ 134:) 128:(

Index

compiler
source code
abstract syntax tree
one-pass compiler
code generation
languages

forward declaration
context-free grammar
abstract syntax tree
directed acyclic graph
Semantic analysis
symbol tables
This final stage
assembly
optimization
C
Pascal
Java
ISBN
978-1-4939-4472-9
Bornat, Richard
Understanding and Writing Compilers: A Do It Yourself Guide
ISBN
0-333-21732-2
Category
Compilers

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.