zoukankan      html  css  js  c++  java
  • 语法树,短语,直接短语,句柄

    1.已知文法:

    S->a|^|(T)

    T->T,S|S

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

    语法书为:

    由语法树可知全部短语:(T,(^,a))       T,(^,a)        (^,a)        ^,a        ^          a

    直接短语:^      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是否有两棵不同的语法树?说明了什么?

     

  • 相关阅读:
    Python练习题 016:猴子吃桃
    Date() 及其 如何验证用户输入的日期是合法的
    关于事件触发的一个小tips
    KVO监听导航栏
    使用CoreText动态下载更换字体
    UICollectionView 的使用
    echarts散点图搭配时间轴
    使用百度echarts画图表的步骤
    canvas画图中drawImage使用
    html5canvas简单画图
  • 原文地址:https://www.cnblogs.com/Qiomo/p/11583315.html
Copyright © 2011-2022 走看看