Multi-pass compiler - wikipedia Multi-pass compiler A multi-pass compiler is a type of compiler that processes the source code or abstract syntax tree of a program several times. This is in contrast to a one - pass compiler, 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. Multi-pass compilers are sometimes called wide compilers, 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 code generation ( 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 languages can not be compiled in a single pass, as a result of their design. Contents 1 Typical multi-pass compiler 1.1 Lexical analysis 1.2 Syntax analysis 1.3 Semantic analysis 1.4 Code generation 2 Advantages of multi-pass compilers 3 References Typical multi-pass compiler Lexical analysis 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 analysis determines the lexical tokens of the language. This step means that forward declaration 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. Syntax analysis Syntax analysis is responsible for looking at syntax rules of the language ( often as a context - free grammar ), and building some intermediate representation of the language. An example of this intermediate representation could be something like an Abstract Syntax Tree or a Directed Acyclic Graph. Semantic analysis Semantic analysis 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 if statements were boolean expressions the cond would be type - checked to make sure it would be a valid boolean expression. if ( cond ) (... ) else (... ) In addition to performing semantic analysis at this stage of compilation, often symbol tables are created in order to assist in code generation. Code generation This final stage of a typical compiler converts the intermediate representation of program into an executable set of instructions ( often assembly ). This last stage is the only stage in compilation that is machine dependent. There can also be optimization done at this stage of compilation that make the program more efficient 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. Advantages of multi-pass compilers Machine Independent : 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. More Expressive Languages : Many programming languages can not be represented with a single - pass compilers. For example, Pascal can be implemented with a single - pass compiler since it requires that all definitions come before their use. var x : Integer ; procedure inc ; begin x : = x + 1 ; end ; x : = 0 ; inc ; This in the single - pass compiler when x is referenced, the semantic analysis and code generation can be done since the compiler already knows from the declaration of x : where the value of x has been stored x ' s type Languages like Java require a multi-pass compiler since the definition of x would not be required to come before the use. public class Example ( public static void main ( String ( ) args ) ( assert ( x = = 0 ) ; x + + ; assert ( x = = 1 ) ; ) static int x = 0 ; ) The multi-pass compiler would allocate the memory location for x during the semantic analysis phase of compilation and would have processed the declaration of x before its use. References Bornat, Richard, Understanding and Writing Compilers : A Do It Yourself Guide, Macmillan Publishing, 1979. ISBN 0 - 333 - 21732 - 2 Bent Thomsen, Languages and Compilers SProg og Overseattere, Department of Computer Science, Aalborg University Retrieved from `` https://en.wikipedia.org/w/index.php?title=Multi-pass_compiler&oldid=824546166 '' Categories : Compilers Hidden categories : All articles with unsourced statements Articles with unsourced statements from February 2009 Talk Contents About Wikipedia Čeština فارسی Русский Edit links This page was last edited on 8 February 2018, at 00 : 25. Text is available under the Creative Commons Attribution - ShareAlike License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia ® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization. About Wikipedia

Question: why are compilers commonly split into multiple passes
Answer: the (intermediate) code is improved pass by pass