diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-06-11 02:00:25 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-06-11 02:00:25 +0200 |
commit | 5a78c6d8f0e30b7815729d9589e2252e439553e0 (patch) | |
tree | d92beb5410d162be26baba373c1a9745bac42ad1 /src/parser.h | |
parent | df36746da04ad7e1c3dc4db8233b1910a37f2f49 (diff) |
Parse very basic declarations
Diffstat (limited to 'src/parser.h')
-rw-r--r-- | src/parser.h | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/parser.h b/src/parser.h index 8da762d..ba5aa58 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,19 +1,38 @@ #ifndef ORYX_PARSER_H #define ORYX_PARSER_H +#include <stdbool.h> #include <stddef.h> #include <stdint.h> #include "lexer.h" enum { - PRSBINADD = '+', - PRSBINSUB = '-', + PRSDECL, /* Declaration */ + PRSNUMERIC, /* Numeric constant */ + PRSTYPE, /* Type */ + + PRSBINADD = '+', /* Addition */ }; typedef uint8_t ast_kind; -#define AST_SOA_BLKSZ (sizeof(ast_kind) + sizeof(size_t) * 3) +#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; @@ -21,10 +40,13 @@ struct ast_soa { struct { size_t lhs, rhs; } *kids; + size_t *extra; size_t len, cap; + + struct auxilliary aux; }; -#define ast_free(x) free((x).kinds) +#define ast_free(x) do { free((x).kinds); free((x).aux.buf); } while (0) /* Parse the tokens in TOKS into an abstract syntax tree */ struct ast_soa parsetoks(struct lexemes_soa toks); |