

This is just an experiment that has not yet been added to the 6809 static
binary translator (or any of the other translators).

The SBTs output a cut-down version of C.  There are still some optimisations
to be made which don't easily fall into the current framework, of "dumpf()"
and "peephole()".

Those would be better served by manipulating an Abstract Syntax Tree (AST)
similarly to how a compiler would manipulate a C program.

This code is a crude compiler - it handles only the subset of C syntax that is
output by the SBT.  In fact a few minor changes were made to the SBT to allow
the grammar that recognises the output to be simplified.

The code can now read all the output from 6809dasm, build it into an AST of sorts,
and re-output the same program.  Next step is to perform source-to-source
optimisations before outputing.  The sort of optimisations planned include
register remembering, constant expression folding, etc.  These are mostly
optimisations that the C compiler would do internally anyway, but doing them
here makes for a more readable translation, especially if the translated
code is then liable to be maintained as a C program.

Although usually I would use a table-driven parser generator, the language
being handled here is so simple that it was quicker to write an ad-hoc
top-down recursive descent parser.  So there may be a few small places
where the parsing code doesn't exactly match the grammar, because shortcuts
were taken opportunistically.
