ZIP实验2- 词法分析(一).zip 656.66KB

Hu_F_Tao

资源文件列表:

实验2- 词法分析(一).zip 大约有8个文件
  1. 实验2- 词法分析(一)/实验2参考/
  2. 实验2- 词法分析(一)/TESTscan.c 3.66KB
  3. 实验2- 词法分析(一)/TEST编译演示.exe 3.29MB
  4. 实验2- 词法分析(一)/实验2 词法分析(一).doc 31.5KB
  5. 实验2- 词法分析(一)/实验2参考/词法分析1.doc 33.5KB
  6. 实验2- 词法分析(一)/实验2参考/词法分析2.doc 29KB
  7. 实验2- 词法分析(一)/实验2参考/词法分析3.doc 10.5KB
  8. 实验2- 词法分析(一)/实验2参考/词法分析4.doc 24.5KB

资源介绍:

实验2- 词法分析(一).zip
<link href="/image.php?url=https://csdnimg.cn/release/download_crawler_static/css/base.min.css" rel="stylesheet"/><link href="/image.php?url=https://csdnimg.cn/release/download_crawler_static/css/fancy.min.css" rel="stylesheet"/><link href="/image.php?url=https://csdnimg.cn/release/download_crawler_static/89917449/raw.css" rel="stylesheet"/><div id="sidebar" style="display: none"><div id="outline"></div></div><div class="pf w0 h0" data-page-no="1" id="pf1"><div class="pc pc1 w0 h0"><img alt="" class="bi x0 y0 w1 h1" src="/image.php?url=https://csdnimg.cn/release/download_crawler_static/89917449/bg1.jpg"/><div class="c x1 y1 w2 h2"><div class="t m0 x2 h3 y2 ff1 fs0 fc0 sc0 ls0 ws0">以下为主分析函数</div><div class="t m0 x2 h3 y3 ff1 fs0 fc0 sc0 ls0 ws0">从输入文件里面读,把分析结果写到输出文件中</div><div class="t m0 x2 h3 y4 ff1 fs0 fc0 sc0 ls0 ws0">参数:<span class="ff2">fpin </span>:输入文件指针<span class="ff2"> fpout: </span>输出文件指针</div><div class="t m0 x2 h3 y5 ff2 fs0 fc0 sc0 ls0 ws0">********************************************************************/</div><div class="t m0 x2 h3 y6 ff2 fs0 fc0 sc0 ls0 ws0">void parse(FILE* fpin,FILE* fpout)</div><div class="t m0 x2 h3 y7 ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x3 h3 y8 ff2 fs0 fc0 sc0 ls0 ws0">char arr[MAXBUF];//<span class="ff1">读出的最长的字符串不超过<span class="_ _0"> </span></span>MAXBUF,MAXBUF<span class="_ _0"> </span><span class="ff1">定义为<span class="_ _0"> </span></span>255<span class="ff1">,</span></div><div class="t m0 x4 h3 y9 ff1 fs0 fc0 sc0 ls0 ws0">够长了我想</div><div class="t m0 x4 h3 ya ff2 fs0 fc0 sc0 ls0 ws0">int i=0;//<span class="ff1">分析含字母的字符串用</span></div><div class="t m0 x4 h3 yb ff2 fs0 fc0 sc0 ls0 ws0">int j=0;//<span class="ff1">分析纯数字的字符串用</span></div><div class="t m0 x4 h3 yc ff2 fs0 fc0 sc0 ls0 ws0">while(1)</div><div class="t m0 x4 h3 yd ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x4 h3 ye ff2 fs0 fc0 sc0 ls0 ws0">fscanf(fpin,"%c",&amp;ch);//<span class="ff1">从输入文件中读入一个字符</span></div><div class="t m0 x3 h3 yf ff2 fs0 fc0 sc0 ls0 ws0">if( ch==' '|| ch ==' ')//<span class="ff1">过滤掉空格和<span class="_ _0"> </span></span>tab</div><div class="t m0 x5 h3 y10 ff2 fs0 fc0 sc0 ls0 ws0">;</div><div class="t m0 x3 h3 y11 ff2 fs0 fc0 sc0 ls0 ws0">else if( ch=='')//<span class="ff1">回车换行符,为下面进行错误判断</span></div><div class="t m0 x5 h3 y12 ff2 fs0 fc0 sc0 ls0 ws0">lineno++;</div><div class="t m0 x3 h3 y13 ff2 fs0 fc0 sc0 ls0 ws0">else if( IsDigit(ch))//<span class="ff1">读入的是数字</span></div><div class="t m0 x3 h3 y14 ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x5 h3 y15 ff2 fs0 fc0 sc0 ls0 ws0">while(IsDigit(ch))</div><div class="t m0 x5 h3 y16 ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x6 h3 y17 ff2 fs0 fc0 sc0 ls0 ws0">arr[j] = ch;</div><div class="t m0 x6 h3 y18 ff2 fs0 fc0 sc0 ls0 ws0">j++;</div><div class="t m0 x6 h3 y19 ff2 fs0 fc0 sc0 ls0 ws0">fscanf(fpin,"%c",&amp;ch);</div><div class="t m0 x5 h3 y1a ff2 fs0 fc0 sc0 ls0 ws0">}</div><div class="t m0 x3 h3 y1b ff2 fs0 fc0 sc0 ls0 ws0">fseek(fpin,-1L,SEEK_CUR);//<span class="ff1">文件指针后退一个字节</span></div><div class="t m0 x5 h3 y1c ff2 fs0 fc0 sc0 ls0 ws0">char* temp1 =(char*)malloc(j+1);/</div><div class="t m0 x5 h3 y1d ff2 fs0 fc0 sc0 ls0 ws0">memcpy(temp1,arr,j);</div><div class="t m0 x5 h3 y1e ff2 fs0 fc0 sc0 ls0 ws0">temp1[j] ='';//<span class="ff1">把数组里面的内容拷贝到连外一个数组里面,<span class="_ _1"></span>因为我定</span></div><div class="t m0 x2 h3 y1f ff1 fs0 fc0 sc0 ls0 ws0">义的</div><div class="t m0 x5 h3 y20 ff2 fs0 fc0 sc0 ls0 ws0">//arr<span class="_ _0"> </span><span class="ff1">为<span class="_ _0"> </span></span>255<span class="_ _0"> </span><span class="ff1">个字节,实际上写不到那么多,所以只拷贝实际上有数据的</span></div><div class="t m0 x5 h3 y21 ff2 fs0 fc0 sc0 ls0 ws0">j=0;//<span class="ff1">恢复初始状态,以备下次使用</span></div><div class="t m0 x5 h3 y22 ff2 fs0 fc0 sc0 ls0 ws0">fprintf(fpout,"%s %d",temp1,2);//<span class="ff1">常数</span></div><div class="t m0 x5 h3 y23 ff2 fs0 fc0 sc0 ls0 ws0">free(temp1);//<span class="ff1">释放内存</span></div></div></div><div class="pi" data-data='{"ctm":[1.611830,0.000000,0.000000,1.611830,0.000000,0.000000]}'></div></div><div id="pf2" class="pf w0 h0" data-page-no="2"><div class="pc pc2 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="/image.php?url=https://csdnimg.cn/release/download_crawler_static/89917449/bg2.jpg"><div class="c x1 y1 w2 h2"><div class="t m0 x3 h3 y3 ff2 fs0 fc0 sc0 ls0 ws0">}</div><div class="t m0 x3 h3 y5 ff2 fs0 fc0 sc0 ls0 ws0">else if(IsAlpha(ch))//<span class="ff1">&#26159;&#23383;&#27597;&#24320;&#22836;&#30340;</span></div><div class="t m0 x3 h3 y6 ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x5 h3 y8 ff2 fs0 fc0 sc0 ls0 ws0">while(IsAlpha(ch) || IsDigit(ch))</div><div class="t m0 x5 h3 y24 ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x6 h3 ya ff2 fs0 fc0 sc0 ls0 ws0">arr[i] =ch;</div><div class="t m0 x6 h3 yb ff2 fs0 fc0 sc0 ls0 ws0">i++;</div><div class="t m0 x6 h3 y25 ff2 fs0 fc0 sc0 ls0 ws0">fscanf(fpin,"%c",&amp;ch);</div><div class="t m0 x5 h3 yc ff2 fs0 fc0 sc0 ls0 ws0">}</div><div class="t m0 x5 h3 yd ff2 fs0 fc0 sc0 ls0 ws0">fseek(fpin,-1L,SEEK_CUR);</div><div class="t m0 x5 h3 y26 ff2 fs0 fc0 sc0 ls0 ws0">char* temp = (char*)malloc(i+1) ;</div><div class="t m0 x5 h3 yf ff2 fs0 fc0 sc0 ls0 ws0">memcpy(temp,arr,i);</div><div class="t m0 x5 h3 y10 ff2 fs0 fc0 sc0 ls0 ws0">temp[i] ='\0';</div><div class="t m0 x5 h3 y12 ff2 fs0 fc0 sc0 ls0 ws0">i=0;</div><div class="t m0 x5 h3 y13 ff2 fs0 fc0 sc0 ls0 ws0">/*<span class="ff1">&#22522;&#26412;&#24605;&#24819;&#21516;&#22788;&#29702;&#25968;&#23383;&#30340;</span>*/</div><div class="t m0 x2 h3 y15 ff2 fs0 fc0 sc0 ls0 ws0">if(FindOK(temp))//FindOK<span class="_ _0"> </span><span class="ff1">&#20989;&#25968;&#22312;&#20851;&#38190;&#23383;&#34920;&#20013;&#26597;&#25214;&#21644;<span class="_ _0"> </span></span>temp<span class="_ _0"> </span><span class="ff1">&#23383;&#31526;&#20018;&#30456;&#21516;&#30340;&#65292;<span class="_ _2"></span>&#25214;&#21040;&#23601;&#36820;&#22238;</span></div><div class="t m0 x2 h3 y27 ff1 fs0 fc0 sc0 ls0 ws0">&#31867;&#21035;&#32534;&#21495;</div><div class="t m0 x3 h3 y28 ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x5 h3 y18 ff2 fs0 fc0 sc0 ls0 ws0">fprintf(fpout,"%s\t\t%d \n",temp,FindOK(temp));</div><div class="t m0 x3 h3 y29 ff2 fs0 fc0 sc0 ls0 ws0">}</div><div class="t m0 x3 h3 y1a ff2 fs0 fc0 sc0 ls0 ws0">else</div><div class="t m0 x3 h3 y2a ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x5 h3 y1b ff2 fs0 fc0 sc0 ls0 ws0">fprintf(fpout,"%s\t\t%d\n",temp,1);//<span class="ff1">&#26631;&#31034;&#31526;&#21495;</span></div><div class="t m0 x3 h3 y1c ff2 fs0 fc0 sc0 ls0 ws0">}</div><div class="t m0 x3 h3 y1d ff2 fs0 fc0 sc0 ls0 ws0">free(temp);</div><div class="t m0 x3 h3 y1e ff2 fs0 fc0 sc0 ls0 ws0">}</div><div class="t m0 x3 h3 y20 ff2 fs0 fc0 sc0 ls0 ws0">//<span class="ff1">&#20197;&#19979;&#20026;<span class="_ _0"> </span></span>2<span class="_ _0"> </span><span class="ff1">&#23383;&#33410;&#30340;&#36816;&#31639;&#31526;&#21495;</span></div><div class="t m0 x3 h3 y2b ff2 fs0 fc0 sc0 ls0 ws0">else if( ch==':')//<span class="ff1">&#31526;&#21495;&#8220;&#65306;&#65309;&#8221;</span></div><div class="t m0 x3 h3 y21 ff2 fs0 fc0 sc0 ls0 ws0">{</div><div class="t m0 x5 h3 y22 ff2 fs0 fc0 sc0 ls0 ws0">fscanf(fpin,"%c",&amp;ch);</div><div class="t m0 x5 h3 y2c ff2 fs0 fc0 sc0 ls0 ws0">if(ch=='=') </div><div class="t m0 x6 h3 y23 ff2 fs0 fc0 sc0 ls0 ws0">fprintf(fpout,"%s\t\t%d\n",":=",20);</div></div></div><div class="pi" data-data='{"ctm":[1.611830,0.000000,0.000000,1.611830,0.000000,0.000000]}'></div></div>
100+评论
captcha
    类型标题大小时间
    ZIP汽车电子 DBC、ARXML、EXCEL 相互转换的工具27.6MB6月前
    ZIPMFC项目管控的主线程是UI线程,有的操作比较费时,我们可以通过工作线程去解决,并提供界面一个等待对话框,告知用户此刻程序没有卡92.91MB6月前
    ZIPPractical_5.zip2.47KB6月前
    ZIPpdf_20230153025.zip123.74KB6月前
    ZIPPython3安装好的文件75.24MB6月前
    ZIP基于Springboot的相亲网站系统6.36MB6月前
    ZIP杨卓衡受灾证明.zip6.12MB6月前
    ZIPDevCpp-v6.5.zip36.15MB6月前