注釈付きでマークされた文字列の解析 #6

注釈無しのマーク付けの記事からすると、今度は、構文解析器に一文字ずつ処理させる代わりに、
<string><marked-string-body><annotation>を一塊の文字列として字句解析系から受け取るように変更する流れだろう。
括弧とコロンを含まない文字列を表す終端記号を<string-except-special>
括弧を含まない文字列を表す終端記号を<string-except-parenthesis>とすると、

<text> ::= <string-headed> | <marked-string-headed>
<string-headed> ::= <string> | <string> <marked-string-headed>
<marked-string-headed> ::= <marked-string> | <marked-string> <marked-string-headed> | <marked-string> <string-headed>
<marked-string> ::= "(" <marked-string-body-with-annotation> ")"
<string> ::= <string-except-parenthesis>
<marked-string-body-with-annotation> ::= <marked-string-body> | <marked-string-body> ":" <annotation>
<marked-string-body> ::= <string-except-special>
<annotation> ::= <string-except-parenthesis>

さらに、単一生成規則を消去して、もう少しコンパクトにすると、

<text> ::= <string-headed> | <marked-string-headed>
<string-headed> ::= <string-except-parenthesis> | <string-except-parenthesis> <marked-string-headed>
<marked-string-headed> ::= <marked-string> | <marked-string> <marked-string-headed> | <marked-string> <string-headed>
<marked-string> ::= "(" <marked-string-body-with-annotation> ")"
<marked-string-body-with-annotation> ::= <string-except-special> | <string-except-special> ":" <string-except-parenthesis>

<string><annotation><string-except-parenthesis>に統合され、
<marked-string-body><string-except-special>として扱う。
これらの区別は注釈無しのマーク付けの時と同様に非終端記号への還元時のアクションで定義できるはずである。
文字から文字列を構成する生成規則を無くしたので#1の生成規則に比べて随分簡潔になった。