1 #include <Teuchos_MathExpr.hpp> 9 Teuchos::Language::Productions& prods = out.
productions;
11 prods[PROD_EXPR](
"expr") >>
"ternary";
12 prods[PROD_TERNARY_DECAY](
"ternary") >>
"add_sub";
13 prods[PROD_OR_DECAY](
"or") >>
"and";
14 prods[PROD_AND_DECAY](
"and") >>
"comp";
15 prods[PROD_ADD_SUB_DECAY](
"add_sub") >>
"mul_div";
16 prods[PROD_MUL_DIV_DECAY](
"mul_div") >>
"pow";
17 prods[PROD_POW_DECAY](
"pow") >>
"neg";
18 prods[PROD_NEG_DECAY](
"neg") >>
"scalar";
19 prods[PROD_TERNARY](
"ternary")
20 >>
"or",
"?",
"S?",
"add_sub",
":",
"S?",
"add_sub";
21 prods[PROD_OR](
"or") >>
"or",
"||",
"S?",
"and";
22 prods[PROD_AND](
"and") >>
"and",
"&&",
"S?",
"comp";
23 prods[PROD_GT](
"comp") >>
"add_sub",
">",
"S?",
"add_sub";
24 prods[PROD_LT](
"comp") >>
"add_sub",
"<",
"S?",
"add_sub";
25 prods[PROD_GEQ](
"comp") >>
"add_sub",
">=",
"S?",
"add_sub";
26 prods[PROD_LEQ](
"comp") >>
"add_sub",
"<=",
"S?",
"add_sub";
27 prods[PROD_EQ](
"comp") >>
"add_sub",
"==",
"S?",
"add_sub";
28 prods[PROD_BOOL_PARENS](
"comp") >>
"(",
"S?",
"or",
")",
"S?";
29 prods[PROD_ADD](
"add_sub") >>
"add_sub",
"+",
"S?",
"mul_div";
30 prods[PROD_SUB](
"add_sub") >>
"add_sub",
"-",
"S?",
"mul_div";
31 prods[PROD_MUL](
"mul_div") >>
"mul_div",
"*",
"S?",
"pow";
32 prods[PROD_DIV](
"mul_div") >>
"mul_div",
"/",
"S?",
"pow";
33 prods[PROD_POW](
"pow") >>
"pow",
"^",
"S?",
"neg";
34 prods[PROD_CALL](
"scalar")
35 >>
"name",
"S?",
"(",
"S?",
"args?",
")",
"S?";
36 prods[PROD_NO_ARGS](
"args?");
37 prods[PROD_SOME_ARGS](
"args?") >>
"args";
38 prods[PROD_FIRST_ARG](
"args") >>
"ternary";
39 prods[PROD_NEXT_ARG](
"args") >>
"args",
",",
"S?",
"ternary";
40 prods[PROD_NEG](
"neg") >>
"-",
"S?",
"neg";
41 prods[PROD_VAL_PARENS](
"scalar") >>
"(",
"S?",
"ternary",
")",
"S?";
42 prods[PROD_CONST](
"scalar") >>
"constant",
"S?";
43 prods[PROD_VAR](
"scalar") >>
"name",
"S?";
44 prods[PROD_NO_SPACES](
"S?");
45 prods[PROD_SPACES](
"S?") >>
"spaces";
47 out.
tokens[TOK_SPACE](
"spaces",
"[ \t\n\r]+");
48 out.
tokens[TOK_NAME](
"name",
"[_a-zA-Z][_a-zA-Z0-9]*");
49 out.
tokens[TOK_ADD](
"+",
"\\+");
50 out.
tokens[TOK_SUB](
"-",
"\\-");
51 out.
tokens[TOK_MUL](
"*",
"\\*");
52 out.
tokens[TOK_DIV](
"/",
"\\/");
53 out.
tokens[TOK_POW](
"^",
"\\^");
54 out.
tokens[TOK_LPAREN](
"(",
"\\(");
55 out.
tokens[TOK_RPAREN](
")",
"\\)");
56 out.
tokens[TOK_COMMA](
",",
",");
57 out.
tokens[TOK_CHECK](
"?",
"\\?");
58 out.
tokens[TOK_CHOOSE](
":",
":");
59 out.
tokens[TOK_GT](
">",
">");
60 out.
tokens[TOK_LT](
"<",
"<");
61 out.
tokens[TOK_GEQ](
">=",
">=");
62 out.
tokens[TOK_LEQ](
"<=",
"<=");
63 out.
tokens[TOK_EQ](
"==",
"==");
64 out.
tokens[TOK_AND](
"&&",
"&&");
65 out.
tokens[TOK_OR](
"||",
"\\|\\|");
66 out.
tokens[TOK_CONST](
"constant",
67 "(0|([1-9][0-9]*))(\\.[0-9]*)?([eE]\\-?[1-9][0-9]*)?");
73 if (ptr.strong_count() == 0) {
74 ptr.reset(
new Language(make_language()));
88 SymbolSetReader::SymbolSetReader():
89 Reader(ask_reader_tables())
93 SymbolSetReader::~SymbolSetReader()
97 void SymbolSetReader::at_shift(any& result,
int token, std::string& text) {
98 if (token == TOK_NAME) result = text;
101 void SymbolSetReader::at_reduce(any& result,
int prod, std::vector<any>& rhs) {
102 if (prod == PROD_VAR) {
103 std::string& name = any_ref_cast<std::string>(rhs.at(0));
104 variable_names.insert(name);
105 }
else if (prod == PROD_CALL) {
106 std::string& name = any_ref_cast<std::string>(rhs.at(0));
107 function_names.insert(name);
111 std::set<std::string> get_variables_used(std::string
const& expr) {
112 SymbolSetReader reader;
114 reader.read_string(result, expr,
"get_variables_used");
115 return reader.variable_names;
int strong_count() const
Return the number of active RCP<> objects that have a "strong" reference to the underlying reference-...
Productions productions
vector of productions
The main class for users to define a language using TeuchosParser.
ReaderTablesPtr make_reader_tables(Language const &language)
constructs ReaderTables for the given Language.
Tokens tokens
vector of tokens
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
RCP< const Language > LanguagePtr
an RCP to a const Language