




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Exam of Advanced Compiler Design and its key important points are: Context-Free Grammar, Regular Expression, Even Number, Input Text, Different Parse Trees, Right-Most Derivations, String Abab, Pair of Double Quotes, Lex Specification, Simplified Grammar
Typology: Exams
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Mid-term Exam
ID Numb er :
Name :
MAKE SURE YOU HAVE FILLED IN YOUR NAME AND ID NUMBER IN THE SPACE ABOVE.
The exam for undergraduate students is di erent from the exam for the graduate students. Make sure you are reading the correct question pap er.
Doubts ab out the questions will b e answered only in the rst 15 minutes of the exam. So, read the questions carefully at the b eginning of the exam.
Write your answers in the space provided.
Keep your answers brief and precise.
The exam consists of 5 questions, in 8 pages (including this page) for a total of 110 p oints.
You may attempt all questions. However, the maximum you can score in this exam is 100 p oints.
GOOD LUCK!
Question Points
Total
L 1 : strings over fa; bg such that every a is immediately followed by at least one b. L 2 : strings over fa; bg such that every a is immediately followed by at most one b. L 3 : strings over fa; bg such that the numb er of a's is same as the numb er of b's.
a. (7 p oints) Is L 1 a regular language? If so, write a regular expression corresp onding to L 1. If not, explain why not.
b. (7 p oints) Is L 2 a regular language? If so, write a regular expression corresp onding to L 2. If not, explain why not.
b. (6 p oints) Is L 3 a regular language? If so, write a regular expression corresp onding to L 3. If not, explain why not.
S ! AaAb S ! B b A ! B !
a. (6 p oints)
a. (6 p oints)
c. (8 p oints) Is G 3 LL(1)? Justify.
S ! AaAb S ! B b A ! B !
Your work must show the item set construction (10 p oints); the SLR action table (Shift entries: 8 p oints, Reduce entries: 4 p oints); and the goto table (3 p oints).
new_operator operator id precedence associativity
where operator id is a sequence of non-white-space characters; precedence is one of high, medium and low; and associativity is one of left and right. The operator id , precedence , associativity elds are separated by one or more whitespace characters. For instance, new op erators /" and \/" which are b oth left-asso ciative such that /" has higher precedence than \/" can b e de ned using this syntax as: the usual de nition of *" and +" w
new_operator /\ high left new_operator / medium left
a. (4 p oints) Consider an op erator #" de ned over expressions e such that e 1 #e 2 #e 3 is equivalent to e 1 #(e 2 #e 3 ) and not same as (e 1 #e 2 )#e 3. Is #" left-asso ciative/right- asso ciative/non-asso ciative?
b. (4 p oints) Consider an op erator |" de ned over expressions e such that e 1 |e 2 |e 3 is equivalent to (e 1 |e 2 )|e 3 and not same as e 1 |(e 2 |e 3 ). Is |" left-asso ciative/right- asso ciative/non-asso ciative?
c. (7 p oints) Using the new_operator construct describ ed ab ove, write the de ntions of #" and |" given that e 1 |e 2 #e 3 is equivalent to e 1 |(e 2 #e 3 ) and not to (e 1 |e 2 )#e 3.
[Continued on next page]
d. (10 p oints) Describ e how you will build a scanner and parser for a language that allows user-de ned op erators using Lex and Bison. You need not write Lex or Bison co de. Describ e how the grammar for expressions would lo ok like, how you would enco de this grammar in Bison, and how tokens for this grammar will b e generated by a scanner built using Lex, and what the symb ol tables would contain. [Hint: With only 3 precedence levels and 2 asso ciativity directions, six abstract op erators can b e used to represent the user-de ned ones.]
END OF EXAM (page 8)