0% found this document useful (0 votes)
14 views

Assignment (MODULE-1) : T 1:a? (B C) A T 2:b? (A C) B T 3:c ? (B A) C ' X? ' Bbaacabc

The document contains questions about compiler phases, lexical analysis, finite automata, regular expressions, ambiguous grammars, and compiler writing tools. Question 1 asks to illustrate compiler phases for an assignment statement. Question 2 asks to determine the sequence of tokens output by a lexical analyzer for a given string. Question 3 asks about the role of lexical analysis and the number of tokens identified. Question 4 asks to construct a DFA and regular expression. Question 5 asks to describe compiler writing tools like LEX and YACC. Question 6 asks to check if a grammar is ambiguous and remove ambiguity.

Uploaded by

Ansh Kundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Assignment (MODULE-1) : T 1:a? (B C) A T 2:b? (A C) B T 3:c ? (B A) C ' X? ' Bbaacabc

The document contains questions about compiler phases, lexical analysis, finite automata, regular expressions, ambiguous grammars, and compiler writing tools. Question 1 asks to illustrate compiler phases for an assignment statement. Question 2 asks to determine the sequence of tokens output by a lexical analyzer for a given string. Question 3 asks about the role of lexical analysis and the number of tokens identified. Question 4 asks to construct a DFA and regular expression. Question 5 asks to describe compiler writing tools like LEX and YACC. Question 6 asks to check if a grammar is ambiguous and remove ambiguity.

Uploaded by

Ansh Kundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment (MODULE-1)

Q.1 Illustrate phases of compiler with an assignment statement

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}

B. L= {na ( w ) mod 3=2∧n b ( w ) mod 2=0| where

' ' 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→ NOT Bexp

Bexp→ TRUE

Bexp→ FALSE

You might also like