So I've been working with the Boost Spirit Compiler tutorial. Currently, it works great with integers. I am working on a way to extend it to handle strings. Here is the link to the source code.
http://www.boost.org/doc/libs/1_57_0/libs/spirit/example/qi/compiler_tutorial/mini_c/
For those familiar with Boost, the following should look familiar - it is a production rule for a primary expression:
primary_expr =
uint_
| function_call
| identifier
| bool_
| '(' > expr > ')'
;
uint_ is what allows a primary_expr to be assigned an int. Normally, we could add some simple functionality for a char or a string by either creating a few more production rules, or else a simple text parser using a regex that identifies quotes or something like that. There are tons of examples if you back up the root of the link I sent.
The real problem comes with the fact that to implement the compiler, the code pushes bytecode operations into a vector. It's trivial to push a single char here, since all chars have an accompanying ASCII code that it will be implicitly converted to, but not the case for an array of chars, since they would lose their context in the process as part of a larger string (that forms a sentence, eg).
The best option I can come up with is to change the
vector<int>
to
vector<uintptr_t>
From my understanding, this type of pointer can point to both integers and chars. Though, it's not simply a matter of changing the 'uint_' to 'uintptr_t' within the above production rule. The compiler tells me that it's an illegal use in this particular instance.
By the way, you will see the implementation of our vector holding the bytecode within the compiler.cpp/.hpp files.
Any help would be appreciated, and if you need any more information, please ask. Thanks.