Beruflich Dokumente
Kultur Dokumente
Typically, most compilers have at least two phases called front end and back end, while they could be either one-pass or multi-pass.
Phase is used to classify compilers according to the construction, while pass is used to classify compilers according to how they operate.
Collected By: Neha 2
Just-in-time compiler,
used by Smalltalk and Java systems, and also by Microsoft .Net's Common Intermediate Language (CIL) Applications are delivered in bytecode, which is compiled to native machine code just prior to execution.
Introduction
What is a compiler ? Compiler is a computer program that translates a computer program written in 1 computer language into an equivalent program written in another computer language.
Types of compilers
Types of Compiler
A single pass compiler makes a single pass over the source text, parsing, analyzing, and generating code all at once.
A Multi pass compiler makes more than 1 pass over the source code ,producing intermediate forms of code after each stages, optimizing the program and generates object code.
Collected By: Neha 5
Lexical analyzer
It is convenient to regard a source program as a sequence of tokens rather than simply string of characters. Token can be keyword, variable name, an integer, arithmetic operator etc. This task is called lexical analysis and part of compiler is called scanner, and input stream of source program is called the lexeme.
Collected By: Neha 7
Syntactical analysis
After the token scan, each statement in the program must be recognized as some language construct, such as declaration or an assignment, described by grammar .This process is called syntax analysis or parsing.
Grammars
Grammars are very much required if we consider construction of a compiler,The high level language is usually described in terms of grammar. This grammar specifies the form ,or syntax, of legal statements in the language. Then the problem of compilation becomes one of matching statements written by the programmer to structures defined by the grammar, and generating object code for each statement.
Collected By: Neha
1 Pass Compiler
Code generator
It is last process of compilation. Its a process in compiler, which translates the lexed and parsed non-erroneous code into the required object code. It involves a set of routines called semantic routines or code generation routines, which generate the object code. The object code generation may depend on computer, but doesn't depend on parsing techniques.
Collected By: Neha 10
Source program
If parser gets some grammar valid constraints derivation then it calls the The lexer goes through the source code generator and generates the object program generating the tokens and Collected By: Neha 11 code. return it to the parser.
14
15
In some cases the design of a language feature may require a compiler to perform more than one pass over the source. For instance, consider a declaration appearing on line 20 of the source which affects the translation of a statement appearing on line 10. In this case, the first pass needs to gather information about declarations appearing after statements that they affect, with the actual translation happening during a subsequent pass.
Collected By: Neha 16
Pascal was explicitly designed to be easy to implement with a single pass compiler and hence to produce the code at faster.
They have accomplished using the strict constructs of defining the variables to be defined before they are used.
Collected By: Neha 17
Pascal Example function odd(n : integer) : boolean; begin if n = 0 then odd := false else if n < 0 then odd := even(n + 1) { Compiler error: 'even' is not defined } else odd := even(n - 1) end;
Collected By: Neha 19
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.
Collected By: Neha 21
CONCLUSION
Single compiler is very fast and are used when very fast compilation is required. The forward reference problem in 1 pass compiler can be solved by defining strict language constructs like in the Pascal. Single pass compiler are better for large programs in general. Example of a platform where single pass can be used are: Pascal.
Collected By: Neha 22