all repos — mgba @ f62ccde49d484c65b212ae86299f4720c9dc836d

mGBA Game Boy Advance Emulator

src/debugger/parser.h (view raw)

 1#ifndef PARSER_H
 2#define PARSER_H
 3
 4#include "common.h"
 5#include "debugger.h"
 6
 7enum LexState {
 8	LEX_ERROR = -1,
 9	LEX_ROOT = 0,
10	LEX_EXPECT_IDENTIFIER,
11	LEX_EXPECT_DECIMAL,
12	LEX_EXPECT_HEX,
13	LEX_EXPECT_PREFIX,
14	LEX_EXPECT_OPERATOR
15};
16
17enum Operation {
18	OP_ASSIGN,
19	OP_ADD,
20	OP_SUBTRACT,
21	OP_MULTIPLY,
22	OP_DIVIDE
23};
24
25struct Token {
26	enum TokenType {
27		TOKEN_ERROR_TYPE,
28		TOKEN_UINT_TYPE,
29		TOKEN_IDENTIFIER_TYPE,
30		TOKEN_OPERATOR_TYPE,
31		TOKEN_OPEN_PAREN_TYPE,
32		TOKEN_CLOSE_PAREN_TYPE,
33	} type;
34	union {
35		uint32_t uintValue;
36		char* identifierValue;
37		enum Operation operatorValue;
38	};
39};
40
41struct LexVector {
42	struct LexVector* next;
43	struct Token token;
44};
45
46struct ParseTree {
47	struct Token token;
48	struct ParseTree* lhs;
49	struct ParseTree* rhs;
50};
51
52size_t lexExpression(struct LexVector* lv, const char* string, size_t length);
53void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
54
55void lexFree(struct LexVector* lv);
56void parseFree(struct ParseTree* tree);
57
58#endif