Você está na página 1de 4

COMPILER DESIGN

1. Define compiler.
A. Compilers are computer programs that translate one language to another. A compiler takes program as
its input written in its source lang. (c, c++) and produces an equivalent program written in its target lang.
(object code)

2. Give the differences between compiler and interpreter.


A. Components compiler Interpreter
Speed: is faster is slower.
Generates intermediate file no intermediate files.
Debugging: difficult easier
Writing: difficult easier
I/p should be given to: target program. Source program
Portable: not yes

3. List different phases of a compiler.


A. Lexical Analyzer, syntax analyzer, semantic analyzer, intermediate code generator, machine independent
code optimizer, code generator, machine dependent code generator.

4. What is the input and output of lexical analyzer?


A. I/P—Program, O/P-- Tokens

5. Define token, lexeme and pattern.


A. Token: A collection of sequence of characters into meaning full units called as tokens.
Lexeme: The string of characters represented by a token is sometimes called its string value or lexeme
Pattern: A regular expression r will also contain characters from the alphabet, but such characters have a
diff. meaning: in a regular expression, all symbols indicate patterns.

6. What is symbol table?


A. The symbol table is the major inherited attribute in a compiler and, after the syntax tree forms the major
data structure as well. The principal symbol table operations are insert, lookup, delete.

7. What may be role of DFA and NFA in lexical analysis?


A.
8. How regular expressions can be used in lexical analysis phase?
A.
9. What is the use of input buffering?
A.
10. List phases present in front end and back end of a compiler.
A. FRONT END-- Scanner, syntax analyzer, semantic analyzer, intermediate code generator,
BACK END—machine independent code optimizer, code generator, machine dependent code generator..

11. What is the other name for lexical analyzer?


A. SCANNER

12. What is the use of lex tool?


A. A program tool to generate code.

13. What are the three sections of lex program?


A. A collection of definitions, a collection of rules, & a collection of auxiliary routines or user routines.

14. How translation rules will be written in lex?


A.
15. What is the use of yylex function?(check)
A. yylex is the name given to the procedure constructed by lex that implements the DFA associated with
the regular expressions and actions given in the action section of the input file.
16. List the steps involved in lex program execution.
A. step 1: enter vi editor
Step 2: lex s.l
Step 3: cc lex.yy.c –ll
Step 4: ./a.out

17. What is meant by * and + in lex programs?


A. *- zero or more repetitions of a.
B. +-one or more repetitions of a.

18. What is meant by parsing?


A. Parsing is the task of determining the syntax, or structure, of a program.

19. Give the differences between top down and bottom up parsing.
A. Tree which forms from root to leaf node is called as top down parsing. Tree which forms from leaf to root
node is called as bottom up parsing.

20. What is context free grammar?


A. it is type2 grammar. A CFG is a specification for the syntactic structure of a programming Lang.

21. What is meant by Left most and Right most derivation?


A. A leftmost derivation is a derivation in which the leftmost nonterminal is replaced at each step in the
derivation.
A rightmost derivation is a derivation in which the rightmost nonterminal is replaced at each step in the
derivation.

22. Define ambiguous grammar.


A. A grammar that generates a string with two distinct parse trees is called an ambiguous grammar.

23. What is the other name for syntax analysis?


A. the PARSER or Parsing

24. What are the four different types of grammar?


A. type 0-Regular grammar, type 1- , type 2- CFG, type 3-.

25. Give examples for top down and bottom up parsers.


A. Top-Down Parsing: Back Tracking, Non-Back Tracking (Recursive, table driven); Bottom up Parsing:
operator precedence, LR

26. What is meant by left recursion and left factoring?


A. Left Recursion: A grammar is left recursion if it has a nonterminal A such that there is a derivation A=>+
Aalpha for some string alpha.
Left Factoring: is a grammar transformation that is useful for producing a grammar suitable for predictive, or top-
down, parsing.

27. How to find FIRST and FOLLOW?


A. FIRST
FIRST(X)=set of terminals=>strings first terminal
W=> set of terminals
R1: X is terminal, FIRST(X)={X}
R2: X is nonterminal, X->E(epsilon)
FIRST(X)=E(epsilon)
Since E(epsilon) is a terminal
R3: A->aY
FIRST(X) = FIRST(aY) ={a}
R4: X->Y1Y2Y3----Yk where Yi are Nonterminals, FIRST(X) =FIRST(Y).
FOLLOW
FOLLOW(X)=set of terminals is at RHS of X. X is always nonterminal
R1: X is a start symbol
FOLLOW(X) ={$}
$ is end mark of string w
R2: X->alphaYbeta
Where X&Y are nonterminals, alpha & beta are terminals or nonterminals
FOLLOW(Y)= FIRST(beta)
Here if FIRST(beta) includes then apply R3.
R3: X->alphaY then FOLLOW(Y)=FOLLOW(X)

28. How to find whether the given grammar is LL (1) or not?


A.
29. What are the three different LR parsers?
A. SLR (Simple LR), CLR (Cannonical LR), LALR (Look Ahead LR)

30. What is LR (0) item?


A. LR(0) item of a grammar G is a production of G with a dot at some position of the body.

31. What is LR (1) item?


A. LR

32. What are the advantage and disadvantages of LALR?

33. What is the meaning of L and R?


A. L- left to right, R- right most derivation

34. What is the use of Augmented Grammar?


A. If G is a grammar with start symbol S, then G’, the augmented grammar for G, is G with a new start symbol
S’ and production S’->S. the purpose of this new starting production is to indicate to the parser when it should
stop parsing and announce acceptance of the input. That is, acceptance occurs when and only when the parser
is about to reduce by S->S’.

35. What Action and Goto parts of a parsing table contains?


A. the ACTION fn takes as argument a state I and a terminal a(or $, the input end marker) the value of
ACTION[i, a] can have one of four forms.
i. Shift j, where j is a state. The action taken by the parser effectively shifts input a to the stack, but uses
state j to represent a.
ii. Reduce a->Bbeta. The action of the parser effectively reduces Bbeta on the top of the stack to head
A.
iii. Accept. The parser accepts the input and finishes parsing.
iv. Error. The parser discovers an error in its input and takes some corrective action.
B. we extend the GOTO fn, defined on sets of item sets, to states: if GOTO[Ii,A] =Ij, then GOTO also maps a
state I and a nonterminal A to state j.

36. What is the use of intermediate code?(check)


A. in the process of translating a source program into target code, a compiler may construct one or more
intermediate representations, which can have a variety of forms. Syntax trees are a form of intermediate
representation; they are commonly used during syntax and semantic analysis.

37. List different forms of Intermediate code.


A. Abstract Syntax Tree, Polish Notation, Three Address Code.

38. What is polish and reverse polish notation?


A. Polish-prefix notation, Reverse Polish-Post fix.
39. What is meant by three address code?
A. Three address code, which consists of a sequence of assembly like instructions with three operands per
instructions. Three- address code is a sequence of instructions of the form
x=y op z
Where x, y &z are names, constants, or compiler-generated temporaries;& op stand for an operator.

40. How three address codes can be implemented?


A.
41. How Abstract Syntax Tree can be implemented?
A. A useful starting point for designing a translator is a data structure called an abstract tree. In an abstract
syntax tree for an expression, each interior node.

42. What are issues of code generation?


A.
43. What is meant by code optimization?
A. Elimination of unnecessary instructions in object code, or the replacement of one sequence of instructions
by a faster sequence of instructions that does the same thing is usually called code improvement or code
optimizer
A great number and variety of techniques to improve code quality have been developed over the years, & these
have come to be known as code optimization techniques.

44. List different optimization methods.


A. Local, Global, Interprocedural optimization.

45. Give different addressing methods.


A.
46. How to allocate registers? (check)
A. The register assignment step that is target machine dependent assigns actual registers to those variables
tagged as register allocated, or to memory locations called pseudo register. Global register allocation, allocation
by graph coloring
.
47. What is Flow Graph?
A. An optimizer that performs global optimizations will construct from the intermediate code of each
procedure a graphical representation of the code called a flow graph.

48. What is the use of graph coloring?


A. GRAPH coloring is a simple, systematic technique for allocating registers and managing register spills

49. List different alp instructions.


A.

Você também pode gostar