Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Give the recognized tokens of the following program in Pascal.

function max ( i , j : integer) : integer;

{ return the maximum of integers i and j }

begin

if i > j the n max := i else max := j

end;

解:由题意可知在该段程序中存在的记号(token)有如下:

记号类型 记号名称

Identifiers max, i, j

Reserved Words function, integer, begin, if, then, else, end

Constants “return the maximum of integers i and j”

Operators >, :=

Punctuation (,,,:, ),;, {, }

Describe the languages denoted by the following regular expressions:

 a (a | b)* a

 a* b a* b a* b a*

解:对于正则表达式 a (a | b)* a,它所表示的集合为{aa, aaa, aba, aaba, …}。用自然语言

可描述为, 首先串的开头和结尾均为一个字母 a,而中间部分则可以由任意多个字母 a

或字母 b 组成, 其中的任意多个指零个或者零个以上。

对于正则表达式 a* b a* b a* b a*, 它所表示的集合为{bbb, abbb, abbaba, …}。用

自然语言可描述为,首先串包含 3 个字母 b,然后在任意字母 b 的前后位置均可插入


任意多个字母 a,其中的任意多个指零个或者零个以上。

Most Languages are case sensitive, so keywords can be written only one

way, and the regular expressions describing their lexemes are very simple.

However, some languages, like Pascal and SQL, are case in sensitive. For E-

xample, the SQL keyword SELECT can also be written select, Select or sEL-

EcT.

 Show how to write a regular expression for a keyword in a case insensitive

language. Illustrate your idea by writing the expression for SELECT in SQL.

解:1) 首先对于一个关键字丌区分大小写的语言,其关键字的正则表达式可书写如下:

(a | b | … | z | A | B | … | Z)((a | b | … | z | A | B | … | Z)| ( 0 | 1 | … | 9 ))*

2) 对于 SQL 语言中的 SELECT 关键字可书写它的正则表达式如下:

(S | s)( E | e)( L | l )( E | e)( C | c)( T | t)

You might also like