include/mgba/internal/debugger/parser.h (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef PARSER_H
7#define PARSER_H
8
9#include <mgba-util/common.h>
10
11#include <mgba-util/vector.h>
12
13CXX_GUARD_START
14
15struct Token;
16DECLARE_VECTOR(LexVector, struct Token);
17
18enum Operation {
19 OP_ASSIGN,
20 OP_ADD,
21 OP_SUBTRACT,
22 OP_MULTIPLY,
23 OP_DIVIDE,
24 OP_MODULO,
25 OP_AND,
26 OP_OR,
27 OP_XOR,
28 OP_LESS,
29 OP_GREATER,
30 OP_EQUAL,
31 OP_NOT_EQUAL,
32 OP_LOGICAL_AND,
33 OP_LOGICAL_OR,
34 OP_LE,
35 OP_GE,
36 OP_NEGATE,
37 OP_FLIP,
38 OP_NOT,
39 OP_SHIFT_L,
40 OP_SHIFT_R,
41};
42
43struct Token {
44 enum TokenType {
45 TOKEN_ERROR_TYPE,
46 TOKEN_UINT_TYPE,
47 TOKEN_IDENTIFIER_TYPE,
48 TOKEN_OPERATOR_TYPE,
49 TOKEN_OPEN_PAREN_TYPE,
50 TOKEN_CLOSE_PAREN_TYPE,
51 TOKEN_SEGMENT_TYPE,
52 } type;
53 union {
54 uint32_t uintValue;
55 char* identifierValue;
56 enum Operation operatorValue;
57 };
58};
59
60struct ParseTree {
61 struct Token token;
62 struct ParseTree* lhs;
63 struct ParseTree* rhs;
64};
65
66size_t lexExpression(struct LexVector* lv, const char* string, size_t length, const char* eol);
67void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
68
69void lexFree(struct LexVector* lv);
70void parseFree(struct ParseTree* tree);
71
72struct mDebugger;
73bool mDebuggerEvaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, int32_t* value, int* segment);
74
75CXX_GUARD_END
76
77#endif