CS606- compiler instruction Solved MCQS From Midterm Papers

Similar documents
MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

Question Bank. 10CS63:Compiler Design

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

Downloaded from Page 1. LR Parsing

CS 4120 Introduction to Compilers

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

LECTURE NOTES ON COMPILER DESIGN P a g e 2

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

Front End. Hwansoo Han

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

Parsers. Xiaokang Qiu Purdue University. August 31, 2018 ECE 468

COMPILER DESIGN. For COMPUTER SCIENCE

UNIT III & IV. Bottom up parsing

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1

LR Parsing Techniques

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

Let us construct the LR(1) items for the grammar given below to construct the LALR parsing table.

Formal Languages and Compilers Lecture VII Part 3: Syntactic A

Wednesday, September 9, 15. Parsers

Parsers. What is a parser. Languages. Agenda. Terminology. Languages. A parser has two jobs:

VIVA QUESTIONS WITH ANSWERS

Syntax Analysis Part I

Bottom-Up Parsing. Lecture 11-12

Parsing. Handle, viable prefix, items, closures, goto s LR(k): SLR(1), LR(1), LALR(1)

LR Parsing - The Items

Final Term Papers 2013

A simple syntax-directed

VALLIAMMAI ENGINEERING COLLEGE

LR Parsers. Aditi Raste, CCOEW

CST-402(T): Language Processors

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

UNIT-III BOTTOM-UP PARSING

2068 (I) Attempt all questions.

Lecture 8: Deterministic Bottom-Up Parsing

QUESTIONS RELATED TO UNIT I, II And III

Wednesday, August 31, Parsers

Lexical Scanning COMP360

ECE 468/573 Midterm 1 September 30, 2015

CS 406/534 Compiler Construction Putting It All Together

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

S Y N T A X A N A L Y S I S LR

Lecture 7: Deterministic Bottom-Up Parsing

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

Bottom-Up Parsing. Lecture 11-12

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Compilers and Interpreters

Compiler Design Aug 1996

Chapter 3: Lexing and Parsing

Torben./Egidius Mogensen. Introduction. to Compiler Design. ^ Springer

General Overview of Compiler

A programming language requires two major definitions A simple one pass compiler

shift-reduce parsing

Monday, September 13, Parsers

1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR / EVEN SEMESTER

The Structure of a Syntax-Directed Compiler

MIT Parse Table Construction. Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology

CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CS5363 Final Review. cs5363 1

CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points.

PRINCIPLES OF COMPILER DESIGN

Compiling Regular Expressions COMP360

Lecture Bottom-Up Parsing

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6

Bottom-Up Parsing II (Different types of Shift-Reduce Conflicts) Lecture 10. Prof. Aiken (Modified by Professor Vijay Ganesh.

SYLLABUS UNIT - I UNIT - II UNIT - III UNIT - IV CHAPTER - 1 : INTRODUCTION CHAPTER - 4 : SYNTAX AX-DIRECTED TRANSLATION TION CHAPTER - 7 : STORA

Properties of Regular Expressions and Finite Automata

COP4020 Spring 2011 Midterm Exam

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

Building Compilers with Phoenix

4. An interpreter is a program that

CSE 5317 Midterm Examination 4 March Solutions

Compiler Design (40-414)

Question Points Score

UNIT -2 LEXICAL ANALYSIS

DEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING UNIT -1-INTRODUCTION TO COMPILERS 2 MARK QUESTIONS

G53CMP: Lecture 4. Syntactic Analysis: Parser Generators. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 4 p.1/32

Conflicts in LR Parsing and More LR Parsing Types

Compilation 2012 Context-Free Languages Parsers and Scanners. Jan Midtgaard Michael I. Schwartzbach Aarhus University

LR Parsing LALR Parser Generators

Bottom Up Parsing. Shift and Reduce. Sentential Form. Handle. Parse Tree. Bottom Up Parsing 9/26/2012. Also known as Shift-Reduce parsing

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

When do We Run a Compiler?

How do LL(1) Parsers Build Syntax Trees?

SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTING DEPARTMENT OF CSE COURSE PLAN

In One Slide. Outline. LR Parsing. Table Construction

Chapter 4. Lexical and Syntax Analysis. Topics. Compilation. Language Implementation. Issues in Lexical and Syntax Analysis.

GUJARAT TECHNOLOGICAL UNIVERSITY

CS 314 Principles of Programming Languages

A Simple Syntax-Directed Translator

Theory and Compiling COMP360

Transcription:

CS606- compiler instruction Solved MCQS From Midterm Papers March 06,2014 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 Final Term MCQ s and Quizzes CS606- compiler instruction If X is a terminal in A--> ax?, then this transition corresponds to a shift of from input to top of parse stack. X (Page 75) A a A canonical collection of sets of items for an augmented grammar, C is constructed as ----- The first set in C is the closure of {[S' -->.S]}, where S is starting symbol of original grammar and S' is the starting non-terminal of augmented grammar. The first set in C is the closure of {[S' -->.S]}, where S is starting symbol of original grammar and S' is the starting non-terminal of original grammar. The first set in C is the closure of {[S' -->.S]}, where S is starting symbol of original grammar and S is the starting non-terminal of augmented grammar. None of these An ----- does not need to examine the entire stack for a handle, the state symbol on the top of the stack contains all the information it needs. LR parser Click here for detail RL parser BU parser 1

Suppose begins with symbol X which may be a terminal (token) or non-terminal. The item can be written as A X (Page 74) Question No: 1 ( Marks: 1 ) YACC parser generator builds up - Please choose one SLR parsing table Canonical LR parsing table LALR parsing table http://en.wikipedia.org/wiki/yacc Question No: 1 ( Marks: 1 ) LR(1) parsing is --- base parsing. - Please choose one DFA (Page 71) CFG PDA The LR(1) parsers cannot recognize precisely those languages in which one-symbol lookahead suffices to determine whether to shift or reduce. (Page 71) Yacc contains built-in support for handling ambiguous grammars resulting in shift-reduce conflicts. By default these conflicts are solved by performing the. Shift action Click here for detail Reduce action Shift and reduce actions De-allocation of memory 2

S --> A xb A --> aab x This grammar contains a reduce-reduce conflict. S --> a B B --> Bb E The non-terminal is left recursive. B a E Following statement represents: if x relop y goto L abstract jump Conditional jump (Page 107) While loop None of the Given When generating a lexical analyzer from a description, the item sets (states) are constructed by two types of moves : character moves and e moves. Character Grammar Token (Page 18) Sentence Left factoring is enough to make a grammar LL(1). Click here for detail 3

Register allocation by graph coloring uses a register interference graph. nodes in the graph are joined by an edge when the live ranges of the values they represent overlap. Two (Page 136) Three Four Five S --> A B A --> e aa B --> e bb FIRST(S) contains elements. 3 4 5 6 The notation instructs YACC to push a computed attribute value on the stack. $$ (Page 98) && ## -- Grammars with LL(1) conflicts can be made LL(1) by applying left-factoring, substitution, and left-recursion removal. Left-factoring takes care of conflicts. FIRST/FIRST FIRST/SECOND SECOND/FIRST 4

In an attribute grammar each production rule(n--> a) has a corresponding attribute evaluation rule that describes how to compute the values of the attributes of each particular node N in the AST. Synthesized Complete Free Bounded When constructing an LR(1) parser we record for each item exactly in which context it appears, which resolves many conflicts present in parsers based on FOLLOW sets. SLR(1) LRS(1) RLS(1) The translation statements can be conveniently specified in YACC Syntax-directed (Page 120) Image-directed Sign-directed. Backpatching to translate flow-of-control statements in pass. One (Page 117) two three all of the given Alternative of the backtrack in parser is Look ahead symbol in. Input (Page 46) Output Input and Output 5

Typical compilation means programs written in high-level languages to low-level. Object code (page 2) Byted code Unicode Both Object Code and byte code In PASCAL represent the inequality test. : := = <> LR parsing a string to the start symbol by inverting productions. Reduces (Page 63) Shifts Adds In multi pass compiler during the first pass it gathers information about. Declaration Click here 4 detail Bindings Static information phase which supports macro substitution and conditional compilation. Semantic Syntax Preprocessing click here for detail None of given 6

In parser the two LL stand(s) for. Left-to-right scan of input left-most derivation All of the given (Page 47) Parser always gives a tree like structure as output (Page 37) Lexer and scanner are two different phases of compiler (Page 12) tree in which each node represents an operator and children of the node represent the operands. Abstract syntax (Page 100) Concrete syntax Parse In compilation process Hierarchical analysis is also called Parsing Syntax analysis click here 4 details Both Parsing and Syntax analysis None of given Ambiguity can easily be handled by Top-down Parser Select correct option: Click here 4 details 7

Front-end of a two pass compiler is consists of Scanner. (Page 5) LL(1) parsing is called non-predictive parsing. Click here 4 details In predictive parsing table the rows are. Non-terminals (Page 54) Terminals Both non-terminal and terminals In LL1() parsing algorithm contains a sequence of grammar symbols. Stack (Page 55) Link list Array None Consider the grammar A --> B C D B --> h B epsilon C --> C g g C h i D --> A B epsilon First of C is. h g, I g, h, I, $ g 8

AST summarizes the grammatical structure with the details of derivations. (Page 8) Left factoring is enough to make LL1 grammar (Rep) f X is a non-terminal in A? ax?, then the interpretation of this transition is more complex because nonterminals do not appear in input Yes (Page 75) No NFA of LR(0) items means look-ahead one sybole no look-ahead (Page 74) look-ahead all sybols A grammar is LR if a ------ shift reduce-reduce parser can recognize handles when they appear on the top of stack. left-to-reverse left-to-rise left-to-right Click here for detail. The output from the algorithm of constructing the collection of canonical sets of LR(1) items will be the Original Grammar G Augmented grammar G' Parsing table (Page 76) 9

Reduction of a handle to the ------- on the left hand side of the grammar rule is a step along the reverse of a right most derivation. Terminal Non-terminal Click here 4 details NFA of LR(1) items means no look-ahead look-ahead one symbol (Page 72) look-ahead all sybols In canonical collection procedure a DFA cannot be constructed from NFA using the subset construction, similar to one we used for lexical analysis. (Page 74) Performing common subexpression elimination on a dependncy graph requires the identification of nodes with the same operator and operands. When using a hash table (with a hash function based on operator and operands) all nodes can be identified in linear time. common uncommon next previous Linear IRs resembles pseudo-code for same. Automated Machine Mechanical machines Token machines Abstract machine (Page 100) 10

The regular expressions a* b* and (a b)* describe the set of strings. Same Different Onto Back patching to translate flow-of-control statements in pass. one (Page 111) two three all of the given Yacc contains built-in support for handling ambiguous grammars resulting in conflicts. Shift-reduce Shift-Shift Shift-second A lexical analyzer generator automatically constructs a that recognizes tokens. FA (Page 18) PDA DP Attributes whose values are defined in terms of a node s own attributes, node s siblings and node s parent are called. Inherited attributes (Page 92) Physical attributes Logical attributes Un-synthesized attributes 11

The following two items A -> P Q B -> P Q can co-exist in an item set. LR LS LT PR Three-address codes are often implemented as a. Set of quadruples (Page 104) Set of doubles Set of Singles The error handling mechanism of the yacc parser generator pushes the input stream back when inserting missing tokens. Flow of values used to calculate synthesized attributes in the parse tree is: Bottom-up (Page 92) Right to left Top-Down Left to right What does following statement represent? x[i] = y Prefix assignment Postfix assignment indexed assignment (Page 107) A lexical analyzer transforms a stream of tokens. The tokens are stored into symbol table for further processing by the parser. (Page 103) 12

LR parsers can handle grammars. Left-recursive (Page 63) file-recursive End-recursive Start-recursive convert the reloadable machine code into absolute machine code by linking library and reloadable object files. Assembler Loader/link-editor Compiler Preprocessor One of the core tasks of compiler is to generate fast and compact executable code. (Page 2) Compilers are sometimes classified as. Single pass Multi pass Load and go All of the given Click here for detail In multi pass compiler during the first pass it gathers information about. Declaration Click here for detail Bindings Static information For each language to make LL(1) grammar, we take two steps, 1st is removing left recurrence and 2nd is applying fin sequence. Click here for detail 13

is evaluated to yield a value. Command Expression Declaration Declaration and Command We can get an LL(1) grammar by. Removing left recurrence Applying left factoring Removing left recurrence and Applying left factoring Click here for detail Can a DFA simulate NFA? Yes click here for detail No Sometimes Depend upon nfa Which of the statement is true about Regular Languages? Regular Languages are the most popular for specifying tokens. Regular Languages are based on simple and useful theory. Regular Languages are easy to understand. All of the given (Page 15) The transition graph for an NFA that recognizes the language ( a b)*abb will have following set of states. {0} {0,1} {0,1,2} {0,1,2,3} Click here for detail The LR(1) items are used as the states of a finite automaton (FA) that maintains information about the parsing stack and progress of a shift-reduce parser. (Page 74) 14

Functions of Lexical analyzer are? Removing white space Removing constants, identifiers and keywords Removing comments All of the given click here for detail Consider the following grammar, S --> atue T --> Tbc/b U --> d And suppose that string abbcde can be parsed bottom-up by the following reduction steps: (i) atbcde (ii) atde (iii) atue (iv) S So, what can be a handle from the following? The whole string, (atue) The whole string, (atbcde) The whole string, (atde) Flex is an automated tool that is used to get the minimized DFA (scanner). (Page 26) We use ----- to mark the bottom of the stack and also the right end of the input when considering the Stack implementation of Shift-Reduce Parsing. Epsilon # $ Click here for detail When generating a lexical analyzer from a token description, the item sets (states) are constructed by two types of moves : character moves and moves. E Click here for detail # @ none of given 15

Bottom-up parsers handle a class of grammars. Large (Page 42) small medium none of the given Let a grammar G = (Vn, Vt, P, S) is modified by adding a unit production S --> S to the grammar and now starting non-terminals becomes S and grammar becomes G = (Vn U {S }, Vt, PU{S --> S}, S ). The Grammar G is called the ----------- Augmented Grammar Lesser Grammar Anonymous Grammar none of given Parser takes tokens from scanner and tries to generate. Binary Search tree Parse tree Syntax tree (Page 8) In Flex specification file different sections are separated by. %% (Page 26) && ## \\ In DFA minimization we construct one for each group of states from the initial DFA. State (Page 25) NFA PDA None of given 16

Consider the grammar A --> B C D B --> h B epsilon C --> C g g C h i D --> A B epsilon Follow of B is. h g, h, i, $ g, i g Consider the grammar A --> B C D B --> h B epsilon C --> C g g C h i D --> A B epsilon Follow of C is. g, h, i, $ (Page 47) g, h, $ h, i, $ h, g, $ An important component of semantic analysis is. code checking type checking (Page 6) flush checking Intermediate Representation (IR) stores the value of its operand in. Registers Memory Hard disk Secondary storage 17

In certain checks are performed to ensure that components of a program fit together meaningfully. Linear analysis Hierarchical analysis Semantic analysis None of given Click here 4 detail Question No: 1 (Marks: 1) - Please choose one Which of the following statement is true about Two pass compiler. Front End depends upon Back End Back End depends upon Frond End Both are independent of each other algorithm is used in DFA minimization. James s Robert s Hopcroft s (Page 25) None of given Question No: 1 ( Marks: 1 ) A is a top down parser. - Please choose one Predictive Parsing (Page 46) Reactive parser Proactive parser Lexical Analyzer generator is written in Java. Flex Jlex (Page 26) Complex None of given 18

avoid hardware stalls and interlocks. Register allocation Instruction scheduling (Page 10) Instruction selection None of given Recursive parsing is done for LL(1) grammar. Decent (Page 47) Ascent Forward Backward Left factoring of a grammar is done to save the parser from back tracking. (Page 61) Responsibility of is to produce fast and compact code. Instruction selection (Page 9) Register allocation Instruction scheduling None of given Optimal registers allocation is an NP-hard problem. (Page 10) Front end of two pass compiler takes as input. Source code (Page 5) Intermediate Representation (IR) Machine Code None of the Given 19

In Three-pass compiler is used for code improvement or optimization. Front End Middle End (Page 10) Back End Both Front end and Back end of a two-pass compiler is consists of Instruction selection, Register allocation and Instruction scheduling. Back end (Page 9) Front end Start None of given NFA is easy to implement as compared to DFA. (Page 19) In Back End module of compiler, optimal register allocation uses. O(log n) O(n log n) N P-Complete (Page 10) In a transition table cells of the table contain the state. Reject state Next state (Page 18) Previous state Parser generator for the grammar LALR (1) is: YACC, Bison, CUP (Page 88) 20

If T --> XYZ is a production of grammar G then which of the following item indicates that a string derivable from X has been seen so far on the input and we hope to see a string derivable from YZ next on the input. T > X@YZ T > XYZ@ T > XY@Z T > @XYZ Click here for detail Question No: 1 ( Marks: 1 ) The most powerful parser is: - Please choose one LR parse Click here for detail LALR parse SLR parse None of these In the Parsing Table the rows correspond to Parsing DFA states and columns correspond to ----. Terminals Non-terminals Terminals and non-terminals None of these Click here for detail Attributes of a node whose values are defined wholly in terms of attributes of node s children and from constants are called. Synthesized attributes (Page 92) Question No: 1 ( Marks: 1 ) Goto L statement represent - Please choose one Unconditional jump (Page 107) 21