【龙书答案】第三章解析(未完成)
来源:互联网 发布:2015年度十大网络剧 编辑:程序博客网 时间:2024/04/30 09:24
Exercise 3.3
Problem 3.3.1
Consult the language reference manuals to determine
The sets of characters that form the input alphabet (exclude those may only appear in character strings or comments).
The lexical form of numerical constants and
The lexical form of identifiers.
for each of the following languages:
C
C++
C#
Fortran
Java
Lisp
SQL
Answer:
Actually this exercise is not that important. Since it will cost much time to search language for each language, which is not worth to do. So we will skip the question first and see whether we have extra time to fill it.
Problem 3.3.2
Describe the languages denoted by the following regular expressions:
a (a | b)* a
((ε|a)b*)*
(a|b)*a(a|b)(a|b)
a*ba*ba*ba*
(aa|bb)((ab|ba)(aa|bb)(ab|ba)(aa|bb))
Answer:
String made up by a’s and b’s and end with a.
Note that this is an arbitrary string make up by a’s and b’s. This is a little bit tricky since I firstly think it cannot form string arbitrarily due to the constraint of a.
This is string made up by a’s and b’s and the third character from last must be a.
String of a’s and b’s but with exactly three b.
String of a’s and b’s that has even number of a and b.
Problem 3.3.3
In a string of length n, how many of the following are there?
Prefixes
Suffixes
Proper prefixes
Substrings
Subsequences
Answer:
Clearly n+1.
Clearly n+1
n-1. Except the empty string and that string itself.
(n+1)n/2 + 1. Just enumerate substrings with length 1,2,3…n. And still need to count the empty string.
There are totally 2^n subsequences, which is a permutation problem.
Problem 3.3.4
Most languages are case sensitive, so keywords can be written only one way, and the regular expressions describing their lexeme is very simple. However, some languages, like SQL, are case insensitive, so a keyword can be written either in lowercase or in uppercase, or in any mixture of cases. Thus, the SQL keyword SELECT can also be written select, Select, or sElEcT, for instance. Show how to write a regular expression for a keyword in a case insensitive language. Illustrate the idea by writing the expression for “select” in SQL.
Answer:
select
→ [Ss][Ee][Ll][Cc][Ee][Tt]
Problem 3.3.5
Write regular definitions for the following languages:
All strings of lowercase letters that contain the five vowels in order.
All strings of lowercase letters in which the letters are in ascending lexicographic order.
Comments, consisting of a string surrounded by /* and /, without an intervening /, unless it is inside double-quotes (“)
All strings of digits with no repeated digits.
Hint: Try this problem first with a few digits, such as {0, 1, 2}.All strings of digits with at most one repeated digit.
All strings of a’s and b’s with an even number of a’s and an odd number of b’s.
The set of Chess moves,in the informal notation,such as p-k4 or kbp*qn.
All strings of a’s and b’s that do not contain the substring abb.
All strings of a’s and b’s that do not contain the subsequence abb.
Answer:
1.
other
→ [bcdfghjklmnpqrstvwxyz]
res→ (other)* a (other | a)* e (other | e)* i (other | i)* o (other | o)* u (other | u)*
注意这里默认了e出现之后的位置不能够再出现a了。原则上符合按顺序的元音字母。
2.
a* b* c*
⋯ z*
这个就是简单的列举一下。
3.
\ / \ * ( [ ^ * ” ] * | ” . * ” | \ * + [ ^ / ] ) * \ * \ /
这个需要解释一下了,[ ^ * ” ] *:除了 * 和 ” 之外所有的符号任意长度的串。
4.5.6.7.
我看了这个答案,要用到状态转换图+状态图简化的一些技巧,我现在还不能看懂,等再过几天看了之后的章节一定会把这里的东西补上。
8.
b*(a+b?)*
终于看到了一个好理解的东西了,首先开头可以出现很多b,然后一旦a出现,就只能有a或者ab了,这就是后面那个闭包的概念。
9.
b* | b*a+ | b*a+ba*
因为其实满足这个条件的字符串不是很多,只有上面三种,所以完全可以枚举达到最终的结果。
Problem 3.3.6
Write character classes for the following sets of characters:
The first ten letters (up to “j”) in either upper or lower case.
The lowercase consonants.
The “digits” in a hexadecimal number (choose either upper or lower case for the “digits” above 9).
The characters that can appear at the end of alegitimate English sentence (e.g. , exclamation point) .
Answer:
1.
[A-Ja-j]
2.
[bcdfghjklmnpqrstvwxzy]
3.
[0-9a-f]
4.
[.?!]
Problem 3.3.7
Note that these regular expressions give all of the following symbols (operator characters) a special meaning:
\ ” . ^ $ [ ] * + ? { } | /
Their special meaning must be turned off if they are needed to represent themselves in a character string. We can do so by quoting the character within a string of length one or more; e.g., the regular expression “**” matches the string ** . We can also get the literal meaning of an operator character by preceding it by a backslash. Thus, the regular expression ** also matches the string **. Write a regular expression that matches the string “\.
Answer:
\”\\
这个很简单的,就是每一个符号前面加一个反斜杠。
Problem 3.3.8-12
To be written.
Exercise 3.4
- 【龙书答案】第三章解析(未完成)
- 【编译原理龙书笔记】(三)词法分析(附联系答案)(仍未完成)
- p122 第三章 第31题 潘璠(未完成)
- p124 第三章 第44题 潘璠(未完成)
- AC++第三章答案
- 思科CCNA第三学期第三章答案
- Opencv第三章练习题答案
- 编译原理答案--第三章
- 学习opencv第三章答案
- 数据挖掘概念与技术(原书第三版)范明 孟小峰译-----第三章课后习题答案
- C#入门经典(第三版)十一章练习题答案
- 第三章 数据类型、运算符与表达式 (答案)
- accelerated c++答案(自写)---第三章
- c++primer第五版课后练习答案(第三章)
- 模板元编程 第三章课后练习(非答案)
- C Primer Plus(第6版)第三章答案
- C++primer第五版第三章答案(1)
- 第三章_课后问题答案(非标准)
- java 值传递 引用传递(又叫地址传递,对象传递)
- 【少年の轨迹】cocos2d-x3.0中LayerColor的锚点的修改
- PHP类与对象,构造函数和析构函数,加上this绑定详解
- Mysql的一条SQL优化(一)
- java笔记22 IO流1(字符流及缓冲区)
- 【龙书答案】第三章解析(未完成)
- 解决升级Xcode6后插件不能用的问题
- 学习笔记:axure 高级教程 2 复选框(添加判断条件)
- 欢迎使用CSDN-markdown编辑器
- 从Code Review 谈如何做技术
- 内部排序(四)归并排序
- 文章标题
- 基于暗通道的图像去雾
- 黑马程序员——java基础——集合(一)