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
|
#ifndef EVALEXPR_H
#define EVALEXPR_H
#include <stddef.h>
#include "fifo.h"
#include "stack.h"
#include "stack_struct.h"
enum token_type
{
NUMBER = 0,
SUB = 1,
ADD = 1,
MOD = 2,
DIV = 2,
MUL = 2,
EXP = 3,
UN_PLUS = 4,
UN_MINUS = 4,
PAR_LEFT = 5,
PAR_RIGHT = 5,
WRONG_TOKEN = -1,
};
struct token
{
enum token_type type;
int value;
};
// evalrpn
int parse_number(const char *expr, size_t *offset);
int get_operands(struct stack **s, int *op1, int *op2);
int my_pow(int a, int b);
int evalrpn(const char *expr, int *retval);
// shunting yard
int opcmp(struct token *op1, struct token *op2);
enum token_type get_type(char op);
int shunting_yard(const char *expr, char **rpn);
#endif /* ! EVALEXPR_H */
|