cgv
Loading...
Searching...
No Matches
expression_processor.h
1#pragma once
2
3#include <utility>
4#include <vector>
5#include <stack>
6#include "variant.h"
7#include "operators.h"
8#include <cgv/utils/token.h>
9
10#include "lib_begin.h"
11
12namespace cgv {
13 namespace ppp {
14
15 class ph_processor;
16
17 enum ExpressionPart { EP_VALUE, EP_OPERATOR, EP_OPEN, EP_FUNC, EP_CLOSE, EP_LIST_OPEN, EP_LIST_CLOSE, EP_LIST_ACCESS, EP_COMMA };
18
20 {
21 variant value;
22 OperatorType ot;
23 ExpressionPart ep;
24 expression_token(const token& tok, const variant& v) : token(tok), value(v), ep(EP_VALUE) {}
25 expression_token(const token& tok, OperatorType _ot) : token(tok), ot(_ot), ep(EP_OPERATOR) {}
26 expression_token(const token& tok, ExpressionPart _ep) : token(tok), ep(_ep) {}
27 };
28
30 {
32
33 protected:
34 bool debug_parse;
35 bool debug_evaluate;
36 typedef std::pair<unsigned int, unsigned int> expr_stack_entry;
37
38 void prepare();
39
40 bool compress_stack_validate(int priority, std::vector<expr_stack_entry>& expression_stack,
41 std::vector<ExpressionPart>& parenthesis_stack,
42 std::stack<variant>& value_stack, std::stack<OperatorType>& operator_stack);
43
44 bool compress_stack_evaluate(int priority, std::vector<expr_stack_entry>& expression_stack,
45 std::vector<ExpressionPart>& parenthesis_stack,
46 std::stack<variant>& value_stack, std::stack<OperatorType>& operator_stack);
47
48 std::vector<expression_token> expression_tokens;
49
50 unsigned int get_nr_comma_separated_expressions(std::vector<expr_stack_entry>& expression_stack,
51 std::vector<ExpressionPart>& parenthesis_stack,
52 std::stack<variant>& value_stack) const;
53
54 ExpressionPart find_last_parenthesis(std::vector<expr_stack_entry>& expression_stack,
55 std::vector<ExpressionPart>& parenthesis_stack) const;
56
57 mutable std::string last_error;
58 mutable token last_error_token;
59 public:
60 bool found_error;
61 bool issued_error;
62
64
65 bool parse(const token& input_token);
66
67 void extract_begins(std::vector<unsigned>& begins, unsigned i0 = 0, unsigned ie = -1) const;
68 bool assign_func_decl(const std::vector<variant>& values) const;
69 bool is_func_decl() const;
70 int classify_call(unsigned i) const;
71
72 bool validate(bool allow_several_values = false);
73 bool evaluate(variant& result, ph_processor* ph_proc);
74
75 const std::string& get_last_error() const;
76 const token& get_last_error_token() const;
77 };
78 }
79}
80#include <cgv/config/lib_end.h>
the pre header processor parses a pre header file and converts it to a header file or uses the inform...
the cgv namespace
Definition print.h:11
representation of a token in a text by two pointers begin and end, that point to the first character ...
Definition token.h:18
token()
construct with both pointers set to 0
Definition token.cxx:8