Assignment (MODULE-1) : T 1:a? (B C) A T 2:b? (A C) B T 3:c ? (B A) C ' X? ' Bbaacabc
Assignment (MODULE-1) : T 1:a? (B C) A T 2:b? (A C) B T 3:c ? (B A) C ' X? ' Bbaacabc
a=(b+c)*(b+c)*2
Show the output of the given statement after passing to every phase of a compiler
Q.2 A lexical analyser uses the following patterns to recognize three tokens T1,T2 and T3 over
the alphabet {a , b , c }.
T 1 :a ? (b∨c)∗a
T 2 :b ? (a∨c)∗b
T 3 :c ?(b∨a)∗c
Note that ' x ? ' means 0 or 1 occurrence of the symbol x. Note also that the analyzer outputs the
token that matches the longest possible prefix. If the string bbaacabc is processed by the
analyser, then find the sequence of tokens it outputs? (For example, output may be T1T2T3 or
T1T1T3 or T2T2 etc.)
Q.3: Discuss the role of Lexical Analyzer. Find the Number of Tokens identified by Lexical
Analysis phase for the following program fragment.
a ¿ ∫ max ( x , y ) b¿
∫x , y; ∫ main()
¿∗find maximum of x∧ y∗¿ {
{ Printf ( “ %d welcome¿CSE 303 course” ,∧x ) ;
return (x> y ? x : y) }
}
c) d)
main( ) main( )
{ {
a=b++±−−∓++¿=; ∫ a=10 ;
} char b=” abc ” ;
¿ t c =30;
ch ar d =” xyz ”;
¿ /¿ comment∗¿ t m=40.5;
}
Q.4 Construct a DFA for the following language over and find its Regular expression also?
A. L= { an bm c k|n , m, k ≥ 1}
' ' w
n a ( w )∧n b ( w ) is a number of a s∧no . of b s ∈ ={a , b }}
Σ
C. Accept the set of all strings over Σ= { a ,b } , which when interpreted as binary number is
divisible by 3. For example the set of accepted strings are {∈ , 0,11,110,1001, … . }
Q.5 Describe various compiler writing tools? Explain LEX and YACC.
Q.6 Check whether the following grammar is ambiguous or not? If yes, remove its ambiguity
and write its equivalent unambiguous grammar.
a) E → E + E/ E∗E/ E ↑ E /id
b) Bexp→ Bexp∨Bexp
Bexp→ Bexp∧Bexp
Bexp→ TRUE
Bexp→ FALSE