编译原理紫龙书(Compilers:Principles,Techniques and Tools Second Edition)部分答案

来源:互联网 发布:如何将程序导入单片机 编辑:程序博客网 时间:2024/04/19 02:11

3.3.2 : Describe the languages denoted by the following regular expressions:

2: 所有的由ab组成的串。

3: This regular expression denotes the language that takes zero or many instances of “a” or “b” as the prefix, followed with an “a”, ended with a string in{aa,ab,ba,bb}.

3.3.5

6 All strings of a's and b's with an even number of a's and an odd number of b's.

 even_a_even_b →aa|bb*  ((ab|ba)(aa|bb)*(ab|ba)(aa|bb)*)*

even_a_odd_b→ b even_a_even_b  |  a (aa|bb)*(ab|ba) even_a_even_b

 

对于偶数个a和奇数个b构成的串,其第一个字符可能是ab

1)如果是b,那么剩下的部分一定是偶数个a和偶数个b

2)如果是a,那么经过若干个aabb,一定会出现一个abba,才能保证a的个数是偶数,b的个数是奇数。若串还没有结束,剩余部分一定是偶数个a和偶数个b

 

8 b*a* | b* | a*)(aa*b)*a*  |  (b*a*|b*|a*)(ba*a)*(a*|b)      

9:  b*a* ba*  | b* a*

 

 


3.5.2

%{

           FILE * fp  = fopen(“copyfile”,”w”);

%}

           non_whitespace [ASCII or characters expect blank, tab and newline]

           whitespace    [ blank and /t/n]

%%

           {whitespace}+  {fprint(fp,%c,’  ‘);}

           {non_whitespace}   {fprint(fp,%c,yytext[0]);}

 

3.6.5

1:

State

a

b

e

0

{0,1}

{0}

1

{1,2}

{1}

2

{2}

{2,3}

{0}

3