Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

Sample Questions

Computer Engineering

Subject Name: System Programming and Compiler Construction Semester: VI

Multiple Choice Questions


Choose the correct option for following questions. All the Questions carry equal
marks
1. Which of the following is designed to control the operations of a computer?
Option A: Application Software
Option B: System Software
Option C: Utility Software
Option D: User

2. A person who designs the programs in a software package is called :


Option A: User
Option B: Software Manager
Option C: System Developer
Option D: System Programmer

3. Assembler is used as a translator for?


Option A: Low level language
Option B: High Level Language
Option C: COBOL
Option D: C

4. They normally interact with the system via the user interface provided by the
application software.
Option A: Programmers
Option B: Developers
Option C: Users
Option D: Testers

5. Storage mapping is done by__________


Option A: Linker
Option B: Compiler
Option C: Loader
Option D: Operating system

6. Interpreter is used as a translator for __________


Option A: Low level language
Option B: High Level Language
Option C: COBOL
Option D: C
7. A system program that set up an executable program in main memory ready for
execution is
Option A: Loader
Option B: Linker
Option C: Assembler
Option D: load and go

8. The __ of a system includes the program s or instructions.


Option A: Icon
Option B: Software
Option C: Hardware
Option D: Information

9. Instructions which won’t appear in the object program are called as _____
Option A: Redundant instructions
Option B: Exceptions
Option C: Mnemonic opcode
Option D: Assembler Directives

10. The last statement of the assembly program should be _______


Option A: STOP
Option B: RETURN
Option C: TERMINATE
Option D: END

11. Translator for low level programming language were termed as


Option A: Assembler
Option B: Compiler
Option C: Linker
Option D: Loader

12. The Macro processor is also called as _______


Option A: Preprocessor
Option B: Postprocessor
Option C: Debugger
Option D: Translator

13. In parameterised macro , the parameter is mapped using____


Option A: by position
Option B: by keyword
Option C: by reference
Option D: by string

14. The linker is a software that is used for______


Option A: Creating signle executable load module
Option B: Excecuting the program
Option C: Creating link between program and data
Option D: Helping loader to load program in memory
15. Which is not a function of a loader
Option A: Allocation
Option B: Translation
Option C: Relocation
Option D: Loading

16. Which of the following software always resides in main memory?


Option A: Text editor
Option B: Assembler
Option C: Linker
Option D: Loader

17. What type of data structure is used by shift reduce parser


Option A: linked list
Option B: Stack
Option C: Queue
Option D: Pointer

18. We can optimize code by


Option A: Dead code elimination
Option B: Common subprogram
Option C: Copy intermediate loop
Option D: Loop declaration

19. Local and loop optimization in turn provide motivation for


Option A: Data flow analysis
Option B: Constant folding
Option C: Pee hole optimization
Option D: DFA

20. Compiler can check ________ error


Option A: Logical
Option B: Syntax
Option C: both a and b
Option D: Content
Descriptive Questions
What is the forward reference problem? Explain single pass assembler with flowchart.
Explain multi pass assembler in detail

• Multipass assembler means more than one pass is used by assembler.


• Multipass assembler is used to eliminate forward references in symbol definition.
• Forward References Problem - The assembler specifies the symbols should be declared
anywhere in the in the program.
• There may be a chances of using a symbol before its declaration which gives rise to a forward
reference problem.
• Due to this problem assembler won’t be able to assemble the instruction and such a problem
is called forward references problem.
• The solution for forward references problem is having an assembler of two pass.
• It creates a number of passes that is necessary to process the definition of symbols.
• In pass one we find out all the Symbols and Literals.
• And in pass two we will perform assembling of code and the data (generating instruction and
generating data).
Show machine code generated for following assembly level program along with data
structures entries
Explain single pass macro processor
Explain the working of macro processor along with the data structures used in it
Explain the working of DLL loader in detail.

Dynamic Linking Loader:


• Dynamic Linking Loader is a general re-locatable loader
• Allowing the programmer multiple procedure segments and multiple data segments and
giving programmer complete freedom in referencing data or instruction contained in other
segments.
• The assembler must give the loader the following information with each procedure or data
segment.
• Dynamic linking defers much of the linking process until a program starts running. It provides
a variety of benefits that are hard to get otherwise.
• Dynamically linked shared libraries are easier to create than static linked shared libraries.
• Dynamically linked shared libraries are easier to update than static linked shared libraries.
• The semantics of dynamically linked shared libraries can be much closer to those of unshared
libraries.
• Dynamic linking permits a program to load and unload routines at runtime, a facility that can
otherwise be very difficult to provide.
Draw and Explain the various phases of compilers with suitable example.
Modify the given grammar and construct a Predictive parser table explaining each step.
E->E+T|T T->T*V|V V-> id.
For a given grammar below, Construct operator precdence relation matrix, assuming *, + are
binary operators and 'id' is terminal symbol, and E as Non terminal.
E->E+E E->E*E E->id Apply operator precedence parsing algorithm for the statement
' id + id * id'
Consider the following grammar: S --> aSbS | bSaS | Epcillon.
1. Frame the transition table and action / goto table of the given grammar.
2. Demonstrate if the grammar is LR(0) or not.
Explain the working of shift reduce parser along with suitable example

Shift Reduce parser attempts for the construction of parse in a similar manner
as done in bottom-up parsing i.e. the parse tree is constructed from
leaves(bottom) to the root(up). A more general form of the shift-reduce parser is
the LR parser.
This parser requires some data structures i.e.
• An input buffer for storing the input string.
• A stack for storing and accessing the production rules.
Basic Operations –
• Shift: This involves moving symbols from the input buffer onto the stack.
• Reduce: If the handle appears on top of the stack then, its reduction by using
appropriate production rule is done i.e. RHS of a production rule is popped
out of a stack and LHS of a production rule is pushed onto the stack.
• Accept: If only the start symbol is present in the stack and the input buffer is
empty then, the parsing action is called accept. When accepted action is
obtained, it is means successful parsing is done.
• Error: This is the situation in which the parser can neither perform shift action
nor reduce action and not even accept action.
Example 1 – Consider the grammar
S –> S + S
S –> S * S
S –> id
Perform Shift Reduce parsing for input string “id + id + id”.
Explain the different forms of intermediate codes used by Compiler.

The following are commonly used intermediate code representation :


Postfix notation Syntax tree Three-address code
Postfix Notation
The ordinary (infix) way of writing the sum of a and b is with operator in the middle : a + b The
postfix notation for the same expression places the operator at the right end as ab +. In
general, if e1 and e2 are any postfix expressions, and + is any binary operator, the result of
applying + to the values denoted by e1 and e2 is postfix notation by e1e2 +. No parentheses are
needed in postfix notation because the position and arity (number of arguments) of the
operators permit only one way to decode a postfix expression. In postfix notation the operator
follows the operand.
Eg : the postfix representation of the expression (a – b) * (c + d) + (a – b) is : ab – cd + ab -+*.
Three-Address Code: A statement involving no more than three references(two for operands
and one for result) is known as three address statement. A sequence of three address
statements is known as three address code. Three address statement is of the form x = y op z ,
here x, y, z will have address (memory location). Sometimes a statement might contain less
than three references but it is still called three address statement.
Eg: the three address code for the expression a + b * c + d :
T1=b*cT2=a+T1T3=T2+d
T 1 , T 2 , T 3 are temporary variables.
Syntax Tree Syntax tree is nothing more than condensed form of a parse tree. The operator
and keyword nodes of the parse tree are moved to their parents and a chain of single
productions is replaced by single link in syntax tree the internal nodes are operators and child
nodes are operands. To form syntax tree put parentheses in the expression, this way it's easy
to recognize which operand should come first.
Example : x = (a + b * c) / (a – b * c)
What is code optimization? Explain machine dependent code optimisation techniques with
suitable example
Explain machine independent code optimization techniques with suitable example
Discuss various issues that occur in the code generation phase of the compiler.
Explain the difference between Compiler and Interpreter
Define the various system softwares used in compilers
What is the need of system softwares?
Explain various data structures used in assembler design
What is the need of an assembler to be multi pass?
Explain various types of statements used in assembler design
What are the different functions performed by macroprocessor?
Explain Parameterized macro with suitable example
Explain conditional macro with suitable example.
What are the different functions performed by loader
Loader
• A loader is a system program, which takes the object code of a program as input and prepares
it for execution.
• Programmers usually define the Program to be loaded at some predefined location in the
memory.
• But this loading address given by the programmer is not be coordinated with the OS.
• The loader does the job of coordinating with the OS to get initial loading address for the .EXE
file and load it into the memory.

Loader Function: The


loader performs the following functions:
1) Allocation
2) Linking
3) Relocation
4) Loading
Allocation:
• Allocates the space in the memory where the object program would be loaded for Execution.
• It allocates the space for program in the memory, by calculating the size of the program. This
activity is called allocation.
• In absolute loader allocation is done by the programmer and hence it is the duty of the
programmer to ensure that the programs do not get overlap.
• In reloadable loader allocation is done by the loader hence the assembler must supply the
loader the size of the program.
Linking:
• It links two or more object codes and provides the information needed to allow references
between them.
• It resolves the symbolic references (code/data) between the object modules by assigning all
the user subroutine and library subroutine addresses. This activity is called linking.
• In absolute loader linking is done by the programmer as the programmer is aware about the
runtime address of the symbols.
• In relocatable loader, linking is done by the loader and hence the assembler must supply to
the loader, the locations at which the loading is to be done.
Relocation:
• It modifies the object program by changing the certain instructions so that it can be loaded at
different address from location originally specified.
• There are some address dependent locations in the program, such address constants must be
adjusted according to allocated space, such activity done by loader is called relocation.
• In absolute Loader relocation is done by the assembler as the assembler is aware of the
starting address of the program.
• In relocatable loader, relocation is done by the loader and hence assembler must supply to
the loader the location at which relocation is to be done.
Loading:
• It brings the object program into the memory for execution.
• Finally it places all the machine instructions and data of corresponding programs and
subroutines into the memory. Thus program now becomes ready for execution, this activity is
called loading.
• In both the loaders (absolute, relocatable) Loading is done by the loader and hence the
assembler must supply to the loader the object program.
Enlist different types of noodles and explain compile and go loader in detail

Types of Loader :-
There are eight(8) general loader schemes available. But
generally main loader scheme is four(1,2,3,4). Those are –
1. Absolute Loader.
2. Relocating Loader.
3. Direct Linking Loader.
4. Dynamic Loader.
5. Assemble – and – go or Compile – and – go loader.
6. Boot Strap Loader.
7. Linking Loader.
8. Relocation Loader.
Explain the working of absolute loader.
What do you mean by relocation? Explain relocating loader in detail.
Explain the difference between linking loader and linkage editor.
Explain the working of compiler phases for following expression Position = initial + rate * 60.
Explain the role of finite automata in lexical analysis
Design DFA for given finite automata. (a+b)*abb
Differentiate between top down and bottom up parser.
Define synthesized and inherited attributes used in Syntactic analysis of compiler.
Generate three address code for the following logical expression. If a<b then 1 else 0

Design quadruple and triple for following expression a=(b+c)*(d+e)

Design DAG representation for given expression. a=(a+b)*(a-c)


Explain flow graphs and basic blocks in detail.
Write a short note on LEX and YACC.

LEX
-Lex is officially known as a "Lexical Analyser".
-Its main job is to break up an input stream into more usable elements. Or in, other words, to
identify the "interesting bits" in a text file.
-For example, if you are writing a compiler for the C programming language,
the symbols { } ( ); all have significance on their own.
-The letter a usually appears as part of a keyword or variable name, and is not interesting on
its own.
-Instead, we are interested in the whole word. Spaces and newlines are completely
uninteresting, and we want to ignore them completely, unless they appear within quotes "like
this"
-All of these things are handled by the Lexical Analyser.
-A tool widely used to specify lexical analyzers for a variety of languages
-We refer to the tool as Lex compiler, and to its input specification as the Lex language.

How does this Lexical analyzer work?


The lexical analyzer created by Lex behaves in concert with a parser in the following manner.
When activated by the parser, the lexical analyzer begins reading its remaining input, one
character at a time, until it has found the longest prefix of the input that is matched by one of
the regular expressions p.
Then it executes the corresponding action. Typically the action will return control to the
parser.
However, if it does not, then the lexical analyzer proceeds to find more lexemes, until an
action causes control to return to the parser.
The repeated search for lexemes until an explicit return allows the lexical analyzer to process
white space and comments conveniently.

YACC
-Yacc is officially known as a "parser".
-It's job is to analyse the structure of the input stream, and operate of the "big picture".
-In the course of it's normal work, the parser also verifies that the input is syntactically sound.
-Consider again the example of a C-compiler. In the C-language, a word can be a function
name or a variable, depending on whether it is followed by a (or a = There should be exactly
one } for each { in the program.
-YACC stands for "Yet another Compiler Compiler". This is because this kind of analysis of
text files is normally associated with writing compilers.

How does this yacc works?


How does this yacc works?
yacc is designed for use with C code and generates a parser written in C.
The parser is configured for use in conjunction with a lex-generated scanner and relies on
standard shared features (token types, yylval, etc.) and calls the function yylex as a scanner
coroutine.
You provide a grammar specification file, which is traditionally named using a .y extension.
You invoke yacc on the .y file and it creates the y.tab.h and y.tab.c files containing a
thousand or so lines of intense C code that implements an efficient LALR (1) parser for your
grammar, including the code for the actions you specified.

You might also like