LEXICAL ANALYSIS




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.



Frequently Asked Questions

+
Ans: A program, written in source language, is translated by the compiler to produce a program in a target language. The source language is usually a high-level language. The target language may or not necessarily be machine language. In most cases, the target language is assembly language, and in which case, the target program must be translated by an assembler into an object program. Then the object program is linked with other object programs to build an executable program, which is normally saved in a specified location of the secondary memory. When it is needed to be executed, the executable file is loaded into main memory before its execution. The whole process is managed, coordinated and controlled by the underlying operating system. Sometimes the target language may be a language other than machine or assembly language, in which case a translator for that language must be used to obtain an executable object program. view more..
+
Ans: A programming language can be defined formally as an artificial formalism in which algorithms can be expressed. It is composed of a set of instructions in a language understandable to the programmer and recognizable by a computer. Computer languages have been continuing to grow and evolve since the 1940’s. Assembly language was the normal choice for writing system software like operating systems, etc. But, C has been used to develop system software since its emergence. The UNIX operating system and its descendants are mostly written in C. Application programs are designed for specific computer applications. Most programming languages are designed to be good for one category of applications but not necessarily for the other. For an instance, COBOL is more suitable for business applications whereas FORTRAN is more suitable for scientific applications. view more..
+
Ans: The Exclusive-NOR gate is a XOR gate followed by a NOT gate. XNOR gate is a two-input and one-output logic gate circuit. In the gate, the output is HIGH if both inputs are either LOW or HIGH 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: 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: 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: 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..
+
Ans: Importance of Computer Programming Today view more..




Rating - 3/5
466 views

Advertisements