C++ Mathematical Expression Toolkit (ExprTk)
release
Toggle main menu visibility
Loading...
Searching...
No Matches
exprtk
exprtk_extract_dependents.cpp
Go to the documentation of this file.
1
/*
2
**************************************************************
3
* C++ Mathematical Expression Toolkit Library *
4
* *
5
* ExprTk Extract Expression Dependents *
6
* Author: Arash Partow (1999-2025) *
7
* URL: https://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
* https://www.opensource.org/licenses/MIT *
14
* SPDX-License-Identifier: MIT *
15
* *
16
**************************************************************
17
*/
18
19
20
#include <cstdio>
21
#include <string>
22
23
#include "
exprtk.hpp
"
24
25
26
template
<
typename
T>
27
void
extract_expression_dependents
()
28
{
29
const
std::string expression =
"a * sin(3x) + foo(abs(y - z) / w)"
;
30
31
exprtk::symbol_table<T>
symbol_table;
32
33
/*
34
Note: Add any functions that are not part of the standard set
35
of ExprTk functions
36
*/
37
symbol_table.
add_function
(
"foo"
,[](T
/*t*/
)->T {
return
T(0); });
38
39
std::deque<std::string> variable_list;
40
std::deque<std::string> function_list;
41
42
if
(!
exprtk::collect_variables
(expression, symbol_table, variable_list))
43
{
44
printf(
"Error: Failed to collect variables for expression: %s\n"
,expression.c_str());
45
variable_list.clear();
46
}
47
48
if
(!
exprtk::collect_functions
(expression, symbol_table, function_list))
49
{
50
printf(
"Error: Failed to collect functions for expression: %s\n"
,expression.c_str());
51
function_list.clear();
52
}
53
54
for
(
const
auto
& var : variable_list)
55
{
56
printf(
"variable: %s\n"
,var.c_str());
57
}
58
59
for
(
const
auto
& func : function_list)
60
{
61
printf(
"function: %s\n"
,func.c_str());
62
}
63
}
64
65
int
main
()
66
{
67
extract_expression_dependents<double>
();
68
return
0;
69
}
70
71
72
/*
73
74
Build:
75
c++ -pedantic-errors -Wall -Wextra -Werror -o exprtk_extract_dependents exprtk_extract_dependents.cpp -L/usr/lib -lstdc++ -lm
76
77
*/
exprtk::symbol_table
Definition
exprtk.hpp:20090
exprtk::symbol_table::add_function
bool add_function(const std::string &function_name, function_t &function)
Definition
exprtk.hpp:21156
exprtk.hpp
extract_expression_dependents
void extract_expression_dependents()
Definition
exprtk_extract_dependents.cpp:27
main
int main()
Definition
exprtk_extract_dependents.cpp:65
exprtk::collect_variables
bool collect_variables(const std::string &expression, Sequence< std::string, Allocator > &symbol_list)
Definition
exprtk.hpp:42365
exprtk::collect_functions
bool collect_functions(const std::string &expression, Sequence< std::string, Allocator > &symbol_list)
Definition
exprtk.hpp:42426
Generated by
1.17.0