The State Language Compiler (SLC) =================================== The SLC is a compiler for a language that does not exist, nor it's supposed to be used by anyone under any circunstances. But still, this is an interesting project. Interesting because, as the language is SO simple and stupid, that I have time to focus on code generation and optimizations. Nevertheless, the compiler must have a reasonable syntax to work with, and thus I'll try to summarize below, plus done and TODO lists. LICENSE ------- http://www.gnu.org/copyleft/lesser.html The license, as the website says, it LGPL. Not that I'm expecting commercial use of this code, but I might want to show it on internal talks, and the recent GPL licenses are becoming too restrictive to even allow that. FEATURES -------- The program compiles some of the syntax described here, enough to get some code generated and executed. You can print the result of every step: - tokenizer - parser - codegen - optimizer - execution TODO ---- * Add logic operators * Allow to print constant strings (maybe expressions) * Add PHI functions on IF blocks * allow to read from multiple files * generate machine code (Intel, ARM) SYNTAX ------ 1. Every expression must terminate with a semi-colon (;). - var foo = 10; # declares and instantiate foo - foo = bar + baz; # instantiate/uses foo - if foo == 10; # conditions - print foo; # output - goto bar; # state change - exit; # exits the program 2. Control flow keywords don't need semi-colon. - if/else/endif - state/end 3. There are only global variables. Declared/instantiated outside states, used only inside states. 4. No code, except variable declaration and instantiation, are allowed outside states. 5. The first state is the entry point. States without explicit goto or that don't reach a valid goto until its end are terminal (exists the program). 6. Expressions should accept addition/subtraction/division/multiplication operators and brackets for grouping. No precedence, operations done from left to right. 7. Conditions should accept: >, <, >=, <=, == and the logic operators && and || with brackets for grouping. 8. There are two types of output: variable only and string only. Strings should be enclosed by double quotes. No escaping allowed.