c++ - How to parse DSL input to high performance expression template -


(edited both title , main text , created spin-off question arose)

for our application ideal parse simple dsl of logical expressions. way i'd parse (at runtime) input text gives expressions lazily evaluated structure (an expression template) can later used within more performance sensitive code.

ideally evaluation fast possible using technique used large number of times different values substituting placeholders each time. i'm not expecting expression template equivalent in performance hardcoded function models same function given input text string i.e. there no need go down route of compiling say, c++, in situ of running program (i believe other questions cover dynamic library compiling/loading).

my own thoughts reading examples boost can use boost::spirit parsing of input text , i'm confident can develop grammar need. however, i'm not sure how can combine parser boost::proto build executable expression template. examples of spirit i've seen merely interpreters or end building kind of syntax tree go no further. examples of proto i've seen assume dsl embedded in host source code , not need interpreted string. i'm aware boost::spirit implemented boost::proto not sure if relevant problem or whether fact suggest convenient solution.

to re-iterate, need able make real following:

const std::string input_text("a && b || c"); // const std::string input_text(get_dsl_string_from_file("expression1.dsl"));  expression expr(input_text);  while(keep_intensively_processing) {     ...     context context(…);     // e.g. context.a = false; context.b=false; context.c=true;      bool result(evaluate(expr, context));     ... } 

i appreciate minimal example or small kernel can build upon creates expression input text evaluated later in context.

i don't think same question posted here: parsing boolean expressions boost spirit i'm not convinced quickest executing way of doing this, though looks clever. in time i'll try benchmark of answers posted.


Comments