To find my C legs again I decided to program a small interpreter/calculator for a BASIC type language in C, as the first programming language I ever learned (after Scratch) was BASIC. Although of course C isn't really the best language for this sort of thing I thought it might be fun for a challenge.
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").
I think RAII is an excellent design principle combined with object oriented programming. I tried to replicate C++ style RAII in my C code, where almost every function/method is prepended with the "class" name (e.g. "expression_evaluate_expression") and with the first parameter a pointer to a struct/object of that class, and "objects" are created using class_create() and then destroyed using class_destroy(object* obj).
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 attribute to the strict create/destroy pattern, which mimics constructors/destructors (see llist_create and llist_destroy). I made heavy use of my existing libraries LList and DArray.