Question

I'm trying to figure out the best way to parse a GE Logician MEL trace file to make it easier to read.

It has segments like

>{!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" 

and

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

I could grovel through doing it procedurally, but after all the regexps I've worked with, I find it hard to believe there's nothing out there that will let me define the rules for parsing the file in a similar manner. Am I wrong?

Was it helpful?

Solution

Make a grammar using ANTLR. If you're using C, lex/yacc are native. ANTLR creates native parsers in Java, Python and .NET. Your output looks like a repl; try asking the vendor for a spec on the input language.

OTHER TIPS

Antlr would do the trick.

In case you're using Perl for parsing. The Perl equivalent of YACC would be the Parse::Yapp module. When I translated a yacc grammar for use with my Perl code, the translation was mostly mechanic. There's also a recursive descent parser generator, which is slow but powerful: Parse::RecDescent.

You could try ANTLR or lex/yacc.

If it were me, I would derive a context-free grammar and plug it into a parser generator, probably Scala's combinator library. However, this grammar looks reasonably easy to parse by hand, just bear in mind the automata theory and it shouldn't be a problem.

I would imagine you could use tools like LEX, FLEX, CUP, ANTLR or YACC (or their equivalents for whatever programming language you are using. Any mainstream programming language has some flavor of these available.) to parse the files if they have a specific structure [more accurately, if they could be represented by a grammar]. These might not work for finer points though.

There's a programming language called Haskell that has a great parsing library you might try. www.haskell.org and http://legacy.cs.uu.nl/daan/parsec.html for more details

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top