-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgcode-expression.h
More file actions
61 lines (51 loc) · 1.54 KB
/
gcode-expression.h
File metadata and controls
61 lines (51 loc) · 1.54 KB
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
/*
============================================================================
Name : gcode-expression.h
Author : Radu - Eosif Mihailescu
Version : 1.0 (2013-08-22)
Copyright : (C) 2013 Radu - Eosif Mihailescu <radu.mihailescu@linux360.ro>
Description : G-Code Expression Evaluator API Header
============================================================================
*/
#ifndef GCODE_EXPRESSION_H_
#define GCODE_EXPRESSION_H_
#include <stdint.h>
#define GCODE_ETT_VALUE 0x01
#define GCODE_ETT_OPERATOR 0x02
#define GCODE_ETT_OPEN 0x03
#define GCODE_ETT_CLOSE 0x04
typedef enum {
GCODE_EO_PLUS = 0,
GCODE_EO_MINUS,
GCODE_EO_AND,
GCODE_EO_OR,
GCODE_EO_XOR,
GCODE_EO_STAR,
GCODE_EO_SLASH,
GCODE_EO_MOD,
GCODE_EO_POWER,
} TGCodeExpressionOperators;
typedef enum {
GCODE_EOP_THIRD,
GCODE_EOP_SECOND,
GCODE_EOP_FIRST
} TGCodeExpressionPrecedence;
typedef struct {
TGCodeExpressionOperators oType;
TGCodeExpressionPrecedence oPrec;
} TGCodeExpressionOperator;
typedef struct {
uint8_t tType;
union {
TGCodeExpressionOperator tOperator;
double tValue;
};
} TGCodeExpressionToken;
/* Evaluates expression according to G-Code expression grammar and returns the
* numeric result. */
double evaluate_expression(const char *expression);
/* Scan line for function names, evaluate and replace them and their arguments
* in line with the numeric result. Used for unary expressions without brackets
* i.e. "G01 XSIN10 YATAN9/14" */
void evaluate_unary_expression(char *line);
#endif /* GCODE_EXPRESSION_H_ */