gpt4 book ai didi

string - JFlex 词法分析器。多行字符串

转载 作者:行者123 更新时间:2023-12-03 17:19:57 25 4
gpt4 key购买 nike

我正在尝试使用 JFlex 解析一些带有多行字符串文字的语言。

例子:

'''
this is a valid multiline string literal with 'quoted' word
'''

我创建了两个状态:
%x IN_QUOTED_STRING
%x IN_MULTILINE_QUOTED_STRING

并创建了几个宏和规则:
QUOTED_STRING_TAIL=[^\']* "'"
QUOTED_STRING_START="@"? "'"
MULTILINE_QUOTED_STRING_START = "@"? "'''"
MULTILINE_QUOTED_STRING_TAIL = [.]* "'''"

%%

<YYINITIAL> {MULTILINE_QUOTED_STRING_START} {yybegin(IN_MULTILINE_QUOTED_STRING);}
<YYINITIAL> {QUOTED_STRING_START} {yybegin(IN_QUOTED_STRING);}

<IN_QUOTED_STRING> {QUOTED_STRING_TAIL} {yybegin(YYINITIAL); return STRING;}
<IN_MULTILINE_QUOTED_STRING> {MULTILINE_QUOTED_STRING_TAIL} {yybegin(YYINITIAL); return STRING;}

但它不起作用。我收到“错误:无法匹配输入”

任何人都可以帮助我解决问题吗?

最佳答案

OP写道:

works for me:

QUOTED_LITERAL="'" ([^\\\'\r\n] | {ESCAPE_SEQUENCE} | (\[\r\n]))* ("'"|\)?
ESCAPE_SEQUENCE=\[^\r\n]
ANY_ESCAPE_SEQUENCE = \[^]
THREE_QUO = (\"\"\")
ONE_TWO_QUO = (\"[^\"]) | (\"\[^]) | (\"\"[^\"]) | (\"\"\[^])
QUO_STRING_CHAR = [^\\\"] | {ANY_ESCAPE_SEQUENCE} | {ONE_TWO_QUO}
TRIPLE_QUOTED_LITERAL = {THREE_QUO} {QUO_STRING_CHAR}* {THREE_QUO}?
%%
<YYINITIAL> {TRIPLE_QUOTED_LITERAL }{ return STRING; }
<YYINITIAL> {QUOTED_LITERAL} { return STRING; }

关于string - JFlex 词法分析器。多行字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562776/

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