From d07deb178676ca42778524e97f3b9729c83bff99 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 17 Jun 2025 20:41:36 +0100 Subject: init commit --- expr.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 expr.h (limited to 'expr.h') diff --git a/expr.h b/expr.h new file mode 100644 index 0000000..0d7422d --- /dev/null +++ b/expr.h @@ -0,0 +1,61 @@ +typedef struct sheet sheet; + +typedef struct expr expr; +typedef struct value value; /* for recursive case */ +typedef struct postfix postfix; + +typedef enum exprType { + VALUE, + POSTFIX, + NESTED, +} exprType; + +typedef enum valueType { + NUM, + LOC, +} valueType; + +typedef struct loc { + int x, y; +} loc; + +typedef struct expr { + char *expr; + exprType t; + union { + expr *nested; + struct { + value *value; + postfix *postfix; + }; + }; +} expr; + +typedef struct postfix { + char op; + expr *expr; +} postfix; + +typedef struct value { + valueType t; + union { + int num; + loc *loc; + }; +} value; + +extern char *in; +extern char *Pin; + +char isop(char c); +void consumeleading(char c); +expr *parseExpr(); +loc *parseLoc(); +postfix *parsePostfix(); +value *parseValue(); +expr *parseExpr(); +double evalValue(value *v, sheet *s); +double evalPostfix(value *v, postfix *p, sheet *s); +double evalExpr(expr *e, sheet *s); +expr *makeNumber(int n); +void freeExpr(expr *e); -- cgit v1.2.3