编译原理与实践第二章答案.doc_第1页
编译原理与实践第二章答案.doc_第2页
编译原理与实践第二章答案.doc_第3页
编译原理与实践第二章答案.doc_第4页
编译原理与实践第二章答案.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

The exercises of Chapter Two2.1 Write regular expression for the following character sets, or give reasons why no regular expression can be written:a. All strings of lowercase letters that begin and end in a.Solutionaa-z*a | ab. All strings of lowercase letters that either begin or end in a ( or both)both:a(a|b|c|z)* ac. All strings of digits that contain no leading zerosSolution1-90-9*d. All strings of digits that represent even numbers(0|1|2|9)*(0|2|4|6|8)e. All strings of digits such that all the 2s occur before all the 9sSolutiona=(0|1|3|4|5|6|7|8)r=(2|a)*(9|a)or9*2*or9*2(1|3-8)*92*g. All strings of as and bs that contain an odd number of as or an odd number of bs(or both)Solutionr1=b*a(b|ab*a)*-odd number of asr2= a*b(a|ba*b)*-odd number of bsr1|r2|r1r2|r2r1orb*a(b*ab*a)*b*|a*b(a*ba*b)*a*i. All strings of as and bs that contain exactly as many as as bsSolutionNo regular expression can be written, as regular expression can not count.2.2 Write English descriptions for the languages generated by the following regular expressions:a. (a|b)*a(a|b|)SolutionAll the strings of as and bs that end with a, ab or aa.OrAll the strings of as and bs that do not end with bb.b. All words in the English alphabet of one or more letters, which start with one capital letter and dont contain any other capital letters.c. (aa|b)*(a|bb)*SolutionAll the strings of as and bs that can be divided into two sub-stings, where in the left substring, the even number of consecutive as are separated by bs while in the right substring, the even number of consecutive b are separated by as.d. All hexadecimal numbers of length one or more, using the numbers zero through nine and capital letters A through F, and they are denoted with a lower or uppercase “x” at the end of the number string.2.12 a. Use Thompsons construction to convert the regular expression (a|b)*a(a|b|) into an NFA.b. Convert the NFA of part (a) into a DFA using the subset construction.Solutiona. An NFA of the regular expression (a|b)*a(a|b|)babaa751234689171112131415161810b. The subsets constructed as follows: 7 = 7, 5,1,3,8,9 7 a = 2, 10 7 b= 42,10 = 2,6,5,1,3,8,9, 10,17,11,13,15,16,18baa12345aaabbbb2,10a = 2, 10, 122,10b =4, 142,10,12 = 2,6,5,1,3,8,9,12,18,10,17,11,13,15,162,10,12a = 2,10,122,10,12b = 4, 144,14 = 4,6,5,1,3,8,9,14,184,14a = 2,104,14b = 44 = 4,6,5,1,3,8,94a =2,104b =42.15rFigure 1 r*sFigure 2 s*Assume we have r* and s* according to figure 1 and 2:rsFigure 2 r*s*Consider r*s* as followThis accepts, for example, rsrs which is not in r*s*. I. e., in this case we cannot eliminate the concatenating transition.2.16 Apply the state minimization algorithm of section 2.4.4 to the following DFAs:cc12435aba. Solutiona. Step 1: Divide the state set into two subsets:1, 2, 34, 5 Step 2: Further divide the subset 1,2,3 into two new subsets:12, 3 Step 3: Can not divide the subsets any more, finally obtains three subsets:12, 34, 5Therefore, the minimized DFA is:cc12435abSolutionb. Step 1: Divide the state set into two subsets:1, 23, 4, 5 Step 2: Further divide the subset 1,2 into two new subsets:12 Step 2: Further divide the

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论