Compiler for the CAPPUS processor
TODO: Implement proper preprocessing step with macro substitution etc.
In the first compilation step, CPL code is loaded using a "source" class.
The source class loads a file that is passed as a file object (as obtained e.g. via open()), and maintains a pointer pointing to a certain character in the file.
The advantage of using a Source object, as opposed to reading bytes from the file immediately, is that it preprocesses the file, i. e. skipping comments. This makes it very easy to use with further processing steps such as lexers.
The source class interface is as follows:
- Initialization:
A source object can be initialised as follows:Source(file: <File object>)
The initialisation will automatically fetch necessary data from the file. - Getting characters:
Theget()method returns the next character in the file, i. e. the character that is pointed to by the class's internal pointer, which is incremented by this method. If the next character is the first character of a comment, the comment is skipped, the first character after the comment is returned, and pointers are adjusted accordingly. - Peeking characters:
Thepeek(depth=1)method behaves similarly to theget()method, the most notable difference being thatget()also increments the object's internal pointer. Additionally, thepeek()method offers for use with the keyword argument depth, which will obtain a character at position internalPointer+depth in the file. depth defaults to 1. - Obtaining file position / stamp:
Theget_pos()method returns a string in the format:<filename> <line>:<column>, which is useful for debugging and producing helpful errors.
Is very baller.
makes ast idk
forgor to implement front and middle end 💀