aboutsummaryrefslogtreecommitdiff
path: root/src/parser.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.h')
-rw-r--r--src/parser.h58
1 files changed, 35 insertions, 23 deletions
diff --git a/src/parser.h b/src/parser.h
index ba5aa58..62f557b 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -8,45 +8,57 @@
#include "lexer.h"
enum {
- PRSDECL, /* Declaration */
- PRSNUMERIC, /* Numeric constant */
- PRSTYPE, /* Type */
+ /* Variable declaration, lhs and rhs may be unused
+ ‘x: lhs = rhs’ */
+ ASTDECL,
- PRSBINADD = '+', /* Addition */
+ /* Constant declaration, lhs and rhs may be unused
+ ‘x: lhs : rhs’ */
+ ASTCDECL,
+
+ /* Function prototype
+ ‘(a: b, c: d) rhs’; aux[lhs].fnproto */
+ ASTFNPROTO,
+
+ /* Function, lhs is the prototype and rhs is the body block */
+ ASTFN,
+
+ /* Braced block, sublist[lhs…rhs] */
+ ASTBLK,
+
+ /* Numeric literal */
+ ASTNUMLIT,
+
+ /* Typename */
+ ASTTYPE,
+
+ /* Return statement, rhs may be unused
+ ‘return rhs’ */
+ ASTRET,
+
+ /* Binary add
+ ‘lhs + rhs’ */
+ ASTBINADD = '+',
+
+ /* Binary sub
+ ‘lhs - rhs’ */
+ ASTBINSUB = '-',
};
typedef uint8_t ast_kind;
#define AST_SOA_BLKSZ (sizeof(ast_kind) + sizeof(size_t) * 4)
-/*
- * AST Notes:
- *
- * Declarations have .lhs set to the type of the symbol being declared and .rhs
- * set to the value of the declaration if it is an assignment declaration. They
- * also have aux.constdecl set to true if it’s a declaration of a constant.
- */
-
-struct auxilliary {
- union extra {
- bool constdecl;
- } *buf;
- size_t len, cap;
-};
-
struct ast_soa {
ast_kind *kinds;
size_t *lexemes;
struct {
size_t lhs, rhs;
} *kids;
- size_t *extra;
size_t len, cap;
-
- struct auxilliary aux;
};
-#define ast_free(x) do { free((x).kinds); free((x).aux.buf); } while (0)
+#define ast_free(x) free((x).kinds)
/* Parse the tokens in TOKS into an abstract syntax tree */
struct ast_soa parsetoks(struct lexemes_soa toks);