100% found this document useful (3 votes)
780 views3 pages

The Mid-Term Exam of Compiler

1. This document is a mid-term examination for a compiler construction course at Sichuan University. 2. It consists of 5 parts testing knowledge of compiler principles and design, regular expressions, finite automata, and converting between models. 3. The student must answer questions, identify true/false statements, fill in blanks, perform regular expression and finite automata conversions, and write pseudocode to implement a DFA.

Uploaded by

MD RIAZ HASAN
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
100% found this document useful (3 votes)
780 views3 pages

The Mid-Term Exam of Compiler

1. This document is a mid-term examination for a compiler construction course at Sichuan University. 2. It consists of 5 parts testing knowledge of compiler principles and design, regular expressions, finite automata, and converting between models. 3. The student must answer questions, identify true/false statements, fill in blanks, perform regular expression and finite automata conversions, and write pseudocode to implement a DFA.

Uploaded by

MD RIAZ HASAN
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/ 3

Sichuan University Mid-term Examination

(Closed Book)
(2020-2021 Academic Year 1st Semester)

课程号 Course Number: 311126030 课程名称 Course Title: Compiler Construction Principles and Practice
任课教师 Lecturer: 考试时间 Time Period:
学生姓名 Name: 学号 Student ID: 成绩 Total Mark:

考 生 承 诺

Student Commitment
我已认真阅读并知晓《四川大学考场规则》和《四川大学本科学生考试违纪作弊处分规定(修
订)》,郑重承诺:
I have read and comprehended the “Regulations of Sichuan University on Examinations”. I give my
commitments as follows:
1、已按要求将考试禁止携带的文具用品或与考试有关的物品放置在指定地点;
1. I have put prohibited stationary and exam-related items at designated area as required.
2、不带手机进入考场;
2. I have not brought cell phone to the examination room.
3、考试期间遵守以上两项规定,若有违规行为,同意按照有关条款接受处理。
3. During the examination, I will comply with the above two provisions. If there is any violation, I
agree to accept the punishments in accordance with the relevant provisions.
考生签名:
Signature:
Part I Answer Questions (30 points, 5 points for each)

1. A compiler translates a source program written in its source language to an equivalent


program written in its target language. What does "an equivalent program" usually refer
to?
2. What's the major difference between an interpreter and a compiler?
3. Please list the phases of a complier which may indeed be written as separately coded
operations.
4. The scanner performs what is called lexical analysis. What’s the task of the scanner in
lexical analysis?
5. Which special meta-character or symbol is used to denote the empty string in regular
expression?
第 1 页,共 3 页(Page 1 of Total Page 3 )
6. What’s the exactly meaning of ε-closure in lexical analysis?
Part II True or False Choice (16 points, 2 points for each)
1. An interpreter is a language translator like a compiler. It executes object code after
translation is complete.
2. A preprocessor is a separate program that collects code separately compiled or assembled
in different object files into a file.
3. The logical units the scanner generates are called tokens, which is much like forming
characters into words in an English sentence.
4. Regular expression represent patterns of strings of characters, which is completely defined
by the set of strings that it matches.
5. The concatenation of two regular expressions r and s is written as r|s, and it matches any
string that is the concatenation of two strings.
6. An expression of the form rs, where r and s are regular expressions, in this case, L(rs) =
L(r)∪L(s).
7. Consider the following statement written by java:
string name = “compiler”;
, and it can be divide into six tokens.
8. An ε-transition is a transition that may occur without consulting the input string, and it can
be viewed as a “match” of the empty string.
Part III Blank filling (10 points, 2 points for each blank)
1. A (An) ________ is a translator for the assembly language of a particular computer.
2. Tokens fall into three categories: ________, special symbols and other tokens such as
NUM and ID.
3. If r and s are regular expressions, then r|s is a regular expression which matches any string
that is matched either by ________ or by ________.
4. The ________ is uniquely given by the current state and the current input character in DFA
(Deterministic Finite Automata).

第 2 页,共 3 页(Page 2 of Total Page 3 )


Part IV Lexical-Directed Translations. (34 points)
1. Considering the simple alphabet Σ={a, b, c}, write regular expressions for the
following character sets: (3 points for each)
a) All strings of letters that begin and end in a.
b) All strings of the characters that contain at least one c.
c) All strings of the characters that contain two consecutive b’s.
d) All strings that contain at least one a and at least one b.

2. Use Thompson's construction to convert the following regular expressions into NFAs
respectively. (4 points for each)
a) a|ab
b) a(a|b)*
c) (aa|b)*a

3. Convert the following NFA into an equivalent DFA using the subset construction, and
provide detailed steps. (10 points)

Part V Programming
(10 points)
1. Translate the following DFA into pseudocode using a doubly nested case statement
inside a loop, where the first case statement tests the current state and the nested second
level tests the input character.
a
a [other]
1 2 3

第 3 页,共 3 页(Page 3 of Total Page 3 )

You might also like