Unity University: Department of Computer Sciences

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

UNITY UNIVERSITY

Department of Computer Sciences


Course Title: Principal of Compiler
Assignment-2
Section 1
Name ID.
1. Sentayhu Berhanu 68988R

Nov, 2020
Part I
1. Compiler translate the source code to machine language
2. Compiler should report the presence of Errors in the source program, in
translation process.
3. What is the output of lexical analyzer? A set of tokens.
4. Grammar of the programming is checked at Analysis Phase of compiler.
5. Parsing Is a process of finding a parse for string of tokens.
6. Compiler can check Syntax Error errors.
7. A grammar that produces more than one parse tree for some sentence is called as
Ambiguous grammar.
8. Lexical analysis is about breaking a sequence of character into Tokens.
9. Lexeme Is considered as a sequence of characters in a token.
10. When expression result = 3+2*8 is tokenized then identify the token category of each
token in expression.
Result is “Identifier”
= is “Assignment operator”
3 is “Integer Literal”
+ is “Addition operator”
2 is “Integer Literal”
* Is “Multiplication Operator”
8 is “Integer Literal”

Part II
1. List the various phases of a compiler?
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Intermediate code generation
5. Code optimizer
6. Code generation
2. What is a symbol table?
Symbol table is an important data structure created and maintained by compilers in order
to store information about the occurrence of various entities such as variable names,
function names, objects, classes, interfaces, etc. Symbol table is used by both the analysis
and the synthesis parts of a compiler.
3. Mention some of the cousins of compiler
- PreProcessor
- Assembler
- Linking and loading
4. List the phase that constitute the Front-end and back-end phase of compiler.
The front end includes all analysis phases end the intermediate code generator.
The back end includes the code optimization phase and final code generation phase.
5. List the various compiler construction tools.
1. Parser Generator
2. Scanner Generator
3. Syntax directed translation engines
4. Automatic code generators
5. Data-flow analysis engine
6. Compiler construction toolkits

6. Differentiate Tokens, patters, Lexeme


 Tokens- Sequence of characters that have a collective meaning.

 Patterns- There is a set of strings in the input for which the same token is produced as output.
This set of strings is described by a rule called a pattern associated with the token

 Lexeme- A sequence of characters in the source program that is matched by the pattern for a
token.

7. List the operations on language


Union, intersection, complement, concatenation
8. Write Regular Expression for identifier.
[a-zA-Z_][0-9a-zA-Z_]*
9. Describe the language denoted by the following regular expression: a(a|b)*a.
All Strings of a’s and b’s began and end with a
10. Mention the various notational short hands for representing regular Expressions.
 One or more instances
 Zero or one instance
 Character classes ([abc] where a,b,c are alphabet symbols denotes the
regular expressions a | b | c.)
 Non regular sets
11. List the various Error Recovery Strategies for a Lexical Analysis.
 Panic mode
 Statement mode
 Error productions
 Global correction
 Abstract Syntax Trees
12. Define a context Free Grammar.
A context-free grammar (CFG) consisting of a finite set of grammar rules is a quadruple (N,
T, P, S) where:
N is a set of non-terminal symbols.
T is a set of terminals
where N ∩ T = NULL. P is a set of rules, P: N → (N ∪ T)*
13. Define Ambiguous Grammar.
A CFG is said to ambiguous if there exists more than one derivation tree for the given input
string i.e., more than one Left Most Derivation Tree (LMDT) or Right Most Derivation Tree
(RMDT).
14. What are the problems with Top-Down parsing?
i. If the right production is not applied you will not get the input string.
ii. If you are not careful, and there is a left recursive production, it can lead to
continue cycling without getting to the answer i.e. input string.
iii. The sequence in which you apply the production matters as to whether you are
going to get the input string or not. That is, there is a particular sequence that will
lead you to the input string.
Iv. If you apply a production and find out that the production cannot work, you have
to start all over again.
15. Given the Grammar G:
G: S->aABF
A->bc|d
B->e
Draw the parse tree for the input string adef using RDP.

a
f
A B

d e

You might also like