tags:

views:

300

answers:

7

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?

+1  A: 

Antlr would do the trick.

metadave
+1  A: 

You could try ANTLR or lex/yacc.

Iulian Şerbănoiu
+1  A: 

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.

Daniel Spiewak
+4  A: 

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.

nt
Thanks, I hadn't run into Antlr before. I had heard of lex and yacc, but I didn't know if there was something better to be using.
SarekOfVulcan
+1  A: 

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.

Mostlyharmless
+1  A: 

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

chessguy
+2  A: 

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.

tsee