gpt4 book ai didi

parsing - BNF 处理转义序列

转载 作者:行者123 更新时间:2023-12-02 16:14:55 27 4
gpt4 key购买 nike

我使用这个 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"

最佳答案

将 str 定义为:

str =  ( strset strescape ) *;

strescape = { \\ } {\" } ;

关于parsing - BNF 处理转义序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2970775/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com