マーク付けに使う文字の変更 #1

マークの開始、注釈の開始、マークの終了の意味をそれぞれ"("":"")"に持たせてきた。
これらの特別な意味をもった文字(メタ文字)の割り当てを解析時に動的に変更したい。
この変更は実行時に与えるコマンドラインオプションで行うことにする。

問題はどのように実装するかである。
今までの感じでは、注釈付きでマークされた文字列の解析での#13のような、
lex/flexだけで作った字句解析器がソースが書きやすく、また、シンプルで読みやすいと思う。
しかし、固定パターンから字句解析器を作ることで高速な処理を実現するlex/flexにおいて、
パターンを動的に変えるという処理を書くのは結構面倒な気がする。

とりあえず、構文規則中のリテラル文字を普通の終端記号で定義して、
字句解析器は動的なメタ文字割り当てに従ってそれを返せるようにする。
上述のように、このような字句解析器を作るのにlex/flexでは面倒な気がするので手書きでやってみる。

構文規則は、

<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> ::= <start-mark> <marked-string-body-with-annotation> <end-mark>
<marked-string-body-with-annotation> ::= <string-except-special> | <string-except-special> <start-annotation> <string-except-parenthesis>
<string-except-parenthesis> ::= <string-except-special> | <start-annotation> | <string-except-parenthesis> <string-except-special> | <string-except-parenthesis> <start-annotation>

のように、リテラル文字"("":"")"
それぞれ<start-mark><start-annotation><end-mark>に言い換えただけである。
文字列中のメタ文字の扱いでは前回示した拡張は行わない。あれはちょっとやり過ぎの感が。