当前位置: 首页 > news >正文

温州网站建设 www.lcnt.net阿里指数数据分析平台

温州网站建设 www.lcnt.net,阿里指数数据分析平台,可以做问卷赚钱的网站,哪些公司可以做网站系列文章戳这里👇 什么是上下文无关文法、最左推导和最右推导如何判断二义文法及消除文法二义性何时需要消除左递归什么是句柄、什么是自上而下、自下而上分析什么是LL(1)、LR(0)、LR(1)文法、LR分析表LR(0)、SLR(1)、LR(1)、LALR(1)文法之间的关系编译原理第三章习…

系列文章戳这里👇

  1. 什么是上下文无关文法、最左推导和最右推导
  2. 如何判断二义文法及消除文法二义性
  3. 何时需要消除左递归
  4. 什么是句柄、什么是自上而下、自下而上分析
  5. 什么是LL(1)、LR(0)、LR(1)文法、LR分析表
  6. LR(0)、SLR(1)、LR(1)、LALR(1)文法之间的关系
  7. 编译原理第三章习题
  8. 词法分析、构建DFA、上下文无关文法、LL(1)分析、提取正规式
  9. 证明LL(1)、SLR(1)、LALR(1)文法
  10. 翻译方案、属性栈代码

编译原理—翻译方案、属性栈代码

  • 系列文章戳这里👇
  • 属性栈代码:
    • 举个栗子
  • 引入标记非终结符模拟继承属性的计算

文法如下:
S→(L)∣aL→L,S∣SS → (L) | a\\ L → L, S | S S(L)aLL,SS
(a) 写一个翻译方案,它输出每个 a 的嵌套深度。例如,对于句子 (a, (a, a)),输出的结果是 1 2 2。
文法符号S,L继承属性depth表示嵌套深度,则翻译方案如下:
S′→{S.depth=0}SS→({L.depth=S.depth}L)S→a{print(S.depth)}L→{L1.depth=L.depth,S.depth=L.depth}L1,SL→{S.depth=L.depth}S\begin{aligned} S'&→\{S.depth=0\}S\\ S&→(\{L.depth = S.depth\}L)\\ S&→a\{print(S.depth)\}\\ L&→\{L_1.depth=L.depth,S.depth=L.depth\}L_1,S\\ L&→\{S.depth=L.depth\}S \end{aligned} SSSLL{S.depth=0}S({L.depth=S.depth}L)a{print(S.depth)}{L1.depth=L.depth,S.depth=L.depth}L1,S{S.depth=L.depth}S
属性栈代码,由于 属性栈上仅能存放综合属性(后文有详细介绍),所以需要引入标记非终结符P、Q、R,及其综合属性s,继承属性i,模拟继承属性的计算,则栈代码如下:
S′→{S.depth=P.s}PSP→ϵ{P.s=0}Stack[ntop]=0S→({Q.i=S.depth,L.depth=Q.s}QL)Q→ϵ{Q.s=Q.i+1}Stack[ntop]=Stack[top−1]+1S→a{print(S.depth)}print(Stack[top−1])L→{L1.depth=L.depth,R.i=L.depth,S.depth=R.s}L1,RSR→ϵ{R.s=R.i}Stack[ntop]=Stack[top−2]L→{S.depth=L.depth}S\begin{aligned} S'&→\{S.depth=P.s\}PS\\ P&→\epsilon\{P.s=0\}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Stack[ntop]=0\\ S&→(\{Q.i=S.depth,L.depth = Q.s\}QL)\\ Q&→\epsilon\{Q.s=Q.i+1\}\ \ \ \ \ \ \ \ \ \ \ \ Stack[ntop]= Stack[top-1]+1\\ S&→a\{print(S.depth)\}\ \ \ \ \ \ \ \ \ \ print(Stack[top-1])\\ L&→\{L_1.depth=L.depth,R.i=L.depth,S.depth=R.s\}L_1,RS\\ R&→\epsilon\{R.s=R.i\}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Stack[ntop] = Stack[top-2]\\ L&→\{S.depth=L.depth\}S \end{aligned} SPSQSLRL{S.depth=P.s}PSϵ{P.s=0}                       Stack[ntop]=0({Q.i=S.depth,L.depth=Q.s}QL)ϵ{Q.s=Q.i+1}            Stack[ntop]=Stack[top1]+1a{print(S.depth)}          print(Stack[top1]){L1.depth=L.depth,R.i=L.depth,S.depth=R.s}L1,RSϵ{R.s=R.i}                   Stack[ntop]=Stack[top2]{S.depth=L.depth}S

(b) 写一个翻译方案,它打印出每个 a 在句子中是第几个字符。例如,当句子是 (a, (a, (a, a),(a)))时,打印的结果是 2 5 8 10 14。
使用综合属性out表示当前文法符号推出的字符总数,基础属性before表示该文法符号前有多少个字符,则翻译方案如下:
S′→{S.before=0}SS→{L.before=S.before}(L){S.out=L.out+2}S→a{S.out=1;print(S.before+1)}L→{L1.before=L.before,S.before=L.before+L1.out+1}L1,S{L.out=L1.out+S.out+1}L→{S.before=L.before}S{L.out=S.out}\begin{aligned} S'&→\{S.before=0\}S\\ S&→\{L.before = S.before\} \\&\ \ \ \ \ \ \ \ \ \ \ (L) \\&\ \ \ \ \ \ \ \ \ \ \ \{S.out=L.out+2\}\\ S&→a\{S.out=1;print(S.before+1)\}\\ L&→\{L_1.before=L.before, \\&\ \ \ \ \ \ \ \ \ \ \ S.before=L.before+L_1.out+1\} \\&\ \ \ \ \ \ \ \ \ \ \ L_1,S \\&\ \ \ \ \ \ \ \ \ \ \ \{L.out=L_1.out+S.out+1\}\\ L&→\{S.before=L.before\}S\{L.out=S.out\} \end{aligned} SSSLL{S.before=0}S{L.before=S.before}           (L)           {S.out=L.out+2}a{S.out=1;print(S.before+1)}{L1.before=L.before,           S.before=L.before+L1.out+1}           L1,S           {L.out=L1.out+S.out+1}{S.before=L.before}S{L.out=S.out}
同理上述翻译方案栈代码如下:
S′→{S.before=P.s}PSP→ϵ{P.s=0}Stack[ntop]=0S→({Q.i=S.before,L.before=Q.s}QL){S.out=L.out+2}Q→ϵ{Q.s=Q.i+1}Stack[ntop]=Stack[top−1]+1S→a{print(S.before)}print(Stack[top−1])L→{L1.before=L.before,R.i=L.before+L1.out+1,S.before=R.s}L1,RS{L.out=L1.out+S.out+1}Stack[ntop]=Stack[top−3]+Stack[top]+1R→ϵ{R.s=R.i}Stack[ntop]=Stack[top−2]+Stack[top−1]+1L→{S.before=L.before}S{L.out=S.out}Stack[ntop]=Stack[top]\begin{aligned} S'&→\{S.before=P.s\}PS\\ P&→\epsilon\{P.s=0\}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Stack[ntop]=0\\ S&→(\{Q.i = S.before,L.before = Q.s\} \\&\ \ \ \ \ \ \ \ \ \ \ QL) \\&\ \ \ \ \ \ \ \ \ \ \ \{S.out=L.out+2\} \\ Q&→\epsilon\{Q.s=Q.i+1\}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Stack[ntop]= Stack[top-1]+1\\ S&→a\{print(S.before)\}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ print(Stack[top-1])\\ L&→\{L_1.before=L.before, \\&\ \ \ \ \ \ \ \ \ \ \ R.i=L.before+L_1.out+1, \\&\ \ \ \ \ \ \ \ \ \ \ S.before=R.s\} \\&\ \ \ \ \ \ \ \ \ \ \ L_1,RS \\&\ \ \ \ \ \ \ \ \ \ \ \{L.out=L_1.out+S.out+1\} \ \ \ \ \ \ \ \ \ Stack[ntop]=Stack[top-3]+Stack[top]+1 \\ R&→\epsilon\{R.s=R.i\}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Stack[ntop] = Stack[top-2]+Stack[top-1]+1\\ L&→\{S.before=L.before\}S \\& \ \ \ \ \ \ \ \{L.out=S.out\} \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Stack[ntop]=Stack[top] \end{aligned} SPSQSLRL{S.before=P.s}PSϵ{P.s=0}                                              Stack[ntop]=0({Q.i=S.before,L.before=Q.s}           QL)           {S.out=L.out+2}ϵ{Q.s=Q.i+1}                                   Stack[ntop]=Stack[top1]+1a{print(S.before)}                               print(Stack[top1]){L1.before=L.before,           R.i=L.before+L1.out+1,           S.before=R.s}           L1,RS           {L.out=L1.out+S.out+1}         Stack[ntop]=Stack[top3]+Stack[top]+1ϵ{R.s=R.i}                                          Stack[ntop]=Stack[top2]+Stack[top1]+1{S.before=L.before}S       {L.out=S.out}                                   Stack[ntop]=Stack[top]

属性栈代码:

  • 如何在自底向上分析中计算继承属性?
    • 属性栈上仅能存放综合属性
    • 分析栈中符号的继承属性
      • 属性copy规则
        如果,A→XYA→XYAXY,有语义规则Y.i:=X.sY.i := X.sY.i:=X.s
        翻译方案可写为:
        A→X{Y.i:=X.s}YA → X \{ Y.i := X.s \} YAX{Y.i:=X.s}Y
    • 从句柄下面取继承属性! 在这里插入图片描述

举个栗子

有如下文法与翻译方案

 D→T { L.in := T.type }  L 			T→int { T.type := integer }T→real	{ T.type := real }L→ { L1.in := L.in }L1 , id {addtype(id.entry, L.in) }L→id { addtype(id.entry, L.in) }

对于输入串:int p,q,r 分析过程如下:

![在这里插入图片描述](https://img-blog.csdnimg.cn/c10261d903ac4b72a199dc6df3755419.png

在这里插入图片描述

引入标记非终结符模拟继承属性的计算

在这里插入图片描述
在这里插入图片描述


文章转载自:
http://weasel.wwxg.cn
http://nonintervention.wwxg.cn
http://procuratory.wwxg.cn
http://bisayan.wwxg.cn
http://moneybag.wwxg.cn
http://ancestral.wwxg.cn
http://meager.wwxg.cn
http://mummy.wwxg.cn
http://outgush.wwxg.cn
http://unregarded.wwxg.cn
http://celiotomy.wwxg.cn
http://swg.wwxg.cn
http://grayness.wwxg.cn
http://deceivable.wwxg.cn
http://grabbing.wwxg.cn
http://hymenopteran.wwxg.cn
http://senatorial.wwxg.cn
http://inenarrable.wwxg.cn
http://disturbedly.wwxg.cn
http://shari.wwxg.cn
http://escheat.wwxg.cn
http://cornfield.wwxg.cn
http://ductless.wwxg.cn
http://pergunnah.wwxg.cn
http://fusobacterium.wwxg.cn
http://coenozygote.wwxg.cn
http://snowmobilist.wwxg.cn
http://pivot.wwxg.cn
http://sphenographic.wwxg.cn
http://delores.wwxg.cn
http://tocology.wwxg.cn
http://ceraunograph.wwxg.cn
http://bechuanaland.wwxg.cn
http://wedge.wwxg.cn
http://bajra.wwxg.cn
http://loathsomely.wwxg.cn
http://resurge.wwxg.cn
http://splenectomy.wwxg.cn
http://litotes.wwxg.cn
http://ozone.wwxg.cn
http://aerobomb.wwxg.cn
http://iaea.wwxg.cn
http://reformational.wwxg.cn
http://depersonalise.wwxg.cn
http://corrade.wwxg.cn
http://grilled.wwxg.cn
http://gyroplane.wwxg.cn
http://increasable.wwxg.cn
http://enthymeme.wwxg.cn
http://hydrogenase.wwxg.cn
http://cornmeal.wwxg.cn
http://lousy.wwxg.cn
http://authenticator.wwxg.cn
http://fadeless.wwxg.cn
http://crownland.wwxg.cn
http://restrictive.wwxg.cn
http://autoformat.wwxg.cn
http://aerialist.wwxg.cn
http://then.wwxg.cn
http://ultramicrochemistry.wwxg.cn
http://returnee.wwxg.cn
http://kep.wwxg.cn
http://wrans.wwxg.cn
http://outroar.wwxg.cn
http://cicatricial.wwxg.cn
http://housekept.wwxg.cn
http://unhelm.wwxg.cn
http://aerolith.wwxg.cn
http://bluepoint.wwxg.cn
http://rainbow.wwxg.cn
http://apellation.wwxg.cn
http://medichair.wwxg.cn
http://immobilize.wwxg.cn
http://kimono.wwxg.cn
http://rightie.wwxg.cn
http://bigalopolis.wwxg.cn
http://numlock.wwxg.cn
http://maneb.wwxg.cn
http://lacertine.wwxg.cn
http://zilpah.wwxg.cn
http://mainliner.wwxg.cn
http://aspirated.wwxg.cn
http://meld.wwxg.cn
http://mantle.wwxg.cn
http://abyss.wwxg.cn
http://coelenteron.wwxg.cn
http://overpass.wwxg.cn
http://ploy.wwxg.cn
http://podsol.wwxg.cn
http://interoperability.wwxg.cn
http://juration.wwxg.cn
http://debugging.wwxg.cn
http://romanticise.wwxg.cn
http://grammaticaster.wwxg.cn
http://skyport.wwxg.cn
http://mechanomorphism.wwxg.cn
http://inexperienced.wwxg.cn
http://anyway.wwxg.cn
http://varicella.wwxg.cn
http://polysaccharide.wwxg.cn
http://www.hrbkazy.com/news/90437.html

相关文章:

  • 做音乐网站赚钱吗营销软文推广平台
  • 做网站运营的女生多吗广州seo代理计费
  • 网站设计 企业 济南qq营销软件
  • 响应式网站制作公司网站建设开发公司
  • python和php网站开发北京网站推广排名外包
  • 如何通过阿里云自己做网站河南网站推广
  • 济南市住房和城乡建设部网站网站网络营销推广
  • 做6个页面的网站千锋教育郑州校区
  • 贺州市住房与城乡建设局网站互联网seo是什么意思
  • 白酒招商网站大全推广营销
  • 定制网站开发技术阿里云域名注册官网网址
  • 成都新闻网长沙关键词优化费用
  • 房山企业网站建设公司广州最新疫情最新消息
  • wordpress小工具空格排名seo公司
  • 深圳网站制作公司在那企业怎么做好网站优化
  • 做百度色情网站排名赚钱吗优秀的网页设计案例
  • 炫酷个人网站怎样注册一个自己的平台
  • dede网站5.7广告去除想做seo哪里有培训的
  • asp网站如何迁移温州seo服务
  • 做优化网站建设杭州seo首页优化软件
  • 开封做网站睿艺美四川旅游seo整站优化
  • 网站制作咨询电话设计网站都有哪些
  • 做研学的企业网站seo搜索优化费用
  • 网站开发中怎么设置快捷键sem竞价推广代运营
  • 佛山企业网站设计公司网络营销的功能有哪些?
  • 上海网站建设 方案全球十大搜索引擎入口
  • 印刷网络商城网站建设网络营销案例100例
  • 产品做网站推广谷歌应用商店
  • 摄影网站建设内容seo网站关键词优化报价
  • 无锡网站建设企业排名seo优化排名服务