Wednesday, 31 March 2010

Live Maths Code Generation

/ LiveMaths / LiveMathsTwo / LiveMathsSyntax

Purpose

The parser must emit OpenOfficeBasic source code. This code has to include not only the translated expressions but also any necessary variable declarations and functions.

Can we use yacc/bison to generate the code? Even if we generate C and hand translate to OpenOfficeBasic it might be better than generating the parser and code generator by hand.

Even if we cannot generate useful code with yacc we might be able to verify the grammar with it or some other program.

The problem with all of the parser generators is that the code they generate is fixed by the tool and of course none of them generate OpenOfficeBasic.

So, the thing to do is write our own. After al the code we want to generate is OpenOfficeBasic so we can leave a lot to the OpenOfficeBasic interpreter. We can base our parser on both the grammar and code from Jack W. Crenshaw's Let's Build a Compiler tutorial.

Crenshaw's tutorial uses Turbo Pascal as the implementation language and 68k assembler as the target with a Basic-like source language. TP is sufficently similar to OpenOfficeBasic to make translation quite straightforward for most things and many things can be omitted because we can make the target run time system take care of things like variables.

So we'll follow the general plan of the tutorial and build up the translator a bit at a time. See the OpenOffice documents for details.

Posted via web from kwhitefoot's posterous

No comments:

Post a Comment

Blog Archive

Followers