diff options
Diffstat (limited to 'src/parser.h')
-rw-r--r-- | src/parser.h | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/parser.h b/src/parser.h index b4ce8c4..9f7bf5e 100644 --- a/src/parser.h +++ b/src/parser.h @@ -10,10 +10,10 @@ #include "types.h" enum { - /* The first four AST tokens are declarations. A declaration is any token T - for which ‘T <= _AST_DECLS_END’ holds. Declarations can also be made - public by using the ‘pub’ keyword, and you can tell if a declaration is - public by if the LSB is set. */ + /* The first four AST tokens are declarations. A declaration is any + token T for which ‘T <= _AST_DECLS_END’ holds. Declarations can + also be made public by using the ‘pub’ keyword, and you can tell + if a declaration is public by if the LSB is set. */ /* Variable declaration, lhs and rhs may be unused ‘x := rhs’; aux[lhs].decl */ @@ -61,43 +61,44 @@ enum { _AST_LAST_ENT, }; -typedef uint8_t ast_kind_t_; -static_assert(_AST_LAST_ENT - 1 <= (ast_kind_t_)-1, - "Too many AST tokens to fix in AST_KIND_T_"); +static_assert(_AST_LAST_ENT - 1 <= UINT8_MAX, + "Too many AST tokens to fix in uint8_t"); -#define AST_EMPTY ((idx_t_)-1) -#define AST_SOA_BLKSZ (sizeof(ast_kind_t_) + sizeof(idx_t_) * 3) +#define AST_EMPTY ((idx_t)-1) +#define AST_SOA_BLKSZ (1 + sizeof(idx_t) + sizeof(pair_t)) -struct aux { +typedef struct { union { struct { - idx_t_ type; + idx_t type; bool ispub; bool isstatic; } decl; } *buf; size_t len, cap; -}; +} aux_t; + +typedef struct { + idx_t lhs, rhs; +} pair_t; -struct ast { - ast_kind_t_ *kinds; - idx_t_ *lexemes; - struct pair { - idx_t_ lhs, rhs; - } *kids; +typedef struct { + uint8_t *kinds; + idx_t *lexemes; + pair_t *kids; size_t len, cap; -}; +} ast_t; #define ast_free(x) free((x).kinds) #define aux_free(x) free((x).buf) /* Parse the tokens in TOKS into an abstract syntax tree, and store auxilliary information in AUX */ -struct ast parsetoks(struct lexemes toks, struct aux *aux) +ast_t parsetoks(lexemes_t toks, aux_t *aux) __attribute__((nonnull)); /* Starting from the node at indent I in AST, return the index of the next node in AST that is of the same nest-depth as I */ -idx_t_ fwdnode(struct ast ast, idx_t_ i); +idx_t fwdnode(ast_t ast, idx_t i); #endif /* !ORYX_PARSER_H */ |