---> 以下の文法を考えてみましょう:
S->SaS|bB
B->AcB| ε
A->dAd| ε
上記の文法について、解析中の文字列を出力する構文指向の定義を記述し、文字列 'bddcab' の注釈付き解析ツリーを構築します。
解決:
上記の文法を書き直すと、次のようになります。
S->S1aS2
S->bB
B->AcB1
B-> ε
A->dA1d
A-> ε
( The numbers 1 and 2 following the non-terminal actually denote subscripts. And the subscripts in above grammar denote instances of the non-terminal.)
上記の文法と意味規則。
Productions Semantic Rules
S->S1aS2 S.val=S1.val+a.lexval + S2.val { print S.val }
S->bB S.val=b.lexval + B.val { Print S.val}
B->AcB1 B.val=A.val+c.lexval + B1.val
B-> ε
A->dA1d A.val=d.lexval + A1.val + d.lexval
A-> ε
** The '+' operator is merely for concatenation.
この解決策は大丈夫ですか?正確ではないかもしれないと感じています。
これが注釈付きの解析ツリーです。