parse.h (1752B)
1 #ifndef __PARSE_H_ 2 #define __PARSE_H_ 3 #include <stdint.h> 4 #include "lexer.h" 5 #include "util.h" 6 7 enum lexpr_ops { 8 LEXPR_ASSIGN, 9 LEXPR_FUNC, 10 LEXPR_REASSIGN, 11 LEXPR_FCALL, 12 }; 13 14 enum type_types { 15 BASIC, 16 PTR, 17 ARR, 18 }; 19 20 typedef struct rexpr rexpr; 21 22 typedef struct type { 23 enum type_types type; 24 union { 25 char *name; /* basic types */ 26 struct { 27 struct type *nested; /* ptr types */ 28 rexpr *size; 29 }; 30 31 }; 32 } type; 33 34 typedef struct rexpr { 35 enum lex_ops op; 36 type *type; 37 union { 38 struct { /* unary ops */ 39 struct rexpr *e; 40 }; 41 struct { /* operators */ 42 struct rexpr *expr[2]; 43 }; 44 struct { /* fun call */ 45 char *fname; 46 struct rexpr *args; 47 int argc; 48 }; 49 /* litterals */ 50 uint64_t n; 51 double f; 52 char *name; 53 struct { /* array litterals */ 54 rexpr *elements; 55 int elementc; 56 }; 57 }; 58 } rexpr; 59 60 typedef struct lexpr { 61 enum lexpr_ops op; 62 union { 63 struct { /* assignments */ 64 type *type; 65 char *name; 66 rexpr *rexpr; 67 }; 68 struct { /* function decs */ 69 type *rtype; 70 char *fname; 71 struct lexpr *args; /* must be of type assign */ 72 int argc; 73 struct lexpr *body; 74 int bodyc; 75 }; 76 rexpr *ret; /* the return value for return statements */ 77 }; 78 } lexpr; 79 80 extern int haserrored; 81 82 void parserErr(const char *msg, lex l); 83 int getpres(tok t); 84 int isop(tok t); 85 tok *findend(tok *start, tok *end); 86 tok *findlowest(tok *start, tok *end); 87 rexpr *parsesimple(tok *start, tok *end, tok *lowest, mctx *ctx); 88 rexpr *parsebin(tok *start, tok *end, tok *lowest, mctx *ctx); 89 rexpr *parserexpr(tok *start, tok *end, mctx *ctx); 90 type *parsetype(lex *l, mctx *ctx); 91 int isterm(tok t); 92 lexpr *parseassign(lex *l, tok name, mctx *ctx); 93 lexpr *parsefunc(lex *l, mctx *ctx); 94 lexpr *parselexpr(lex *l, mctx *ctx); 95 #endif