Compiler Design

Topics: Parsing, Compiler, LR parser Pages: 22 (7419 words) Published: March 25, 2012
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 2007-2008, EVEN SEMESTER PRINCIPLES OF COMPILER DESIGN-CS1352 TWO-MARK QUESTIONS 1. What does translator mean? A translator is a program that takes a input program on one programming language (source language) and produces output in another language (object language or target language). 2. What are the phases of a compiler? • Lexical analysis phase or scanning phase • Syntax analysis phase • Intermediate code generation • Code optimization • Code generation 3. What is the role of lexical analysis phase? Lexical analyzer reads the source program one character at a time, and grouped into a sequence of atomic units called tokens. Identifiers, keywords, constants, operators and punctuation symbols such as commas, parenthesis, are typical tokens. 4. Define lexeme? The character sequence forming a token is called lexeme for the token. 5. What are the two functions of parser?  It checks the tokens appearing in its input, which is output of the lexical analyzer.  It involves grouping the tokens of source program into grammatical phrases that are used by the compiler to synthesize the output. Usually grammatical phrases of the source program are represented by tree like structure called parse tree. 6. Mention the role of semantic analysis? Semantic analysis checks the source program for semantic errors and gathers information for the subsequent code-generation phase. It uses hierarchical structure to identify the operators and operands of expressions and statements. An important component of semantic analysis is type checking .In type checking the compiler checks that each operator has operands that are permitted by the source language specification.      

In such cases, certain programming language supports operand coercion or type coercion also. 7. Name some variety of intermediate forms. o Postfix notation or polish notation. o Syntax tree o Three address code o Quadruple o Triple  

8. Write the syntax for three-address code statement, and mention its properties. Syntax: A= B op C ƒ Three-address instruction has at most one operator in addition to the assignment symbol. The compiler has to decide the order in which operations are to be done. ƒ The compiler must generate a temporary name to hold the value computed by each instruction. ƒ Some three-address instructions can have less than three operands. 9. What are the techniques behind code optimization phase?  Constant folding  Loop constant code motion  Induction variable elimination  Common sub expression elimination  Strength reduction  Mathematical identities 10. Name minimum 4 compiler construction tools. ˆ LEX ˆ YACC-Parser generator ˆ Syntax directed translation scheme. ˆ Automatic code generator ˆ Data flow engines 11. Define the rule to develop an unambiguous grammar from ambiguous grammar. If S->αSβSγ / α1 / α2 / α3 / α4 /. ……/ αn is an ambiguous grammar than Unambiguous grammar becomes S-> αSβS1γ / S1 S1->α1 / α2 / α3 / α4 /. ……/ αn 12. What is meant by recognizer? It is a part of LEX analyzer that identifies the presence of a token on the input is a recognizer for the language defining that token. It is the program, which automatically recognize the tokens. A recognizer for a language L is a program that

takes an input string “x” and response “yes” if “x” is sentence of L and “no” otherwise. 13. What are the conditions to satisfied for NFA. NFA should have one start state. NFA may have one or more accepting states. ε-Transitions may present on NFA. There can be more than transitions, on same input symbol from any one state. In NFA, from any state “S” i. There can be at most 2 outgoing ε-transitions. ii.There can be only one transition on real input symbol. iii.On real input transition it should reach the new state only. 14. Define ambiguous grammar, and specify it demerits. If a grammar produces more than one parse tree for the given input string then it is called ambiguous grammar. It’s demerit is • It...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Compiler Essay
  • Essay about Compiler Design Final Exam
  • Basic Compiler Design Essay
  • Compiler Essay
  • Design and Development of a Simple Program Compiler Pl/0 Essay
  • Compiler and Interpreter Essay
  • The Use of Compiler Essay

Become a StudyMode Member

Sign Up - It's Free