Regular Language - Advanced Compiler Design - Exam, Exams of Computer Science

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

2012/2013

Uploaded on 03/19/2013

dharmaa
dharmaa 🇮🇳

4.4

(19)

149 documents

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE-304 Compiler Design
Fall 2000
Mid-term Exam
Oct 31, 2000.
Duration: 1 hour, 10 minutes.
ID Number :
Name :
INSTRUCTIONS
Read the following carefully before answering any question.
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 paper.
Doubts about the questions will be answered only in the rst 15 minutes of the exam. So, read the
questions carefully at the beginning 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
points.
You may attempt all questions. However, the maximum you can score in this exam is
100
points.
GOOD LUCK!
Question Points
1.
2.
3.
4.
5.
Total
1
Docsity.com
pf3
pf4
pf5
pf8

Partial preview of the text

Download Regular Language - Advanced Compiler Design - Exam and more Exams Computer Science in PDF only on Docsity!

CSE-304 Compiler Design

Fall 2000

Mid-term Exam

Oct 31, 2000.

Duration: 1 hour, 10 minutes.

ID Numb er :

Name :

INSTRUCTIONS

Read the following carefully b efore answering any question.

 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

  1. [Total: 20 p oints] Consider the following two languages:

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.

  1. [Total: 25 p oints] Consider the context-free grammar G 3 :

S ! AaAb S ! B b A !  B ! 

a. (6 p oints)

F I R S T (A) =

F I R S T (B ) =

F I R S T (S ) =

a. (6 p oints)

F O LLO W (S ) =

F O LLO W (A) =

F O LLO W (B ) =

c. (8 p oints) Is G 3 LL(1)? Justify.

  1. [Total: 25 p oints] Give the SLR parsing table (action and goto table) for the following grammar (same as G 3 ):

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).

  1. [Total 25 p oints]Some langauges allow users to de ne new in x op erators in their programs; then the users also sp ecify the asso ciativity and precedence of these op erators. Assume that the new op erators are de ned using the syntax:

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)