3 ms·
I didn't really intend to make the interpreter part complex. It's more like a proof of concept that the tree can be easily traversed and evaluated. Besides, any
by bluetomcat 11y ago
I didn't really intend to make the interpreter part complex. It's more like a proof of concept that the tree can be easily traversed and evaluated. Besides, anyone who intends to use more than 128 variables in this language has either chosen the wrong language, or has to extend it at least with functions :-)
The parts that I wanted to make robust and recoverable from all kinds of errors were the lexer and the parser.
- DougMerritt 11y agoWell add an array anyway, to make my above hypothetical project easier. :)
- bluetomcat 11y agoSuggestion considered :-)
- bluetomcat 11y agoI just added array support: https://github.com/bbu/simple-interpreter/commit/392c38e78996a8fc3bda588342d04711166acce7 https://github.com/bbu/simple-interpreter/commit/392c38e7899... The arrays themselves are dynamically realloc'ed and checked for out of bounds access. I've also added some runtime warnings for access to undefined variables and negative or out of bounds array access. Also, there is an equivalence between variables and arrays: `var[0]` is the same as `var`. All in 1466 lines :-)
- DougMerritt 11y agoExcellent, that's all good stuff. And yes, that's pretty concise. My toy interpreters tend to grow without bounds.