all repos — mgba @ 6d898542c765f4efc4a094c5ebd3f3465c36f417

mGBA Game Boy Advance Emulator

src/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 "util/common.h"
10
11CXX_GUARD_START
12
13#include "debugger.h"
14
15enum LexState {
16	LEX_ERROR = -1,
17	LEX_ROOT = 0,
18	LEX_EXPECT_IDENTIFIER,
19	LEX_EXPECT_BINARY,
20	LEX_EXPECT_DECIMAL,
21	LEX_EXPECT_HEX,
22	LEX_EXPECT_PREFIX,
23	LEX_EXPECT_OPERATOR
24};
25
26enum Operation {
27	OP_ASSIGN,
28	OP_ADD,
29	OP_SUBTRACT,
30	OP_MULTIPLY,
31	OP_DIVIDE
32};
33
34struct Token {
35	enum TokenType {
36		TOKEN_ERROR_TYPE,
37		TOKEN_UINT_TYPE,
38		TOKEN_IDENTIFIER_TYPE,
39		TOKEN_OPERATOR_TYPE,
40		TOKEN_OPEN_PAREN_TYPE,
41		TOKEN_CLOSE_PAREN_TYPE,
42		TOKEN_SEGMENT_TYPE,
43	} type;
44	union {
45		uint32_t uintValue;
46		char* identifierValue;
47		enum Operation operatorValue;
48	};
49};
50
51struct LexVector {
52	struct LexVector* next;
53	struct Token token;
54};
55
56struct ParseTree {
57	struct Token token;
58	struct ParseTree* lhs;
59	struct ParseTree* rhs;
60};
61
62size_t lexExpression(struct LexVector* lv, const char* string, size_t length);
63void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
64
65void lexFree(struct LexVector* lv);
66void parseFree(struct ParseTree* tree);
67
68CXX_GUARD_END
69
70#endif