終端記号(しゅうたんきごう、英: Terminal symbol)と非終端記号(ひしゅうたんきごう、英: Nonterminal symbol)は、句構造規則の生成規則中にあらわれる記号類の分類である。規則群のうちの、どれかの規則の左辺にあらわれている記号、すなわち、他の記号列と置換できるものとして定義されている記号が非終端記号で、ある種の変数名のようなものとも言える。それに対し、右辺の記号列中のみにあらわれる、いわゆる「アルファベット」の1文字から成る記号が終端記号である。実用上は(プログラミング言語などでは)終端記号は文字そのものではなく、英語などにおける「単語」に相当する「トークン」と呼ばれるもの(「字句」の記事、および字句解析#トークンなどを参照)であることも多い。 終端記号は、生成規則の右辺のみに現れ、左辺には現れない。よって、生成規則によってそれ以上は変換されない(これが“終端”と呼ばれる理由である)。 非終端記号とは、置換されうる記号のことであり、構文変数 と呼ばれることもある。 以下、単に「集合」とあるものは全て有限集合である。この理論では文法は一般に、記号列を別の記号列に置換できるものとして定義する生成規則の集合によって定義される。これらの生成規則は、文字列の生成やパースに使われる。それぞれの生成規則は、置換される記号列からなる ヘッド (左辺)と、置換する記号列からなる ボディ (右辺)を持つ。規則は、ヘッド → ボディ のような形に書く。例えば、規則 z0 → z1 は、z0 を z1 で置き換えることを表す。 1950年代に ノーム・チョムスキー [1][2] によって提案された生成文法の古典的な形式では、文法 G は次のように構成される: 以上からなる4つ組 < N , Σ , P , s > {\displaystyle <N,\Sigma ,P,s>} として、言語が形式的に定義される。[3][4]
終端記号
非終端記号
句構造文法詳細は「句構造文法」を参照
非終端記号 の集合 N {\displaystyle N}
終端記号(アルファベット) の集合 Σ {\displaystyle \Sigma }
生成規則 の集合 P {\displaystyle P} 。 P {\displaystyle P} の要素であるそれぞれの規則は次のような形をしている:
( Σ ∪ N ) ∗ n ( Σ ∪ N ) ∗ → ( Σ ∪ N ) ∗ {\displaystyle (\Sigma \cup N)^{*}n(\Sigma \cup N)^{*}\rightarrow (\Sigma \cup N)^{*}} ここで n ∈ N {\displaystyle n\in N} ここで ∗ {\displaystyle {}^{*}} は クリーネのスター(つまり、0個以上の並びを意味する)、 ∪ {\displaystyle \cup } は和集合を表し、よって ( Σ ∪ N ) ∗ {\displaystyle (\Sigma \cup N)^{*}} は0個以上の記号の並びを表す。つまり、左辺は少なくとも1つの非終端記号を含む。右辺が空列の場合は、誤解を避けるために Λ {\displaystyle \Lambda } , e {\displaystyle e} , ϵ {\displaystyle \epsilon } のような記号を使うことがある。
開始記号 s ∈ N {\displaystyle s\in N}
参考文献
Aho, Sethi, & Ullman, Compilers: Principles, Techniques, and Tools, Addison-Wesley, 1986.
^ Chomsky, Noam (1956). “Three Models for the Description of Language”. IRE Transactions on Information Theory
^ Chomsky, Noam (1957). Syntactic Structures. The Hague: Mouton
この項目は、コンピュータに関連した書きかけの項目です。この項目を加筆・訂正などしてくださる協力者を求めています(PJ:コンピュータ/P:コンピュータ)。
.mw-parser-output .hlist ul,.mw-parser-output .hlist ol{padding-left:0}.mw-parser-output .hlist li,.mw-parser-output .hlist dd,.mw-parser-output .hlist dt{margin-right:0;display:inline-block;white-space:nowrap}.mw-parser-output .hlist dt:after,.mw-parser-output .hlist dd:after,.mw-parser-output .hlist li:after{white-space:normal}.mw-parser-output .hlist li:after,.mw-parser-output .hlist dd:after{content:" ・\a0 ";font-weight:bold}.mw-parser-output .hlist dt:after{content:": "}.mw-parser-output .hlist-pipe dd:after,.mw-parser-output .hlist-pipe li:after{content:" |\a0 ";font-weight:normal}.mw-parser-output .hlist-hyphen dd:after,.mw-parser-output .hlist-hyphen li:after{content:" -\a0 ";font-weight:normal}.mw-parser-output .hlist-comma dd:after,.mw-parser-output .hlist-comma li:after{content:"、";font-weight:normal}.mw-parser-output .hlist-slash dd:after,.mw-parser-output .hlist-slash li:after{content:" /\a0 ";font-weight:normal}.mw-parser-output .hlist dd:last-child:after,.mw-parser-output .hlist dt:last-child:after,.mw-parser-output .hlist li:last-child:after{content:none}.mw-parser-output .hlist dd dd:first-child:before,.mw-parser-output .hlist dd dt:first-child:before,.mw-parser-output .hlist dd li:first-child:before,.mw-parser-output .hlist dt dd:first-child:before,.mw-parser-output .hlist dt dt:first-child:before,.mw-parser-output .hlist dt li:first-child:before,.mw-parser-output .hlist li dd:first-child:before,.mw-parser-output .hlist li dt:first-child:before,.mw-parser-output .hlist li li:first-child:before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child:after,.mw-parser-output .hlist dd dt:last-child:after,.mw-parser-output .hlist dd li:last-child:after,.mw-parser-output .hlist dt dd:last-child:after,.mw-parser-output .hlist dt dt:last-child:after,.mw-parser-output .hlist dt li:last-child:after,.mw-parser-output .hlist li dd:last-child:after,.mw-parser-output .hlist li dt:last-child:after,.mw-parser-output .hlist li li:last-child:after{content:")\a0 ";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li:before{content:" "counter(listitem)" ";white-space:nowrap}.mw-parser-output .hlist dd ol>li:first-child:before,.mw-parser-output .hlist dt ol>li:first-child:before,.mw-parser-output .hlist li ol>li:first-child:before{content:" ("counter(listitem)" "}.mw-parser-output .navbar{display:inline;font-size:75%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}.mw-parser-output .infobox .navbar{font-size:88%}.mw-parser-output .navbox .navbar{display:block;font-size:88%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}
表示
編集