-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.h
89 lines (75 loc) · 2.08 KB
/
eval.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (c) 2020 Anamitra Ghorui
* This file is part of Calcium.
*
* Calcium is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Calcium is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Calcium. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file eval.h
* \author Anamitra Ghorui
* \brief Calcium expression evaluation
*
*/
#ifndef CA_EVAL_H
#define CA_EVAL_H
#include "stack.h"
#include "hashmap.h"
#include "error.h"
#include "types.h"
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
/// Contains the expression and the current location on the expression.
typedef struct CaExpr CaExpr;
struct CaExpr {
CaSize pos;
const char *buf;
};
/// The "context" the evaluator runs on.
typedef struct CaContext {
uint8_t flags;
uint16_t level;
CaHash env;
CaStack *oper;
CaStack *expr;
} CaContext;
/**
* \brief Takes a string and readies it for tokenisation.
* \param data The string
* \return Pointer to a ca_expr struct
*/
CaExpr *ca_tokenize(const char *data);
/**
* \brief Gets the next token, and the type from the expression.
* \param expr The expression to read.
* \param type The type to write back.
* \param start The start of the token.
* \param end The end of the token.
* \return An error code.
*/
CaError ca_next_token(CaExpr *expr, CaType *guess, CaSize *start,
CaSize *end);
/**
* \brief Initialises a context.
* \return A pointer to the context.
*/
CaContext *ca_context_init();
/**
* \brief Evaluates a given expression.
* \param c The context.
* \param s The expression.
* \return An error code.
*/
CaError ca_eval(CaContext c, CaExpr s);
#endif