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

<p>It has segments like </p>

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

<p>and</p>

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

<p>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?</p>

[{'answer_id': 74942, 'author': 'metadave', 'author_id': 7237, 'author_profile': 'https://Stackoverflow.com/users/7237', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.antlr.org" rel="nofollow noreferrer">Antlr</a> would do the trick.</p>\n'}, {'answer_id': 74944, 'author': 'INS', 'author_id': 13136, 'author_profile': 'https://Stackoverflow.com/users/13136', 'pm_score': 1, 'selected': False, 'text': '<p>You could try ANTLR or lex/yacc.</p>\n'}, {'answer_id': 74964, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 1, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 74970, 'author': 'nimish', 'author_id': 3926, 'author_profile': 'https://Stackoverflow.com/users/3926', 'pm_score': 3, 'selected': True, 'text': "<p>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.</p>\n"}, {'answer_id': 74971, 'author': 'Mostlyharmless', 'author_id': 12881, 'author_profile': 'https://Stackoverflow.com/users/12881', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 75018, 'author': 'chessguy', 'author_id': 1908025, 'author_profile': 'https://Stackoverflow.com/users/1908025', 'pm_score': 1, 'selected': False, 'text': '<p>There\'s a programming language called Haskell that has a great parsing library you might try. www.haskell.org and <a href="http://legacy.cs.uu.nl/daan/parsec.html" rel="nofollow noreferrer">http://legacy.cs.uu.nl/daan/parsec.html</a> for more details</p>\n'}, {'answer_id': 91500, 'author': 'tsee', 'author_id': 13164, 'author_profile': 'https://Stackoverflow.com/users/13164', 'pm_score': 2, 'selected': False, 'text': '<p>In case you\'re using Perl for parsing. The Perl equivalent of YACC would be <a href="http://search.cpan.org/dist/Parse-Yapp" rel="nofollow noreferrer">the Parse::Yapp</a> 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: <a href="http://search.cpan.org/dist/Parse-RecDescent" rel="nofollow noreferrer">Parse::RecDescent</a>.</p>\n'}]
['https://Stackoverflow.com/questions/74928', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2531/']