Lexical Analyzer for Pascal for the C3
Mike Green
Posts: 23,101
I thought I would post this maybe as a source of code fragments for those that are interested. I put together a lexical analyzer for an extended Pascal compiler. It accepts input from a PS/2 keyboard and displays information on a TV display (using Cluso99's 1-pin drivers), keeps its working tables in the C3's SRAM, and writes its output (lexical tokens and symbol table) to C3 flash files. There's a C3 version of Kye's FATEngine, but it's not really used at this point. Eventually it will be used for the input file and any output files.
In this program, there are several symbol table lookup routines, one that uses a pre-defined table and one that uses a symbol table in SRAM. There's a numeric input routine that accepts hex constants ($00000000), binary constants (%00000000), and decimal constants including floating point. The analyzer accepts Pascal comments and C type line comments (using //). The analyzer uses a two character backup scheme so it can move ahead two characters in the input stream, but back up through one or both of them if it doesn't know what to do with what it finds.
I may polish this up in a couple of weeks and probably work on a parser later this summer. I have no idea whether I'll take this further than that, but here it is.
In this program, there are several symbol table lookup routines, one that uses a pre-defined table and one that uses a symbol table in SRAM. There's a numeric input routine that accepts hex constants ($00000000), binary constants (%00000000), and decimal constants including floating point. The analyzer accepts Pascal comments and C type line comments (using //). The analyzer uses a two character backup scheme so it can move ahead two characters in the input stream, but back up through one or both of them if it doesn't know what to do with what it finds.
I may polish this up in a couple of weeks and probably work on a parser later this summer. I have no idea whether I'll take this further than that, but here it is.
zip
95K
Comments
Interesting. For those who want self-hosting, perhaps 'Turbo Pascal' on the Prop may yet arrive ?
Esitmates on how large it would be after adding an Editor and Compiler/debug ?
Any such work should 'common subset' with a widespread PC language, so that PC tools can be use too, for algorithm framework and testing,
and I'd do more than one language - what you have sounds like it would split easily.
We're not talking here about an IDE. Any text editor would be separate. I'd probably just start with the one that's part of Sphinx.
The language we're talking about here is an extended Pascal with some string manipulation and ways to explicitly escape the strong typing of Pascal. The concepts and extensions I plan are based on Palm Pascal, a self-hosted 68xxx and ARM compiler for the PalmOS, now redone for Android.