I've recently noticed that even in systems programming, fast but lightweight
expression evaluation is much more useful than a full-blown scripting language.
As I mentioned before in this thread, for microcontrollers I typically only need access to variables in RAM, occasionally functions; in systems programming, also string manipulation and even regular expressions (which in POSIXy systems are included in the base standard C library and thus do not "cost" anything extra; see
man 3 regex and
POSIX basic regular expression syntax).
In all cases I tend to have a
context object (in C, a structure that often contains a hash table of "variables" and another of "functions" and "operators" the expression can access), often shared across a few expressions, but also with more than one context in a single application.
The nicest interface for this is in Python-Python –– I mean, when evaluating Python expressions in Python, but not when using Python as an embedded language –– since its built-in
eval() function takes a global and a local dictionary (perfect for
context) where even other built-ins can be overridden to limit the language facilities. In JavaScript, one can create a
Function object using the expression, but either all context variable names are listed as function parameters, or the expression uses e.g.
this base object (so all references are of form
this.variable_or_function) –– this is because it uses an array instead of a dictionary to represent function arguments ––; workable, but not perfect.
(Okay, another wall of text. Get to the point already!
)
Thus, I'd love a modular lightweight scripting language suited for microcontrollers that one could easily strip down to (or pick only the) expression evaluation and C function call machinery. I notice several of you have already written small interpreters for embedded use (at 32-bit Cortex-M scale we already have several options noted in this thread), but paying more attention to this type of modularity and minimalism might be warranted. I particularly like the division between global and local states, with both states as separate objects/structures supplied to the evaluator, along with the string or token stream representing the expression.