4 ms·
Of course, the implemented language is simple enough, to accomodate this simple implementation. Still, looks nice, the code is very clear, and the comments are
by tomsmeding 9y ago
Of course, the implemented language is simple enough, to accomodate this simple implementation. Still, looks nice, the code is very clear, and the comments are pretty good.
The syntax is of course very limited with a one-line lexer, so more sophistocation here would somewhat expand the lexer, even though if it remains centered around regexes (which it probably will), it can remain pretty small.
When expanding the language, the tree building code can probably stay pretty small as well, if the syntax of your new constructs are chosen wisely. (I foresee control structures as prefix operators, which will be interesting to say the least.)
The evaluator and transpiler would complicate themselves significantly when adding control structures to the language: I think the most code-expanding task would be handling of not-directly evaluated code blocks. In the case of conditionals, you can probably get away with the ?: operator, also seeing as JS has the comma operator. But in the case of loops, you need a conpletely different structure in the output; it would depend on the implementation whether that stays small or not.
Of course, adding control structures is only useful if there's some way of defining names, be it variables (producing an imperative language) or recursion-capable functions (producing a functional language). It might be an interesting exercise to see how far you can push this language while still keeping the compiler under, say, 100 lines. :P
Protip if you do that: ditch the evaluator. A compiler doesn't need an interpreter to compile. ;)