OpcUaCanOpen
CANopen OPC-UA server
exprtk_simple_example_12.cpp
Go to the documentation of this file.
1
/*
2
**************************************************************
3
* C++ Mathematical Expression Toolkit Library *
4
* *
5
* Simple Example 12 *
6
* Author: Arash Partow (1999-2019) *
7
* URL: http://www.partow.net/programming/exprtk/index.html *
8
* *
9
* Copyright notice: *
10
* Free use of the Mathematical Expression Toolkit Library is *
11
* permitted under the guidelines and in accordance with the *
12
* most current version of the MIT License. *
13
* http://www.opensource.org/licenses/MIT *
14
* *
15
**************************************************************
16
*/
17
18
19
#include <cstdio>
20
#include <string>
21
22
#include "
exprtk.hpp
"
23
24
25
template
<
typename
T>
26
void
bubble_sort
()
27
{
28
typedef
exprtk::symbol_table<T>
symbol_table_t
;
29
typedef
exprtk::expression<T>
expression_t
;
30
typedef
exprtk::parser<T>
parser_t
;
31
32
std::string
bubblesort_program =
33
" var upper_bound := v[]; "
34
" var swapped := false; "
35
" repeat "
36
" swapped := false; "
37
" for (var i := 0; i < upper_bound; i += 1) "
38
" { "
39
" for (var j := i + 1; j < upper_bound; j += 1) "
40
" { "
41
" if (v[i] > v[j]) "
42
" { "
43
" v[i] <=> v[j]; "
44
" swapped := true; "
45
" }; "
46
" }; "
47
" }; "
48
" upper_bound -= 1; "
49
" until (not(swapped) or (upper_bound == 0)); "
;
50
51
T v[] = { T(9.9), T(2.2), T(1.1), T(5.5), T(7.7), T(4.4), T(3.3) };
52
53
symbol_table_t
symbol_table;
54
symbol_table.
add_vector
(
"v"
,v);
55
56
expression_t
expression;
57
expression.
register_symbol_table
(symbol_table);
58
59
parser_t
parser
;
60
parser
.compile(bubblesort_program,expression);
61
62
expression.value();
63
}
64
65
int
main
()
66
{
67
bubble_sort<double>();
68
return
0;
69
}
exprtk
exprtk_simple_example_12.cpp
Generated on Fri Sep 11 2020 14:30:05 for OpcUaCanOpen by
1.8.14