-
Notifications
You must be signed in to change notification settings - Fork 1
/
Console.h
157 lines (138 loc) · 4.6 KB
/
Console.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
#pragma region Include
#include "Memory.h"
#pragma endregion
#pragma region Definitions
#define FACTOR_NUMBER (uint8_t)1
#define FACTOR_NODE (uint8_t)2
#define FACTOR_FUNCTION (uint8_t)3
#define FACTOR_PARENTHESIS (uint8_t)4
#define GET_NUMBER_ARG(X_ID) (args[X_ID].value.number)
#define GET_MATRIX_ARG(X_ID) (args[X_ID].value.matrix)
#define GET_RADIAN_ARG(X_ID) (memory->radian ? GET_NUMBER_ARG(X_ID) : deg2rad(GET_NUMBER_ARG(X_ID)))
#define INIT_RESULT EValue result = {0};
#define RETURN_RESULT return result;
#define SET_MATRIX_RESULT(X_ID) result.number = false; result.value.matrix = X_ID;
#define SET_NUMBER_RESULT(X_ID) result.number = true; result.value.number = X_ID;
#define SET_UNIT_RESULT(X_ID) result.number = true; result.value.number = memory->radian ? X_ID : rad2deg(X_ID);
#define RETURN_NUMBER_RESULT(X_ID) INIT_RESULT; SET_NUMBER_RESULT(X_ID); RETURN_RESULT;
#define RETURN_MATRIX_RESULT(X_ID) INIT_RESULT; SET_MATRIX_RESULT(X_ID); RETURN_RESULT;
#define RETURN_UNIT_RESULT(X_ID) INIT_RESULT; SET_UNIT_RESULT(X_ID); RETURN_RESULT;
#pragma endregion
#pragma region Structures
struct PFunction
{
char *name;
PTerm *args[CMD_PARAM_COUNT];
uint8_t argcount;
};
struct PFactor
{
PFactor *next;
void *value;
uint8_t type;
bool divisor;
};
struct PTerm
{
PTerm *next;
PFactor *factors;
bool negative;
};
struct PExpression
{
Node *left;
PTerm *right;
char leftname;
bool assignment;
};
struct EValue
{
union
{
float number;
Matrix* matrix;
} value;
bool number;
};
#pragma endregion
PExpression* parse_formula(Memory* memory, char* in, char** out);
PTerm* parse_expression(Memory* memory, char* in, char** out);
PFactor* parse_term(Memory* memory, char* in, char** out);
PFunction* parse_function(Memory* memory, char* in, char** out);
bool run_command(Memory* memory, PExpression* input, bool* newline);
char* check_formula(Memory* memory, PExpression* input);
char* check_expression(Memory* memory, PTerm* input);
char* check_term(Memory* memory, PFactor* input);
char* check_factor(Memory* memory, void* input, uint8_t type);
EValue evaluate_formula(Memory* memory, PExpression* input, char** error);
EValue evaluate_expression(Memory* memory, PTerm* input, char** error);
EValue evaluate_term(Memory* memory, PFactor* input, char** error);
EValue evaluate_factor(Memory* memory, void* input, uint8_t type, char** error);
void free_formula(PExpression* expresion);
void free_expression(PTerm* term);
void free_term(PFactor* factor);
void free_function(PFunction* function);
#pragma region Commands
EValue cmd_clear(CMD_PARAM_DECL);
#pragma region Matrix
EValue cmd_list(CMD_PARAM_DECL);
EValue cmd_get(CMD_PARAM_DECL);
EValue cmd_set(CMD_PARAM_DECL);
EValue cmd_iseq(CMD_PARAM_DECL);
EValue cmd_transpose(CMD_PARAM_DECL);
EValue cmd_inverse(CMD_PARAM_DECL);
EValue cmd_determinant(CMD_PARAM_DECL);
EValue cmd_adjoint(CMD_PARAM_DECL);
EValue cmd_rank(CMD_PARAM_DECL);
EValue cmd_id(CMD_PARAM_DECL);
EValue cmd_diag(CMD_PARAM_DECL);
EValue cmd_low(CMD_PARAM_DECL);
EValue cmd_up(CMD_PARAM_DECL);
EValue cmd_all(CMD_PARAM_DECL);
EValue cmd_rowop(CMD_PARAM_DECL);
EValue cmd_rowswt(CMD_PARAM_DECL);
EValue cmd_rowmul(CMD_PARAM_DECL);
EValue cmd_rowadd(CMD_PARAM_DECL);
EValue cmd_colop(CMD_PARAM_DECL);
EValue cmd_colswt(CMD_PARAM_DECL);
EValue cmd_colmul(CMD_PARAM_DECL);
EValue cmd_coladd(CMD_PARAM_DECL);
EValue cmd_power(CMD_PARAM_DECL);
EValue cmd_power(CMD_PARAM_DECL);
#pragma endregion
#pragma region Math
EValue cmd_abs(CMD_PARAM_DECL);
EValue cmd_pi(CMD_PARAM_DECL);
EValue cmd_e(CMD_PARAM_DECL);
EValue cmd_sqrt(CMD_PARAM_DECL);
EValue cmd_ln(CMD_PARAM_DECL);
EValue cmd_log(CMD_PARAM_DECL);
EValue cmd_deg(CMD_PARAM_DECL);
EValue cmd_rad(CMD_PARAM_DECL);
EValue cmd_sin(CMD_PARAM_DECL);
EValue cmd_cos(CMD_PARAM_DECL);
EValue cmd_tan(CMD_PARAM_DECL);
EValue cmd_cot(CMD_PARAM_DECL);
EValue cmd_sec(CMD_PARAM_DECL);
EValue cmd_csc(CMD_PARAM_DECL);
EValue cmd_sinh(CMD_PARAM_DECL);
EValue cmd_cosh(CMD_PARAM_DECL);
EValue cmd_tanh(CMD_PARAM_DECL);
EValue cmd_coth(CMD_PARAM_DECL);
EValue cmd_sech(CMD_PARAM_DECL);
EValue cmd_csch(CMD_PARAM_DECL);
EValue cmd_asin(CMD_PARAM_DECL);
EValue cmd_acos(CMD_PARAM_DECL);
EValue cmd_atan(CMD_PARAM_DECL);
EValue cmd_acot(CMD_PARAM_DECL);
EValue cmd_asec(CMD_PARAM_DECL);
EValue cmd_acsc(CMD_PARAM_DECL);
EValue cmd_asinh(CMD_PARAM_DECL);
EValue cmd_acosh(CMD_PARAM_DECL);
EValue cmd_atanh(CMD_PARAM_DECL);
EValue cmd_acoth(CMD_PARAM_DECL);
EValue cmd_asech(CMD_PARAM_DECL);
EValue cmd_acsch(CMD_PARAM_DECL);
#pragma endregion
#pragma endregion