all repos — mgba @ 7edf7cdb159618bfe4c58d1306f004238556b25a

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
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	OP_DEREFERENCE,
42};
43
44struct Token {
45	enum TokenType {
46		TOKEN_ERROR_TYPE,
47		TOKEN_UINT_TYPE,
48		TOKEN_IDENTIFIER_TYPE,
49		TOKEN_OPERATOR_TYPE,
50		TOKEN_OPEN_PAREN_TYPE,
51		TOKEN_CLOSE_PAREN_TYPE,
52		TOKEN_SEGMENT_TYPE,
53	} type;
54	union {
55		uint32_t uintValue;
56		char* identifierValue;
57		enum Operation operatorValue;
58	};
59};
60
61struct ParseTree {
62	struct Token token;
63	struct ParseTree* lhs;
64	struct ParseTree* rhs;
65};
66
67size_t lexExpression(struct LexVector* lv, const char* string, size_t length, const char* eol);
68void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
69
70void lexFree(struct LexVector* lv);
71void parseFree(struct ParseTree* tree);
72
73struct mDebugger;
74bool mDebuggerEvaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, int32_t* value, int* segment);
75
76CXX_GUARD_END
77
78#endif