4

この BNF を使用してスクリプトを解析します。

{identset} = {ASCII} - {"\{\}};     //<--all ascii charset except '\"' '{' and '}'
{strset}   = {ASCII} - {"};
ident      = {identset}*;
str        = {strset}*;
node     ::= ident "{" nodes "}" |  //<--entry point
             "\"" str "\"" | 
             ident;
nodes    ::= node nodes |
             node;

次のテキストをツリー構造に正しく解析できます

doc {
    title { "some title goes here" }
    refcode { "SDS-1" }
    rev { "1.0" }
    revdate { "04062010" }
    body {  
        "this is the body of the document
         all text should go here"
        chapter { "some inline section" }
        "text again"
    }
}

私の質問は、文字列リテラル内のエスケープ シーケンスをどのように処理するかです。

"some text of \"quotation\" should escape"
4

1 に答える 1

1

strを次のように定義します。

str =  ( strset strescape ) *;

strescape = { \\ } {\" } ;
于 2010-06-04T12:40:16.240 に答える