【龙书答案】第三章解析(未完成)

本文详细解答了《龙书》第三章的多项练习题,涉及各种编程语言的字符集、词汇形式,以及如何用正则表达式描述语言,包括C、C++、C#等,并探讨了大小写敏感语言的关键词处理,如SQL。
摘要由CSDN通过智能技术生成

Exercise 3.3


Problem 3.3.1

Consult the language reference manuals to determine

  1. The sets of characters that form the input alphabet (exclude those may only appear in character strings or comments).

  2. The lexical form of numerical constants and

  3. The lexical form of identifiers.

for each of the following languages:

  1. C

  2. C++

  3. C#

  4. Fortran

  5. Java

  6. Lisp

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

  1. a (a | b)* a

  2. ((ε|a)b*)*

  3. (a|b)*a(a|b)(a|b)

  4. a*ba*ba*ba*

  5. (aa|bb)((ab|ba)(aa|bb)(ab|ba)(aa|bb))

Answer:

  1. String made up by a’s and b’s and end with a.

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

  3. This is string made up by a’s and b’s and the third character from last must be a.

  4. String of a’s and b’s but with exactly three b.

  5. 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?

  1. Prefixes

  2. Suffixes

  3. Proper prefixes

  4. Substrings

  5. Subsequences

Answer:

  1. Clearly n+1.

  2. Clearly n+1

  3. n-1. Except the empty string and that string itself.

  4. (n+1)n/2 + 1. Just enumerate substrings with length 1,2,3…n. And still need to count the empty string.

  5. There are totally 2^n subsequences, which is a permutation problem.


Problem 3.3.4

Most languages are case sensiti

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值