cfengine/core — pull request #882 by tzz (2013-08-16 10:35:22+00:00)
Title: Redmine#2111: eval() function for math evaluation

This implementation uses a PEG (parsing expression grammar). The `peg` tool used to compile `math.peg` into `math.pc` (a C file) is MIT licensed at http://piumarta.com/software/peg/ and is tiny, so it could be included in the distribution. I've included `math.pc` in a separate commit so you can test it, and added a rudimentary `Makefile.am` rule to generate it via `peg -o math.pc math.peg`.

Note that unlike `lex`, the expression parser here is reentrant and thread-safe. It works off a local context for every invocation, so there are no global variables. The trivial stack implementation resides in the local context as well.

I am not sure about the mechanics of incorporating the `peg` tool or `math.pc` into the Automake process properly.

The list of functions and operators is trivial to extend through `math.peg` and the grammar is (IMHO) much simpler to write and understand than the classic lex+yacc grammars, so I feel this is a good extensible solution.

Acceptance test included. I will add documentation if this pull request is accepted in some form.