You are on page 1of 1

Done (10th-Nov-2022)

Week 6 – Test1 – Alpha 2022/23 Session

CSC313 – Compiler Construction

Question 1

Use tree diagrams to exhaustively capture

a) compiler as a part of computer


b) the relationship among all components of compiler translation process
c) Copy and complete the table

Component Input Processing tool Output Example (A=B+C)


Scanner Source --- Token streams ---
code
--- --- Context-free --- ---
grammar
--- --- --- --- ---
--- --- --- --- ---
--- --- Pattern matching Optimised TAC, ---
algorithms Quad
Target code generator --- --- Assembly code, ---
target code
--- --- Pattern matching Assembly code, ---
algorithms final target code

Question 2

Consider the context-free grammar: S -> SS+ | SS* | a

a) Show how the string aa+a* can be generated by this grammar.


b) Construct a parse tree for this string.
c) Copy and complete the table

Grammar Type Language Production rule Application in


compiler for
programming
languages
Type 0
Type 1
Type 2
Type 3

Question 3

a) In your own words, describe a ‘recursive descent parser’


b) Consider the context-free grammar production rule (P: S-->S-|SS*|a), show how the string a-a*-a*
can be generated.
c) Consider the context-free grammar production rule (P: S-->aSbS|bSaS|E), show that this grammar is
ambiguous by finding an example string of terminals a and b that results in two or more parse trees.
Also show that the grammar is ambiguous by finding the 2 different parse trees that exist for string
w = abab

You might also like