C++ Mathematical Expression Toolkit (ExprTk) release
Loading...
Searching...
No Matches
exprtk_pyramid.cpp
Go to the documentation of this file.
1/*
2 **************************************************************
3 * C++ Mathematical Expression Toolkit Library *
4 * *
5 * ExprTk Pyramid *
6 * Author: Arash Partow (1999-2024) *
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
26template <typename T>
27void pyramid()
28{
29 typedef exprtk::symbol_table<T> symbol_table_t;
30 typedef exprtk::expression<T> expression_t;
31 typedef exprtk::parser<T> parser_t;
32
34
35 symbol_table_t symbol_table;
36
37 symbol_table.add_package(io_package);
38
39 const std::string pyramid_program =
40 " const var n := 30; "
41 " "
42 " for (var i := 0; i < n; i += 1) "
43 " { "
44 " for (var j := 0; j < n - i - 1; j += 1) "
45 " { "
46 " print(' '); "
47 " }; "
48 " "
49 " for (var j := 0; j < 2 * i + 1; j += 1) "
50 " { "
51 " print('*'); "
52 " }; "
53 " "
54 " println(); "
55 " } ";
56
57 expression_t expression;
58 expression.register_symbol_table(symbol_table);
59
60 parser_t parser;
61 parser.compile(pyramid_program,expression);
62
63 expression.value();
64}
65
66int main()
67{
68 pyramid<double>();
69 return 0;
70}
void pyramid()
int main()