-
Notifications
You must be signed in to change notification settings - Fork 0
/
SvdCExpressionParser.h
148 lines (125 loc) · 4.75 KB
/
SvdCExpressionParser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright (c) 2010-2021 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef SvdCExpressionParser_H
#define SvdCExpressionParser_H
#include <string>
#include <map>
#include <list>
class SvdCExpressionParser {
public:
SvdCExpressionParser(const std::string& exprStr);
~SvdCExpressionParser();
bool Parse();
/*
* Expression - Node types
*/
typedef enum xeType {
xme_const = 256, // some constant
xme_strcon, // string "xxxx"
xme_namcon, // identifier
xme_labcon, // some label, not used in XM
xme_ref, // some reference
xme_reff, // bit-field-reference - not used in XM
xme_cast, // some type cast
xme_postinc, // expr++ postfix
xme_postdec, // expr-- postfix
xme_preinc, // ++expr prefix
xme_predec, // --expr prefix
xme_addr, // & (address_of) - not used in XM
xme_cont, // * (content_of) - not used in XM
xme_plus, // unary +
xme_minus, // unary -
xme_not, // ! (not)
xme_compl, // ~ (complement)
xme_asn, // = (assignment
xme_asnor, // |=
xme_asnxor, // ^=
xme_asnand, // &=
xme_asnlsh, // <<=
xme_asnrsh, // >>=
xme_asnadd, // +=
xme_asnsub, // -=
xme_asnmul, // *=
xme_asndiv, // /=
xme_asnmod, // %=
xme_hook, // e0 ? e1 : e2
xme_land, // &&
xme_lor, // ||
xme_and, // & (bit-and)
xme_or, // | (bit-or)
xme_xor, // ^ (bit-xor)
xme_equ, // ==
xme_nequ, // !=
xme_lequ, // <=
xme_gequ, // >=
xme_gt, // >
xme_lt, // <
xme_lsh, // <<
xme_rsh, // >>
xme_add, // +
xme_sub, // -
xme_mod, // %
xme_div, // /
xme_mul, // *
xme_param, // actual parameter
xme_void, // void-node
xme_fcall, // direct function call
xme_what, // unknown token
xme_eoi, // end of input
xme_identi, // some identifer
xme_quest, // ?
xme_colon, // :
xme_pp, // ++ token
xme_mm, // -- token
xme_star, // * token
xme_openbr, // ( token
xme_closebr, // ) token
xme_opendim, // [ token
xme_closedim, // ] token
xme_openbl, // { token
xme_closebl, // } token
xme_comma, // expr, expr
xme_semik, // ;
xme_comment, // // Comment
xme_dot, // .
xme_qual, // identifier . identifer
xme_index, // expr [index_expr]
xme_typmemb, // 'typedef-id : type_member_id'
// xme_vardecl, // Variable declaration via '__var'
} XETYPE;
typedef struct token_s {
XETYPE type;
std::string text;
token_s() : type(xme_what) {}
} token_t;
using TokenList = std::list<token_t>;
const TokenList& GetTokenList() { return m_tokenList; }
protected:
typedef struct expr_s {
expr_s *L;
expr_s *R;
XETYPE tp;
std::string text;
expr_s() : L(0), R(0), tp(xme_what) {}
~expr_s() {
delete L;
delete R;
}
} expr_t;
XETYPE GetChar ();
XETYPE PutChar ();
XETYPE PeekChar ();
XETYPE GetNextToken (token_t& token);
XETYPE SkipWhite ();
XETYPE GetToken (std::string& tokenTxt, const std::string& allowedSymbols);
private:
static const std::string symbol;
static const std::string number;
std::string m_exprStr;
std::size_t m_strPos;
TokenList m_tokenList;
};
#endif // SvdCExpressionParser_H