Intermediate code generation and optimization




Intermediate code generation and optimization To make the target program a bit smaller or faster or both, many compilers produce an intermediate form of code for optimization. In most cases, the intermediate code is generated in assembly language or in a different language at a level between assembly language and machine language.



Frequently Asked Questions

+
Ans: Semantic analysis :The semantics of a statement in a programming language define what will happen when that statement is executed. Semantic rules assign meanings to valid statements of the language. In the semantic analysis phase, the parsed statements are analysed further to make sure that the operators and operands do not violate source language specification. view more..
+
Ans: Syntax analysis In this phase, tokens are conflated into syntactic units such as expressions, statements, etc. that must conform to the syntax rules of the programming language. This process is known as parsing. Syntax is similar to the grammar of a language. Syntax rules specify the way in which valid syntactic elements are combined to form the statements of the language. Syntax rules are often described using a notation known as BNF (Backus Naur Form) grammar. view more..
+
Ans: Lexical analysis In this phase, the source program is scanned for lexical units (known as tokens) namely, identifier, operator delimiter, etc. and classify them according to their types. A table, called symbol table, is constructed to record the type and attributes information of each user-defined name used in the program. This table is accessed in the other phases of compilation. view more..
+
Ans: Intermediate code generation and optimization To make the target program a bit smaller or faster or both, many compilers produce an intermediate form of code for optimization. In most cases, the intermediate code is generated in assembly language or in a different language at a level between assembly language and machine language. view more..
+
Ans: Code generation This is the final phase of a standard compilation which converts every statement of the optimized intermediate code into target code using predefined target language template. The target language template depends on the machine instructions of the processor, addressing modes and number of registers, etc. view more..
+
Ans: Most of the high-level languages provide libraries of subroutines or functions so that certain common operations may be reused by system-supplied routines without explicit coding. Hence, the machine language program produced by the translator must normally be combined with other machine language programs residing within the library to form a useful execution unit. This process of program combination is called linking and the software that performs this operation is variously known as a linker. The features of a programming language influence the linking requirements of a program. In languages like FORTRAN, COBOL, C, all program units are translated separately. Hence, all subprogram calls and common variable references require linking. Linking makes the addresses of programs known to each other so that transfer of control from one subprogram to another or a main program takes place during execution. view more..
+
Ans: There are three types of translators, namely Assembler, Compiler and Interpreter. Assembler converts one assembly language statement into a single machine language instruction. . Depending on its implementation, a high-level language employs a compiler or an interpreter or both for translation. One statement in a high-level programming language will be translated into several machine language instructions. Both compiler and interpreter translate a program written in high-level language into machine language but in different fashion. Compiler translates the entire source program into object program at once and then the object files are linked to produce a single executable file. Unlike compiler, an interpreter translates one line of source code at a time—then executes it—before translating the next one and it does this every time the program executes. BASIC is a language that is usually implemented with an interpreter. Translation using an interpreter is slower than that using a compiler. The interpreter translates each line of source code to machine code each time the program is executed. With respect to debugging, an interpreted language is better than the compiled language. In an interpreter, syntax error is brought to the attention of the programmer immediately so that the programmer can make necessary corrections during program development. The Java language uses both a compiler and an interpreter. view more..
+
Ans: Loading is the process of bringing a program from secondary memory into main memory so it can run. The system software responsible for it is known as loader. The simplest type of loader is absolute loader which places the program into memory at the location prescribed by the assembler. Bootstrap loader is an absolute loader which is executed when computer is switched on or restarted to load the operating system. In most of the cases, when a compiler translates a source code program into object code, it has no idea where the code will be placed in main memory at the time of its execution. In fact, each time it is executed, it would likely be assigned a different area of main memory depending on the availability of primary storage area at the time of loading. That is why, compilers create a special type of object code which can be loaded into any location of the main memory. When the program is loaded into memory to run, all the addresses and references are adjusted to reflect the actual location of the program in memory. This address adjustment is known as relocation. Relocation is performed before or during the loading of the program into main memory view more..




Rating - 4/5
490 views

Advertisements