语法树,短语,直接短语,句柄2.0

1.已知文法:

S->a|^|(T)

T->T,S|S

分析句型(T,(^,a)),求全部的短语、直接短语和句柄。

存在如下的语法树:

 

存在的短语如下: 

 

 

 

 

 

 直接短语如下:

句柄如下:

2.构造上下文无关文法,描述语言:

anbn|n>=0} ①

{ambn|m>=n>=0} ②

{(ab)n|n>=0} ③

{ambn|m,n>=1} ④

①:S->aSb|ε

        if n>0 then S->aa...S...bb

        if n=0 then S->ε

        else other

②:S->BA|ε

       A->anbn

       B->am

      if m>n>0 then S->aaaa...S...bbb    (a的个数大于b的个数)

      if n=0 then S->ε

      else other

③: S->abS|ε

        if n>0 then S->abababab...S

        if n=0 else  S->ε

        else other 

④: S->aSb|ab

        if m=n>1 then S->aaa...S...bbb   (a的个数等于b的个数)

        if m>n>1 then S->aaaa...S...bbb   (a的个数大于b的个数)

        if n>m>1 then S->aaa...S...bbbb   (a的个数小于b的个数)

        if n=m=1 then S->ab

        else other

 

3.如果if语句的方法:

stmt->if expr then stmt

     | if expr then stmt else stmt

     | other

句子if E1 then if E2 then S1 else S2是否有两棵不同的语法树?说明了什么?

 

 

转载于:https://www.cnblogs.com/ccw1124486193/p/11582822.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值