CIT-316
CIT-316
CIT-316
Question: Explain the three (3) main techniques for loop optimization
Question: List and explain three loop optimization technique
Answer :
Str ength Reduction which replaces an expensive (time consuming) operator by
a faster one;
Induction Variable Elimination which eliminates variables from inner loops;
Code Motion which moves pieces of code outside loops.
Question: Mention the semantic errors that can be recognized by the semantic
analyzer
Answer :
1. "identifier not declared"; either omitted declaration or misspelt an identifier.
2. incompatible use of types e.g assigning boolean to strings
3. Parameter or subscript miscount
Question: What is the major role and the categories of optimization within a compiler
Answer: Optimisation within a compiler is concerned with improving in some
way the generated object code while ensuring the result is identical.
Optimisations fall into three categories:
a. Speed: improving the runtime performance of the generated object code.
b. Space: reducing the size of the generated object code
c. Safety: reducing the possibility of data structures becoming corrupted
Question: Suppose we have a grammar G:
1. E → E + T
2. E → T
3. T → T * F
4. T → F
5. F → (E)
6. F → a
Question: What are the different areas that causes problems during the measurement
on the performance of an actual compiler
Question: Outline the problematic areas when considering the performance
measurement of an actual compiler
Answer :
i. multiple r outine calls during lexical analysis for each and every source character
ii. skipping white space during lexical analysis
iii. skipping over a comment
iv. decoding a tightly packed par se table during syntax analysis
v. looking things up in the name table during semantic analysis
vi. determining whether some name is a r eser ved keywor d or a user definable
identifier.
Question: Outline the four actions adopted when implementing the shift reduce
algorithm
Answer :
Actions
a. Shift - push token onto stack
b. Reduce - remove handle from stack and push on corresponding nonterminal
c. Accept - recognise sentence when stack contains only the distinguished symbol and
input is empty
d. Er r or - happens when none of the above is possible; means original input was not
a sentence.
Question: With sample representations, describe the various types of parse trees.
Answer :
Question: Generate the corresponding target machine code for the expression in prev
Answer :
LOAD R1, a // Step 1: Load a into R1
LOAD R2, b // Step 1: Load b into R2
SUB R1, R2 // Step 1: R1 = a - b (t1)
Answer :
Question: What are the drawbacks of syntax analyzer that makes semantic analysis
phase very important
Answer :
1. Lack of Meaningful Interpretation
2. No Type Checking
3. No Type Checking
4. No Control Flow Analysis
5. No Enforcement of Language-Specific Constraints
Question: Write down what is involved when considering code generation task
Answer :
Question: Enumerate the errors which can be detected during lexical analysis
Question: Discuss the following (include examples where possible)
Answer :
i. Errors during Lexical Analysis:
a) Strange characters: Some programming languages do not use all possible
characters, so any strange ones which appear can be reported.
b) Long quoted strings I: Many programming languages do not allow quoted
strings to extend over more than one line; in such cases a missing quote can
be detected.
c) Invalid numbers: A number such as 123.45.67 could be detected as invalid
during lexical analysis
ii. Errors during Syntax Analysis: during syntax analysis the compiler automatically
generate a useful error message just by listing the tokens which would be acceptable
at that point.
iii. Errors during Semantic Analysis: One of the most common errors reported during
semantic analysis is
a) "identifier not declared”,
b) others include incompatible type, or
c) parameter miscount
Question: Enumerate five (5) common run-time errors which can be detected by most
IDEs with its debugging option
Answer :
attempt to divide by 0
overflow (and possibly underflow) during arithmetic operations.
attempt to use a variable before it has been set (undefined variable)
attempt to refer to a non-existent array element (invalid subscript).
attempt to set a variable to some value outside its range
various errors related to pointers:
Attempt to use a pointer before it has been set
attempt to use a nil pointer
attempt to use a pointer which points outside an array
attempt to use a pointer after the memory it points to has been released.
Question: Describe any three (3) structures which can be used to implement symbol
tables (include the computational complexity of each structure)
Answer :
a. Linear List
a) O(n) probes per lookup
b) easy to expand — no fixed size
c) one allocation per insertion
b. Or der ed Linear List
a) O(log2 n) probes per lookup using binary search
b) insertion is expensive (to reorganise list)
c. Binar y Tr ee
a) O(n) probes per lookup, if the tree is unbalanced
b) O(log2 n) probes per lookup, if the tree is balanced
c) easy to expand with no fixed size
d) one allocation per insertion
d. Hash Table
a) O(1) probes per lookup on the average
b) expansion costs vary with specific scheme
Question: Using a diagram, show the syntactic divisions within a Formal System.
Answer :
Symbols and strings of symbols may be broadly divided into nonsense and
wellformed formulas. The set of well-formed formulas is divided into theorems and
non-theorems. However, quite often, a formal system will simply define all of its
well-formed formula as theorems.
Question: In top-down parsing, order of trying the alternatives may influence getting
the input or not.
Answer
i) State the method that can be used to overcome this.
factor ing i.e left factoring is used to ensure that the right sequence/order is used.
ii. Hence given the grammar,
G: A → αβ
A → αγ
How do we get rid of this dilemma using the method stated in (i) above?
We can get rid of
this dilemma by using left factoring to determine the right sequence.
That is the above becomes:
A → αA’
A’ → β | γ
Question: Briefly describe the utilities provided by the operating system to execute
the object code generated by the compiler.
a. linking: A linker takes several object files and libraries as input and produces one
executable object file.
b. loading: A loader loads an executable object file into memory, initialises the
registers, heap, data, etc. and starts the execution of the programme.
c. Relocatable shar ed libr ar ies: allow effective memory use when many different
applications share the same code.