src/debugger/parser.h (view raw)
1#ifndef PARSER_H
2#define PARSER_H
3
4#include "util/common.h"
5#include "debugger.h"
6
7enum LexState {
8 LEX_ERROR = -1,
9 LEX_ROOT = 0,
10 LEX_EXPECT_IDENTIFIER,
11 LEX_EXPECT_BINARY,
12 LEX_EXPECT_DECIMAL,
13 LEX_EXPECT_HEX,
14 LEX_EXPECT_PREFIX,
15 LEX_EXPECT_OPERATOR
16};
17
18enum Operation {
19 OP_ASSIGN,
20 OP_ADD,
21 OP_SUBTRACT,
22 OP_MULTIPLY,
23 OP_DIVIDE
24};
25
26struct Token {
27 enum TokenType {
28 TOKEN_ERROR_TYPE,
29 TOKEN_UINT_TYPE,
30 TOKEN_IDENTIFIER_TYPE,
31 TOKEN_OPERATOR_TYPE,
32 TOKEN_OPEN_PAREN_TYPE,
33 TOKEN_CLOSE_PAREN_TYPE,
34 } type;
35 union {
36 uint32_t uintValue;
37 char* identifierValue;
38 enum Operation operatorValue;
39 };
40};
41
42struct LexVector {
43 struct LexVector* next;
44 struct Token token;
45};
46
47struct ParseTree {
48 struct Token token;
49 struct ParseTree* lhs;
50 struct ParseTree* rhs;
51};
52
53size_t lexExpression(struct LexVector* lv, const char* string, size_t length);
54void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
55
56void lexFree(struct LexVector* lv);
57void parseFree(struct ParseTree* tree);
58
59#endif