1. Translator : it performs the translation of a program written in given programming language without losing the functional of original code
2. Language processors : process pgm written in source code[it is language translator which translates the source into machine code] it consist of pre processor , compiler ,assembler ,linker , loader.
2.1. Interpreter : it translates high level into machine code. When it comes to compiler it reads the whole source code at once and generates intermediate code in many passes but in interpreter it read the statement from line i/p ,then converts to intermediate code ,execute it ,then next statement . if error occurs ,then stops the execution and report it but in compiler it reads the whole pgm even if encounter error.
2.1.1. Assembler : translates assembly into machine code , the o/p of assembler object file(contains the combination of machine instruction as well as data in memory)
2.2. Pre processor : it is system software which is used to process the source pgm before fed into compiler and consist of following functions - Macro processing – allows user to define macros that are shorthand for longer constructs. File inclusion it includes the header files into pgm text. Rational processor provide user with built in macros like while and if statements. Language extension provides feature similar to built in macros
2.2.1. Loader : it is part of OS and responsible for loading executable files into memory and executes them and calculates the size of pgm ,data and creates memory space of it
2.2.2. Linker : it links and merge the various objects files together in order to make an executable file. Major task isto search and locate referenced module in pgm and determine the memory location where the code is loaded
3. Phases of compiler : in phase each source pgm transforms from one to another
3.1. Lexical ,syntax ,semantic , intermediate code generator , code optimizer ,code generator (symbol table manager , error handler)
4. Analysis phase
4.1. Lexical analysis : It reads the character in the source pgm and groups them into stream of tokens in each tokens is called as keywords or identifier and the certain tokens will augmented by lexical value.
4.2. Syntax analysis (parsing): the tokens produced by lexical are sent here as input and generates a parse tree or syntax tree. And tokens are checked against the source code grammar.
4.2.1. Semantic analysis: It checks whether the parse tree follows the rules of language, and produces syntax tree as output.
5. Synthesis phase:
5.1. Intermediate code generation: After the semantic analysis, here generates an intermediate code of the source for target machine like an abstract, and makes a way to easier translate into target code.
5.1.1. Code optimization: it removes unnecessary code lines and arrange the sequence of statements in order to speed up the program execution without wasting resources.
5.1.2. Code generation: it’s a final phase where it generates the target code.
6. Errors encountered in different phases :
6.1. Error in Syntax analysis : lexical (name of some identifier typed incorrectly)Syntactical (missing semicolon),Semantical(incompatible value),Logical(code not reachable)
6.1.1. Error recovery actions : panic mode ,statement mode, error productions ,global corrections
6.2. Program submitted to compiler often have error of various kind. So good compiler should detect as many error and recover from them.
6.2.1. Errors during lexical Analysis : strange character ,long quoted strings, invalid numbers
6.2.2. Error recovery actions : Deleting an extraneous character ,inserting a missing character, Replacing an incorrect character by correct character , Transposing two adjacent character.
6.3. Errors during semantic analysis : type error, logical error , run time error
7. Typesof computer language translators : assembler , interpreters and compiler
7.1. Assembler(converts the assembly pgm into machine code) compiler(translates the source code into executable binary code[target code]) Interpreter(process of translating high level source code into target code)
7.1.1. Advantage & disadvantage of Interpreter : good at locating error, debugging is easy and rather slow and no object is produced , so translation is done every times in pgm running
7.2. Advantage & disadvantage of compiler : fast in execution , debugging a pgm is much harder [when the error found. again whole pgm is re-compile]
7.2.1. Application of compiler : program translation , software productivity tools NOTE: Hybrid :which translates a human readable source code into intermediate for later interpretation Example of Hybrid : text formatters , silicon compiler , query interpreter.
8. Analysis – Synthesis model (compilation)
8.1. Analysis (lexical ,syntax, semantic) : it breaks up source into pgm into pieces and creates intermediate of source and during analysis the operation implied by source are determined and recorded in structure call syntax tree , in which each node represent an operation and child node as argument operation.
8.2. Synthesis: It constructs the desired target pgm from intermediate representation and has more specialized technique
9. Activities of compiler
9.1. Symbol table manager : contains record for each identifier with fields of attribute. And able to find identifier quickly to store and retrieve data from record quickly (code generators use symbol table to retrieve the details )
9.1.1. Error handler : As each phase can encounter error , so somehow to deal with the error , it can be detected in analysis phase.
10. The Grouping phase :
10.1. Front end – it depend primarily on source language and are independent of target machine. They are .. lexical analysis ,syntactic analysis, creation of symbol table ,semantic analysis, generation of intermediate code, part of code optimization ,error handling that goes along with above said phrase
10.1.1. Back end – it depends on compiler and does not depend on source but depend on intermediate language . they are ..code optimization ,code generation ,necessary symbol table and error handling operations
11. Compiler construction tools :
11.1. They are parser generator(produce syntax analyzer from grammatical description), scanner generator(produce lexical analyzer from regular expression),Syntax directed translation engines(produce collection of parse tree for walking and generating intermediate code),code generator(produce the code generator from collection of rules), data flow analysis engine (gathering information about how values
11.1.1. They should hide the details of the generation algorithm and produce component as they are specialize in implementing it .
12. Programming language basics :
12.1. Static/Dynamic distinction : it have static policy and dynamic policy
12.2. Static policy – decided at run time ,dynamic policy –decided at compile time, scope rules –to determine scope of declaration by looking only at pgm and can be determined by compiler.
12.2.1. Environment and states : it is mapping from names to location in the store.
12.2.2. Block structures : language that allows block to be nested is a blocked structure