简体   繁体   中英

BNF to handle escape sequence

I use this BNF to parser my script:

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

It can parse correctly the following text into tree structure

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"
    }
}

my question is, how do I handle escape sequence inside string literal:

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

Define str as:

str =  ( strset strescape ) *;

with

strescape = { \\ } {\" } ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM