• No results found

Compiler Construction ETCS-405

N/A
N/A
Protected

Academic year: 2021

Share "Compiler Construction ETCS-405"

Copied!
10
0
0

Loading.... (view fulltext now)

Full text

(1)

Maharaja Agrasen Institute Of Technology CSE

Compiler Construction

ETCS-405

TUTORIAL FILE

Computer Science and Engineering

Maharaja Agrasen Institute of Technology, PSP Area,

Sector – 22, Rohini, Delhi – 110085

(2)

Maharaja Agrasen Institute Of Technology CSE

Phases of Complier Construction tools ,algorithms in various small modules & finally combining all of them to give it a shape of complier with reserved Or subset of keywords . In the Compiler Construction and Design lab , the students are expected to learn the steps of creating the compiler into different phases. The general phases of a compiler are :

 Lexical analysis

 Syntax analysis

 Semantic Analysis

 Intermediate code generator

 Code optimizer

 Code generator

Apart from these , there are two other phases of a compiler namely symbol table manager and error handler . This Lab concentrated on the earlier stages of a compiler namely Lexical analysis, syntax analysis and parsing table generation. To achieve our purpose of studying the early phases of compiler development we have broken down the task of a compiler further into a number of separate programs as shown below in the list of experiments.

Therefore, the aim of the lab is to understand, which existing techniques( Bottom Up Parsing, Top down Parsing) , in order to provide software engineers guidelines for the learning to make a new compiler with its new features.

(3)

Maharaja Agrasen Institute Of Technology CSE

Tutorial sheet 1

Q 1.Constructs predicted passing table for the following grammar: S- > I Et S S’/a

S -> eS/  E->b

Q2. Consider the following grammar ? S-> ()/a

L-> L,S/s

Check this grammar is left recursive or not ?. Q3- S-> AaAb / BbBa

A-> B- >

Test whether the grammar is LL (1) or not , and construct predictive passing table for it. Q-5 S-> (AB/E

A-> 1Ac/dc B-> OS

C-> 1

Check whether grammar is LL(1)

Q6 Which of the following is a phase of a compilation process ?

A. Lexical analysis B. Code generation C. Both (a) and (b) D. None of these

(4)

Maharaja Agrasen Institute Of Technology CSE

: programmer?

A. Allocation B. LInking C. Reallocation D. both (A) and (B)

Q8 Advantage of using assembly language rather than machine language is that A. it is mneomonic and easy to read

B. addresses any symbolic not absolute C. introduction of data to program is easier D. All of these

Q9 An interpreter is a program that

A.places programs into memory and prepares them for execution

B.automates the translation of assembly language into machine language. C.accesses a program written in a high level language and produces an object

program.

(5)

Maharaja Agrasen Institute Of Technology CSE Tutorial sheet 2. Q-1 s -> AB AC A-> a A/c B- >bBC C->C Eliminate E()-productions

Q-2 Eliminate unit production from the following grammar ? S-> AB

A-> a B-> C/b D->E E->a

Q-3 Eliminate left recursion from the grammar ? S-> A

A-> Ad/AE/ aB/ac B-> bBc /F

c-> g

Q-4 Consider S-> aa/ aSa show that passer succeeds on 2 a’s , 4 a’s but not 6a’s Q5 Assembly code data base is associated with

A.assembly language version of the program which is created by the code.

B.a permanent table of decision rules in the form of patterns for matching with the uniform symbol table to discover syntactic structure.

C.Both (a) and (b)

D.a permanent table which lists all key words and special symbols of the language in symbolic form.

(6)

Maharaja Agrasen Institute Of Technology CSE

A.recognize the major constructs of the language and to cal the appropriate action routines that wil generate the intermediate form or matrix for these constructs B.build a literal table and an identifier table.

C.build a uniform symbol table.

D.parse the source program into the basic elements or tokens of the language.

Q7 The table created by lexical analysis to describe all literals used in the source program is

A. Terminal table B. Literal table C. Identiier table D. Reductions

Q8 A linker is given object module for a set ofprograms that were compiled separately. What information need not be included in an object module

A.Object code B.Relocation bits

C.Names and locations of all external symbols deined in the object module ? D.Absolute addresses of internal symbols.

(7)

Maharaja Agrasen Institute Of Technology CSE

Tutorial sheet 3

Q-1 Accept set of string of 0’s & 1’s with at most one pair of consecutive Zero and at most one pair of consecutive 1’S?

Q-2 Construction of finite automata contain even number of zeros and odd no. of ones.?

Q-3 Construct a finite automata that contain odd number of 0’S and even no.of 1’s?

Q-4 Construct a finite automata that contain equal number of 0’s and 1’s and no prefix of string should contain 2 more 0’s than 1’s or two more 1’s than 0’s? Q5 A compiler for a high level language that runs on one machine and produce code for different machine is called

 Optimizing compiler

 One pass compiler

 Cross compiler

 Multipass compiler

Q6 Relocating bits used by relocating loader are specified by

 Relocating loader itself

 Linker

 Assembler

 Macro processor

Q7 In operator precedence parsing , precedence relations are defoned

 For all pair of non terminals

 For all pair of terminals

 To delimit the handle

(8)

Maharaja Agrasen Institute Of Technology CSE

a substring and convert it to DFA?

Q-2 Construct a finite automata that accept string of decimal digits divisibly by3? Q-3 construct a finite automata that will accept those string of a binary number that are divisible by three?

Q-4 Eliminate  (lambda)Production ? S-> AB AC

A-> a A / B-> bB / C-> C

Q5One difference between a non-deterministic finite automata (NFA) and a deterministic finite automata (DFA) is:

(a) DFAs have only one final state.

(b) NFAs are always in exactly one state when recognizing a string of characters. (c) NFAs have e transitions.

(d) NFAs only have one outgoing edge from a state for each symbol

Q6 Which is class of grammars the Chomsky Hierarchy can be used to describe the largest set of languages:

(a) regular

(b) recursively-enumerable (c) context-sensitive

(d) context-free

Q7 Every context sensitive language is also ... (a) context-free.

(b) LL(k).

(c) recursively enumerable. (d) None of the above

(9)

Maharaja Agrasen Institute Of Technology CSE

Tutorial sheet 5

Q-1 Eliminate unit productions? S-> AB

A-> a C-> D D-> E E-> a

Q-2- Make transition Diagram of grammar? S-> OA / 1B /O/ 1

A-> OS /1 B /1 B-> OA /1S And also convert it to DFA.

Q- 3 Obtain regular expression from Regular grammar? S-> oA/0/1B

A-> 1 A/ 1 B-> OB / 1S

Q-4 Define left linear grammar , define right linear grammar?

Q5 Under which of the following circumstances might you choose to implement a programming language using an interpreter rather than a compiler?

(a) Executables for programs in the language should be able to be distributed and exe-cuted without the language implementation.

(b) Programs in the language need to perform well (run quickly).

(c) The language allows the program to generate and execute program code in the language dynamically.

(10)

Maharaja Agrasen Institute Of Technology CSE

Q-1 Convert the following grammar to left Linear Grammar? S-> a A

A-. aA/gB/g B-> gA

Q-2 S-> Aa /asa if S-> asa before S- aa is tried by parser ,then parser succeeds on 2a’s , 4 a’s but not 6 a’s ?

Q-3 Define left linear grammar , define right linear grammar? Q4 The first principle a compiler must always observe is that ... (a) the compiler must never backtrack.

(b) the compiler must output type errors as graphical ASTs.

(c) the compiler must preserve the meaning of the program being compiled. (d) the compiler must produce code that is more efficient than hand-tuned assembly code.

Q5 Which of the following statements about the current standard Java implementation for Java

is not true?

(a) It contains a compiler (javac) that translates Java source code to Java bytecode. (b) It implements Java using a pure compiler.

(c) The virtual machine for executing Java bytecode (java) uses a bytecode interpreter.

(d) The virtual machine for executing Java bytecode (java) uses a just-in-time compiler

References

Related documents

There are many augmented reality (AR) applications avail- able that can be used to create educational contents for these mobile devices. This paper surveys the most popular

(The default value is the same as the Extension General Use field on the Site Details: Automatic Design Definition window at the time that the NE is created. Choices displayed will

Strategy 1: Cloud for Development and Test Environments ArcGIS 19 • Expanded data storage quickly • Achieved 100% reliability over 18 months • Saved costs Oracle

Overall, Nebraska will continue to benefit from growing foreign demand for food products and the state’s manufacturing sector is expected to achieve steady, moderate growth

The ordinal regression method was used to evaluate the relationship between ICT performance of the overall production procedures in Greek SMEs (enhancement of

The Counseling and Advising Center, located in the Student and Community Services Building, provides comprehensive services for students who seek assistance in dealing with

This document describes how to insert a popup window of the TimeTrade appointment widget while keeping your own web page shaded in the background.. Using this popup widget

Every time the in-memory data structure for a particular column family is dumped to disk we set its bit in the commit log stating that this column family has been successfully