56% Off
View Sample

VTU eNotes On Compiler Design (Computer Science)

₹27.00 ₹30.00 ₹60.00 56% Off

Buy Ebook Buy Combo
Select your Combo
Combo: VTU Notes For Computer Science Engineering
₹900.00 ₹328.05
Add to Wish List

3 Offers Available

Get Rs.50 Instant Cashback on the purchase of Rs.400 or aboveSAVE10, Already Applied
More Offers
Less Offers

Product Specifications

Publisher VTU eLearning
Author: Panel Of Experts
Number of Pages 156
Available in all digital devices
  • About the book

About this eBook

Chapter 1 1. Introduction 1.1 Language Processors A compiler is a program that can read a program in one language source language and translate it into an equivalent program in another language target language . If the target program is an executable machine-language program, it can then be called by the user to process inputs and produce outputs. An interpreter is another common kind of language processor. Instead of producing a target program as a translation, an interpreter appears to directly execute the operations specified in the source program on inputs supplied by the user. The machine-language target program produced by a compiler is usually much faster than an interpreter at mapping inputs to outputs. An interpreter, however, can usually give better error diagnostics than a compiler, because it executes the source program statement by statement. A language-processing system typically involves preprocessor, compiler, assembler and linker loader in translating source program to target machine code. 1.2 The structure of a Compiler Analysis source program to intermediate representation front end Synthesis intermediate representation to target program back end The analysis part breaks up the source program into constituent pieces and imposes a grammatical structure on them. It then uses this structure to create an intermediate representation of the source program. If the analysis part detects that the source program is either syntactically ill formed or semantically unsound, then it must provide informative messages, so the user can take corrective action. The analysis part also collects information about the source program and stores it in a data structure called a symbol table, which is passed along with the intermediate representation to the synthesis part. The synthesis part constructs the desired target program from the intermediate representation and the information in the symbol table. The analysis part is often called the front end of the compiler the synthesis part is the back end. The phases of a compiler are lexical analyzer scanning linear analysis , syntax analyzer hierarchical analysis parsing , semantic analyzer, intermediate code generator, machineindependent code optimizer, code generator and machine-dependent code optimizer
Symbol table manager and error handler are two independent modules which will interact with all phases of compilation. A symbol table is a data structure containing a record for each identifier with fields for the attributes of the identifier. When an identifier in the source program is detected by the lexical analyzer, the identifier is entered into the symbol table. Each phase can encounter errors. After detecting an error, a phase must somehow deal with that error, so that compilation must proceed, allowing further errors in the source program to be detected. The first phase of a compiler is called lexical analysis or scanning. The lexical analyzer reads the stream of characters making up the source program and groups the characters into meaningful sequences called lexemes. For each lexeme, the lexical analyzer produces as output a token of the form token-name, attribute-value that it passes on to the subsequent phase, syntax analysis. In the token, the first component token-name is an abstract symbol that is used during syntax analysis, and the second component attribute-value points to an entry in the symbol table for this token. Information from the symbol-table entry is needed for semantic analysis and code generation. The second phase of the compiler is syntax analysis or parsing. The parser uses the first components of the tokens produced by the lexical analyzer to create a tree-like intermediate