Compiler: Mahmudul Hasan (Moon)
Compiler: Mahmudul Hasan (Moon)
1 Compiler Takes Entire program as input Interpreter Takes Single instruction as input .
4 Conditional Control Statements are Executes faster Conditional Control Statements are Executes slower
7 Error diagnostics is less than a compiler. Error diagnostics is better than a compiler.
1.Define compiler and interpreter. Write the difference between them. (page 2)
2.Define Preprocessor, Assembler, Linker, Loader, Byte code, lexical analysis, lexical analyzer,
Intermediate code generation
In computer science, a preprocessor is a program that processes its input data to produce output that is
used as input to another program.
A linker tool is used to link all the parts of the program together for execution.
In computer systems a loader is the part of an operating system that is responsible for loading programs
and libraries.
Byte code is program code that has been compiled from source code into low-level code for a software
interpreter. It may be executed by a virtual machine (such as a JVM) or further compiled into machine
code, which is recognized by the processor.
Lexical analysis is the first phase of a compiler. It takes the modified source code from language
preprocessors that are written in the form of sentences.
The lexical analyzer breaks these syntaxes into a series of tokens, by removing any whitespace or
comments in the source code.
Intermediate code generation is the process by which a compiler's code generator converts
some intermediate representation of source code into a form that can be readily executed by a machine.
Chapter 2
1.Describe the model of a compiler front end . (page 41er figure 2.3 draw and discribe)
2.Define context free grammar, describe the four component of a context free grammer.(page 42 er
2.2.1 er point 4 ta)
A context-free grammar (CFG) is a set of recursive rules (or productions) used to generate patterns of
strings. or
A context-free grammar (CFG) is a certain type of formal grammar, a set of production rules that
describe all possible strings in a given formal language.
3.Define parse tree. Write the properties of a parse tree. (page 43 er 2.2.3 er point 4 ta)
A parse is an ordered, rooted tree that represents the syntactic structure of a string according to some
context-free grammar. Or
A parse tree is an entity which represents the structure of the derivation of a terminal string from some
non-terminal symbol.
An unambiguous grammar is a context-free grammar for which every valid string has a unique
leftmost derivation or parse tree.
Chapter 3
Chapter 4
1.Define Panic mode recovery, Phrase level recovery, Error Production, Global Correction.
Panic Mode Recovery
In this method, successive characters from input are removed one at a time until a designated set of
synchronizing tokens is found. Synchronizing tokens are deli-meters such as ; or }
Advantage is that it’s easy to implement and guarantees not to go to infinite loop
Disadvantage is that a considerable amount of input is skipped without checking it for additional
errors
Error production
If user has knowledge of common errors that can be encountered then, these errors can be
incorporated by augmenting the grammar with error productions that generate erroneous
constructs.
If this is used then, during parsing appropriate error messages can be generated and parsing can
be continued.
Disadvantage is that it’s difficult to maintain.
Global Correction
The parser examines the whole program and tries to find out the closest match for it which is error
free.
The closest match program has less number of insertions, deletions and changes of tokens to
recover from erroneous input.
Due to high time and space complexity, this method is not implemented practically.
2.Given a grammar, construct the lest most and right most derivation.
3.Given a grammar, eliminate its left recursion.
4. Given a grammar, eliminate its left factoring.