all repos — mgba @ f5ef07bebb7cdc0df60c63cc739c44e95ec0650e

mGBA Game Boy Advance Emulator

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
15enum Operation {
16	OP_ASSIGN,
17	OP_ADD,
18	OP_SUBTRACT,
19	OP_MULTIPLY,
20	OP_DIVIDE,
21	OP_MODULO,
22	OP_AND,
23	OP_OR,
24	OP_XOR,
25	OP_LESS,
26	OP_GREATER,
27	OP_EQUAL,
28	OP_NOT_EQUAL,
29	OP_LOGICAL_AND,
30	OP_LOGICAL_OR,
31	OP_LE,
32	OP_GE,
33	OP_NEGATE,
34	OP_FLIP,
35	OP_NOT,
36	OP_SHIFT_L,
37	OP_SHIFT_R,
38};
39
40struct Token {
41	enum TokenType {
42		TOKEN_ERROR_TYPE,
43		TOKEN_UINT_TYPE,
44		TOKEN_IDENTIFIER_TYPE,
45		TOKEN_OPERATOR_TYPE,
46		TOKEN_OPEN_PAREN_TYPE,
47		TOKEN_CLOSE_PAREN_TYPE,
48		TOKEN_SEGMENT_TYPE,
49	} type;
50	union {
51		uint32_t uintValue;
52		char* identifierValue;
53		enum Operation operatorValue;
54	};
55};
56
57DECLARE_VECTOR(LexVector, struct Token);
58
59struct ParseTree {
60	struct Token token;
61	struct ParseTree* lhs;
62	struct ParseTree* rhs;
63};
64
65size_t lexExpression(struct LexVector* lv, const char* string, size_t length);
66void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
67
68void lexFree(struct LexVector* lv);
69void parseFree(struct ParseTree* tree);
70
71struct mDebugger;
72bool mDebuggerEvaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, int32_t* value, int* segment);
73
74CXX_GUARD_END
75
76#endif