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 回答