Parsing 处理转义序列的BNF
我使用此BNF解析我的脚本:Parsing 处理转义序列的BNF,parsing,escaping,grammar,bnf,Parsing,Escaping,Grammar,Bnf,我使用此BNF解析我的脚本: {identset} = {ASCII} - {"\{\}}; //<--all ascii charset except '\"' '{' and '}' {strset} = {ASCII} - {"}; ident = {identset}*; str = {strset}*; node ::= ident "{" nodes "}" | //<--entry point "\
{identset} = {ASCII} - {"\{\}}; //<--all ascii charset except '\"' '{' and '}'
{strset} = {ASCII} - {"};
ident = {identset}*;
str = {strset}*;
node ::= ident "{" nodes "}" | //<--entry point
"\"" str "\"" |
ident;
nodes ::= node nodes |
node;
我的问题是,如何处理字符串中的转义序列literal:
"some text of \"quotation\" should escape"
将str定义为:
str = ( strset strescape ) *;
与
str = ( strset strescape ) *;
strescape = { \\ } {\" } ;