all repos — mgba @ 47605b40e73704734a0f4187e323040280ad87d9

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_AND,
22	OP_OR,
23	OP_XOR,
24	OP_LESS,
25	OP_GREATER,
26	OP_EQUAL,
27	OP_LE,
28	OP_GE,
29};
30
31struct Token {
32	enum TokenType {
33		TOKEN_ERROR_TYPE,
34		TOKEN_UINT_TYPE,
35		TOKEN_IDENTIFIER_TYPE,
36		TOKEN_OPERATOR_TYPE,
37		TOKEN_OPEN_PAREN_TYPE,
38		TOKEN_CLOSE_PAREN_TYPE,
39		TOKEN_SEGMENT_TYPE,
40	} type;
41	union {
42		uint32_t uintValue;
43		char* identifierValue;
44		enum Operation operatorValue;
45	};
46};
47
48DECLARE_VECTOR(LexVector, struct Token);
49
50struct ParseTree {
51	struct Token token;
52	struct ParseTree* lhs;
53	struct ParseTree* rhs;
54};
55
56size_t lexExpression(struct LexVector* lv, const char* string, size_t length);
57void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
58
59void lexFree(struct LexVector* lv);
60void parseFree(struct ParseTree* tree);
61
62struct mDebugger;
63bool mDebuggerEvaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, int32_t* value, int* segment);
64
65CXX_GUARD_END
66
67#endif