all repos — mgba @ a58f8f8675209df00bd06aada55fb14a270a1e6b

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};
15
16enum Operation {
17	OP_ASSIGN,
18	OP_ADD,
19	OP_SUBTRACT,
20	OP_MULTIPLY,
21	OP_DIVIDE
22};
23
24struct Token {
25	enum TokenType {
26		TOKEN_ERROR_TYPE,
27		TOKEN_UINT_TYPE,
28		TOKEN_IDENTIFIER_TYPE,
29		TOKEN_OPERATOR_TYPE,
30	} type;
31	union {
32		uint32_t uintValue;
33		char* identifierValue;
34		enum Operation operatorValue;
35	};
36};
37
38struct LexVector {
39	struct LexVector* next;
40	struct Token token;
41};
42
43struct ParseTree {
44	struct Token token;
45	struct ParseTree* lhs;
46	struct ParseTree* rhs;
47};
48
49size_t lexExpression(struct LexVector* lv, const char* string, size_t length);
50void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
51
52void lexFree(struct LexVector* lv);
53void parseFree(struct ParseTree* tree);
54
55#endif