您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 华南理工大学计算机全英班编译原理实验2
  所属分类: C/C++
  开发工具:
  文件大小: 1mb
  下载次数: 0
  上传时间: 2018-05-20
  提 供 者: z_y_r*****
 详细说明: Goals 1Complete a recursive–descent parser for TINY+. Parser gives syntax analysis to the tokens generated by the scanner. Output of the parser is an abstract syntax tree. 2Semantic analyzer builds the symbol table and check semantic errors. 3Intermediate code generator will translate any TINY+ program into three-address intermediate code. 4Syntax and semantic errors should be detected. a)Syntax errors: Start symbol and following symbol error Identifiers error, such as int is not followed by an identifier; Parenthesis matchi ng error, such as ( and ) do not match; Symbol error, such as in assignment the symbol should be ‘:=’, while in compare expressions the symbol should be ‘=’ b)Semantic errors: An identifier is used before the declarations of it and an identifier is declared more than once. The type of a condition expression is not bool The types of operands are not equal The types of the left and right hand side of assignment are not equal Requirement 1Write your program in C or C++ 2This experiment must be finished in 12 periods. You will submit a report and the source code Example output for some TINY+ programs Test1 int A,B,C,D; while AD do if A=1 then A:= B*C+37 else repeat A:=A*2 until A+C<=B+D end end The output should be Note: suppose stmt-sequence.next=L0, that is, the label attached to the first three-address instruction to be executed after the code for stmt-sequence(the root of the syntax tree) will always be L0 1)Label L1 2)if AD goto L2 6)goto L0 7)Label L2 8)if A=1 goto L4 9)goto L5 10)Label L4 11)t1:=B*C 12)t2:=t1+37 13)A:=t2 14)goto L1 15)Label L5 16)Label L6 17)t3:=A*2 18)A:=t3 19)t4:=A+C 20)t5:=B+D 21)if t4<=t5 goto L1 22)goto L6 23)Label L0 Test 2 int x,fact; read x; if x>0 and x<100 then {don’t compute if x<=0} fact:=1; while x>0 do fact:=fact*x; x:=x-1 end; write fact end The output should be 1) read x; 2) Label L1 3) if x>0 goto L3 4) goto L0 5) Label L3 6) if x<100 goto L2 7) goto L0 8) Label L2 9) fact:=1 10) Label L4 11) Label L6 12) if x>0 goto L7 13) goto L5 14) label L7 15) t1:=fact*x 16) fact:=t1 17) Label L8 18) t2:=x-1 19) x:=t2 20) goto L6 21)Label L5 22) write fact 23) Label L0 Appendix: Attribute grammar for code generation of control statements Seq->S ; Seq1 {S.next=newlabel; Seq1.next=Seq.next; Seq.code=S.code || Label S.next || Seq1.code} Seq->S {S.next=Seq.next; Seq.code=S.code} S->repeat Seq until E {S.begin =newlabel; Seq.next=newlabel; E.true=S.next; E.false=S.begin; S.code=Label S.begin || Seq.code || Label Seq.next || E.code} S->while E do Seq end {S.begin=newlabel Seq.next=S.begin E.true=newlabel E.false=S.next S.code=Label S.begin || E.code || Label E.true || Seq.code || goto S.begin } S->if E then Seq end {E.true=newlabel; E.false=S.next; Seq.next=S.next S.code=E.code || Label.E.ture || Seq.code} S->if E then Seq1 else Seq2 end {E.ture=newlabel; E.false=newlabel; Seq1.next=S.next; Seq2.next=S.next; S.code=E.code || Label E.true || Seq1.code || goto S.next || Label E.fasle || Seq2.code } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 输入关键字,在本站1000多万海量源码库中尽情搜索: