My wife always says, “It’s the journey, not the destination.” Well, I started out wanting to generate a parser for modelica and ended up writing a parser-generator and several parsers. Now I’m working on translators. My parser-generator is called nyacc. The example parsers I’m working are for C99, modelica, matlab, and javascript. The parsers output the parse tree in SXML and I’m using foldts*-values from (sxml fold) to do the translation. Here is an illustration of the progress I’m making on javascript, from source code to output from guile. — Matt
var x; x = Math.sqrt(26.01); x += 1; x ==(parser)==> (SourceElements (VariableStatement (VariableDeclarationList (VariableDeclaration (Identifier "x")))) (EmptyStatement) (AssignmentExpression (PrimaryExpression (Identifier "x")) (assign) (CallExpression (obj-ref (PrimaryExpression (Identifier "Math")) (Identifier "sqrt")) (ArgumentList (PrimaryExpression (NumericLiteral "26.01"))))) (EmptyStatement) (AssignmentExpression (PrimaryExpression (Identifier "x")) (add-assign) (PrimaryExpression (NumericLiteral "1"))) (EmptyStatement) (PrimaryExpression (Identifier "x"))) ==(foldts*-values)==> (begin (define x (@@ (jslib) undefined)) (set! (toplevel x) (apply (apply (@@ (jslib) lkup) (@@ (jslib) Math) (const "sqrt")) (const 26.01))) (set! (toplevel x) (apply (@@ (jslib) JS+) (toplevel x) (const 1))) (toplevel x)) ==(compile)==> 6.1000000000000005