You are on page 1of 3

四川大学期末考试试题(闭卷)

(2020-2021 学年第 1 学期) A卷


课程号: Course Number: 311126030 课程名称: Course Title: Compiler Construction Principles
and Practice 适用专业年级:
学号(Student ID): 姓名(Student Name):
Student Commitment
I have read and comprehended the “Regulations of Sichuan University on Examinations”. I give
commitments as follows:
1. I have put prohibited stationary and exam-related items at designated area as required.
2. I have not brought cell phone to the examination room.
3. D uring t e he I xamination,
w c w t a t illp omplyI t i a ithv he I a bove wo
to accept the punishments in accordance with the relevant provisions.

Signature:
题 号 一(20%) 二(20%) 三(20%) 四(40%)
得 分
卷面总分 教师签名 阅卷时间
注意事项:1. 请务必将本人所在学院、姓名、学号、任课教师姓名等信息准确填写在试题纸和添卷纸上;
2. 请将答案全部填写在本试题纸上;
3. 考试结束,请将试题纸、添卷纸和草稿纸一并交给监考老师。
N o ti c e : 1 . P l e a s e w r i t e y o u r s t u d e n t I D a n d y o u r n a m e i n b o t h e x a m p a p e r s a n d a d d e d a n
precisely;
2.Please write all your answers on this exam paper;
3.Aft er the exam, please hand in exam paper, added answer sheet and scratch papers to examiners all
together.


评阅教师 得分 Part I Answer Questions (20 points, 5 points for each)

1 2 3 4

1. The scanner usually computes possibly several attributes for each token. It is often helpful
to collect all the attributes into a single structured data type. Please define such a structured
data type for a token.

2. Which three basic operations are there in regular expressions?

3. What's the exactly meaning of a rightmost derivation in syntax analysis?


4. What's the disadvantages of an ambiguous grammar in syntax analysis?

注:试题字迹务必清晰,书写工整。 In total 3 pages,This is page 1


教务处试题编号:311-
课程名称: 任课教师: Student ID: Student Name:

Part II Blank filling (20 points, 4 points for each blank)


评阅教师 得分

1 2 3 4 5

1. ________ represent patterns of strings of characters.


2. The ________state is uniquely given by the ________state and the current input character
in a DFA.
3. A derivation begins with ___________ and ends with a string of token symbols.
4. Symbols in the alphabet are called ___________, since they terminate a
derivation.

评阅教师 得分
Part III Lexical-Directed Translations. (20 points, 10 points for each)

1 2

1. C o n s i d e r i n g t h e s i m p l ex, ay,l pz}h ,a bwert i tΣe = r{ e g u l a r e x p r e s s i o n s f o


following character sets:
(1) All strings of the characters that contain at least one x.
(2) A l l s t r i n g s o f t h e c h a r a
y’s

2. Use Thompson's construction to convert the following regular expressions into NFAs
respectively.
(1) a(a|b|c)
(2) (a|b|)*a

评阅教师 得分 Part IV Syntax analysis. (40 points)

1 2 3

1. Give Given the grammar and the string a * b + a.


E → E +T ∨T
T → T∗F∨F
F → a∨b
Write down a leftmost derivation and a parse tree for the above string. (10 points)
2. Given the grammar

Notice: Please write clearly and legibly. In total 3 pages,This is page


教务处试题编号:311-
课程名称: 任课教师: Student ID: Student Name:

S → a S b S|a S|a

Show that this grammar is ambiguous. (10 points)


3. Consider the grammar
S→ S;aT|aT|;aT
T→,aT|,a
(1) Remove the left recursion and left factor this grammar. (10 points)
(2) C o n s Ft ir rua scn ttFd o l ls oe w t s f o r t h e n o n - t e r m i n a l s
(10 points)

Notice: Please write clearly and legibly. In total 3 pages,This is page


教务处试题编号:311-

You might also like