资源描述:
《编译原理实验报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、编译原理实验报告姓名:***班级:***学号:***指导老师:***otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeA
2、fterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand实验一编译程序的分析与验证一、实验目的:熟练掌握LR分析
3、表以及编译原理的基本过程,学会分析编译程序。二、实验要求:理论联系实际,将所学知识用到实处。上机实验,验证老师给的代码的正确性,进而学会怎么写编译程序。三、实验内容:验证自己的文法的正确性,识别文法中的单词、句子、关键字、变量,等等。验证下述程序输出结果的正确性:while(a>b)dobeginifm>=nthena:=a+1elsewhilek=hdox:=x+2;m:=n+x*(m+y)end#~四、程序部分代码:#include"stdio.h"#include"string.h"#defi
4、neACC-2/**************************************/#definesy_if0#definesy_then1#definesy_else2#definesy_while3#definesy_begin4#definesy_do5#definesy_end6#definea7#definesemicolon8#definee9#definejinghao10#defineS11#defineL12#definetempsy15#defineEA18#defin
5、eE019#defineplus34#definesub35#definetimes36otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJingdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecial
6、CommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommitteeSecretaryandrecorderoftheCountypartyCommitteeSecretary,Ministersand#definediv37#defin
7、ebecomes38#defineop_and39#defineop_or40#defineop_not41#definerop42#definelparent48#definerparent49#defineident56#defineintconst57/********************算术表达式的LR分析表********************/staticintaction1[14][9]={{-1,-1,-1,-1,2,-1,3,-1,1},{4,5,6,7,-1,-1,-1,A
8、CC,-1},{-1,-1,-1,-1,2,-1,3,-1,8},{106,106,106,106,-1,106,-1,106,-1},{-1,-1,-1,-1,2,-1,3,-1,9},{-1,-1,-1,-1,2,-1,3,-1,10},{-1,-1,-1,-1,2,-1,3,-1,11},{-1,-1,-1,-1,2,-1,3,-1,12},{4,5,6,7,-1,13,-1,-1,-1},{101,101,101,101,-1,101,-1,101,-1},{