To find my C legs again I decided to program a small interpreter for a BASIC type language in C, as the first programming language I ever learned (after Scratch) was BASIC.
Realising the largest challenge was the expression parser I started there. I use a custom tokenising/parsing module to tokenise expressions, then use Edsger Dijkstra's "shunting yard algorithm" to convert the tokens to an intermediate form of RPN, then use a simple RPN solver to evaluate the expression.
At the moment MBasic is just a REPL environment, although I am currently working on control flow statements for a more structured language.
"MBasic" supplies the usual operators, +, -, *, /, ^, % (for integer and floats), and all of those operators as compound assignment operators too (+=, -=...).
As you can see from the examples to the right, the three "primitive" data types are integer, floating point, and string. General promotion rules apply, where 10 / 3 is 3 (integer division), but 10 / 3.0 causes the 10 to be promoted to a float, causing the expression to evaluate to 3.33333 (although only printed out to five d.p. the internal storage of floats is C "float").
As my normal language of choice is C++ obviously I am a practicioner of RAII and object oriented programming- and I tried to replicate this in my C code, where almost every
I used Visual Studio's _CRTDBG memory leak detector and as far as I'm aware the program has no direct memory leakage- which I would guess is due to the strict create/destroy pattern, which mimics constructors/destructors, see llist_create (and llist_destroy which is off the page). I made heavy use of my existing libraries LList and DArray.