C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html

This commit is contained in:
Arash Partow
2014-05-28 07:10:40 +10:00
parent baa1feb6d2
commit 02d2402ca5
6 changed files with 3054 additions and 1304 deletions

View File

@ -28,25 +28,23 @@ void bubble_sort()
typedef exprtk::expression<T> expression_t;
typedef exprtk::parser<T> parser_t;
std::string expr_string =
" upper_bound := v[]; "
" repeat "
" swapped := false; "
" for(i := 0; i < upper_bound; i += 1) "
" { "
" for(j := i + 1; j < upper_bound; j += 1) "
" { "
" if (v[i] > v[j]) "
" { "
" temp := v[i]; "
" v[i] := v[j]; "
" v[j] := temp; "
" swapped := true; "
" }; "
" }; "
" }; "
" upper_bound -= 1; "
" until (not(swapped) or (upper_bound == 0)); ";
std::string bubblesort_program =
" upper_bound := v[]; "
" repeat "
" swapped := false; "
" for(i := 0; i < upper_bound; i += 1) "
" { "
" for(j := i + 1; j < upper_bound; j += 1) "
" { "
" if (v[i] > v[j]) "
" { "
" v[i] <=> v[j]; "
" swapped := true; "
" }; "
" }; "
" }; "
" upper_bound -= 1; "
" until (not(swapped) or (upper_bound == 0)); ";
T v[] = { T(2.2), T(1.1), T(5.5), T(4.4), T(3.3) };
@ -59,7 +57,7 @@ void bubble_sort()
parser_t parser;
parser.enable_unknown_symbol_resolver();
parser.compile(expr_string,expression);
parser.compile(bubblesort_program,expression);
expression.value();
}