我正在尝试找出解析 GE Logician MEL 跟踪文件的最佳方法,以使其更易于阅读。

它有像这样的段

>{!gDYNAMIC_3205_1215032915_810 = (clYN)}
execute>GDYNAMIC_3205_1215032915_810 = "Yes, No"
results>"Yes, No" 
execute>end 
results>"Yes, No" 

>{!gDYNAMIC_3205_1215032893_294 = (clYN)}
execute>GDYNAMIC_3205_1215032893_294 = "Yes, No"
results>"Yes, No" 
execute>end 
results>"Yes, No" 

>{IF (STR(F3205_1220646638_285, F3205_1220646638_301) == "") THEN "" ELSE (\par\tab fnHeadingFormat("Depression") + CFMT(F3205_1220646638_285, "", "Have you often been bothered by feeling down, depressed or hopeless? ", "B", "\par ") + CFMT(F3205_1220646638_301, "", "Have you often been bothered by little interest or pleasure in doing things? ", "B", "\par ") ) ENDIF}
execute>call STR("No", "No")
results>"NoNo" 
execute>"NoNo" == ""
results>FALSE 
execute>if FALSE
results>FALSE 
execute>call FNHEADINGFORMAT("Depression")
execute>call CFMT("Depression", "B,2")
results>"\fs24\b Depression\b0\fs20 " 
execute>"\r\n" + "\fs24\b Depression\b0\fs20 "
results>"\r\n\fs24\b Depression\b0\fs20 " 
execute>"\r\n\fs24\b Depression\b0\fs20 " + "\r\n"
results>"\r\n\fs24\b Depression\b0\fs20 \r\n" 
results>return "\r\n\fs24\b Depression\b0\fs20 \r\n" 
execute>call CFMT("No", "", "Have you often been bothered by feeling down, depressed or hopeless? ", "B", "\par ")
results>"\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par " 
execute>"\r\n\fs24\b Depression\b0\fs20 \r\n" + "\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par "
results>"\r\n\fs24\b Depression\b0\fs20 \r\n\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par " 
execute>call CFMT("No", "", "Have you often been bothered by little interest or pleasure in doing things? ", "B", "\par ")
results>"\b Have you often been bothered by little interest or pleasure in doing things? \b0 No\par " 
execute>"\r\n\fs24\b Depression\b0\fs20 \r\n\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par " + "\b Have you often been bothered by little interest or pleasure in doing things? \b0 No\par "
results>"\r\n\fs24\b Depression\b0\fs20 \r\n\b Have you often been bothered by feeling down, depressed or hopeless? \b0 No\par \b Have you often been bothered by little interest or pleasure in doing things? \b0 No\par " 

我可能会在程序上卑躬屈膝,但在我使用过所有正则表达式之后,我发现很难相信没有什么可以让我定义以类似方式解析文件的规则。我错了吗?

有帮助吗?

解决方案

使用 ANTLR 创建语法。如果您使用 C,则 lex/yacc 是原生的。ANTLR 使用 Java、Python 和 .NET 创建本机解析器。你的输出看起来像一个repl;尝试向供应商询问输入语言的规范。

其他提示

安特尔 就可以了。

如果您使用 Perl 进行解析。YACC 的 Perl 等价物是 解析::亚普 模块。当我翻译 yacc 语法以与我的 Perl 代码一起使用时,翻译大部分是机械式的。还有一个递归下降解析器生成器,它很慢但功能强大: 解析::RecDescent.

您可以尝试 ANTLR 或 lex/yacc。

如果是我,我会导出一个上下文无关语法并将其插入解析器生成器,可能是 Scala 的组合器库。然而,这个语法看起来相当容易手工解析,只要记住自动机理论,它应该不是问题。

我想您可以使用 LEX、FLEX、CUP、ANTLR 或 YACC 等工具(或者您使用的任何编程语言的等效工具)。任何主流编程语言都有一些可用的功能。)来解析文件(如果它们具有特定的结构)[更准确地说,如果它们可以用语法表示]。但这些可能不适用于更精细的点。

有一种名为 Haskell 的编程语言,它有一个很棒的解析库,您可以尝试一下。www.haskell.org 和 http://legacy.cs.uu.nl/daan/parsec.html 更多细节

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top