new operator modulo and fix operator priority for simple addition
[calc.git] / parser.h
CommitLineData
bc97a989
LM
1#ifndef __PARSER_H__
2#define __PARSER_H__
3
4/* function type */
5
6typedef enum {
f2927108 7 Val = 0,
bc97a989 8 Add, Sub,
c47a9298
LM
9 Mul, Div, Mod,
10 Pow, Sqr,
bc97a989
LM
11 Cos, Sin, Atn,
12 Log, Exp
13} func_t;
14
15/* keyword type */
16
17typedef struct _keyword_t {
18 char *keyword;
19 func_t func;
20 int nbops;
21 int offset;
11cda8d7 22 int prio;
bc97a989
LM
23} keyword_t;
24
25/* calculus element type */
26
0b489a77 27#define MAX_OPERANDS 10
bc97a989
LM
28typedef struct _element_t {
29 func_t func;
30 int nbops;
31 struct _element_t *ops[MAX_OPERANDS];
32 float value;
11cda8d7 33 int prio;
bc97a989
LM
34} element_t;
35
0b489a77
LM
36#define ERROR_OP ((element_t *)(-1))
37
bc97a989
LM
38/* parser function */
39
ef37d966 40element_t *parser (char *str, char **next, int prio);
bc97a989
LM
41
42void print_element (element_t *root, int level);
43
f2927108
LM
44double evaluate_element (element_t *root);
45
bc97a989
LM
46#endif /* __PARSER_H__ */
47
48/* vim: set ts=4 sw=4 et: */