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#include "debugger.h"
11
12enum LexState {
13 LEX_ERROR = -1,
14 LEX_ROOT = 0,
15 LEX_EXPECT_IDENTIFIER,
16 LEX_EXPECT_BINARY,
17 LEX_EXPECT_DECIMAL,
18 LEX_EXPECT_HEX,
19 LEX_EXPECT_PREFIX,
20 LEX_EXPECT_OPERATOR
21};
22
23enum Operation {
24 OP_ASSIGN,
25 OP_ADD,
26 OP_SUBTRACT,
27 OP_MULTIPLY,
28 OP_DIVIDE
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 } type;
40 union {
41 uint32_t uintValue;
42 char* identifierValue;
43 enum Operation operatorValue;
44 };
45};
46
47struct LexVector {
48 struct LexVector* next;
49 struct Token token;
50};
51
52struct ParseTree {
53 struct Token token;
54 struct ParseTree* lhs;
55 struct ParseTree* rhs;
56};
57
58size_t lexExpression(struct LexVector* lv, const char* string, size_t length);
59void parseLexedExpression(struct ParseTree* tree, struct LexVector* lv);
60
61void lexFree(struct LexVector* lv);
62void parseFree(struct ParseTree* tree);
63
64#endif