aboutsummaryrefslogtreecommitdiff
path: root/include/parse.h
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2025-05-05 11:54:58 +0200
committerHimbeer <himbeer@disroot.org>2025-05-05 11:54:58 +0200
commit828f7cfe05eec5547837867101fc662c3dea60f1 (patch)
treed42580915bc74937c9d5bf14f678679bc3ab3d35 /include/parse.h
parentc640c9856b499af2ed5faedbf03e9945d74aafa9 (diff)
Define overhauled AST data structures
Diffstat (limited to 'include/parse.h')
-rw-r--r--include/parse.h170
1 files changed, 130 insertions, 40 deletions
diff --git a/include/parse.h b/include/parse.h
index 5b97353..64d1eac 100644
--- a/include/parse.h
+++ b/include/parse.h
@@ -2,77 +2,167 @@
#define CERC_PARSE_H
#include "expr.h"
-struct ast_expr {
- struct disjunction_e dis;
+struct ast_local {
+ const char *name;
+ struct type type;
+ struct expr *init;
};
-struct ast_externfunc {
- const char *name;
- struct type ret;
- struct type *params;
- int paramsz, paramlen;
+struct ast_assign {
+ struct expr lhs;
+ struct expr rhs;
+};
+
+enum crement {
+ INCREMENT,
+ DECREMENT,
+};
+
+struct ast_elsebody {
+ struct ast_stmt *stmts;
+ int stmtsz, stmtlen;
+};
+
+struct ast_else {
+ int cond;
+ union {
+ struct ast_if *conditional;
+ struct ast_elsebody body;
+ } action;
+};
+
+struct ast_if {
+ struct expr cond;
+ struct ast_stmt *stmts;
+ int stmtsz, stmtlen;
+ struct ast_else *alt;
+};
+
+struct ast_for {
+ struct ast_stmt *init;
+ struct expr cond;
+ struct ast_stmt *step;
+ struct ast_stmt *stmts;
+ int stmtsz, stmtlen;
+};
+
+struct ast_return {
+ struct expr *value;
+};
+
+enum stmt {
+ S_LOCALVAR,
+ S_ASSIGN,
+ S_ADDASSIGN,
+ S_SUBASSIGN,
+ S_MULASSIGN,
+ S_DIVASSIGN,
+ S_REMASSIGN,
+ S_ANDASSIGN,
+ S_ORASSIGN,
+ S_XORASSIGN,
+ S_INCR,
+ S_DECR,
+ S_IF,
+ S_FOR,
+ S_RETURN,
+ S_EXPR,
};
-struct ast_param {
+struct ast_stmt {
+ enum stmt kind;
+ union {
+ struct ast_local localvar;
+ struct ast_assign assign;
+ enum crement cre;
+ struct ast_if conditional;
+ struct ast_for loop;
+ struct ast_return ret;
+ struct expr e;
+ } stmt;
+};
+
+struct ast_include {
+ const char *path;
+};
+
+struct ast_global {
const char *name;
+ int ispub;
+ int isextern;
struct type type;
};
-enum subfield {
- SUB_INDEX,
- SUB_FIELD,
+struct ast_const {
+ const char *name;
+ struct expr value;
};
-struct loc_postfix {
- enum subfield sub;
- union {
- struct ast_expr index;
- const char *field;
- } id;
+struct ast_enumvar {
+ const char *name;
+ struct expr *override;
};
-enum const_global {
- CST_TYPE,
- CST_BOOL,
- CST_NUMBER,
- CST_STRING,
+struct ast_enum {
+ struct expr init;
+ struct ast_enumvar *variants;
+ int variantsz, variantlen;
};
-struct ast_const_global {
+struct ast_field {
const char *name;
- enum const_global kind;
- union {
- struct type type;
- bool b;
- struct number num;
- char *str;
- } value;
+ struct type type;
};
-struct ast_import {
- struct path path;
+struct ast_struct {
const char *name;
+ int align;
+ struct ast_field *fields;
+ int fieldsz, fieldlen;
+};
+
+struct ast_union {
+ const char *name;
+ struct type *types;
+ int typesz, typelen;
+};
+
+struct ast_func {
+ int ispub;
+ int isextern;
+ const char *name;
+ struct ast_field *params;
+ int paramsz, paramlen;
+ struct type *ret;
+ struct ast_stmt *stmts;
+ int stmtsz, stmtlen;
};
enum toplevel {
- TOP_EXTERNFUNC,
- TOP_FUNC,
+ TOP_INCLUDE,
+ TOP_GLOBAL,
TOP_CONST,
+ TOP_ENUM,
+ TOP_STRUCT,
+ TOP_UNION,
+ TOP_FUNC,
};
struct ast_toplevel {
enum toplevel kind;
union {
- struct ast_externfunc *extfn;
- struct ast_func *function;
- struct ast_const_global *constant;
- } decl;
+ struct ast_include include;
+ struct ast_global globalvar;
+ struct ast_const constant;
+ struct ast_enum enumconst;
+ struct ast_struct structdecl;
+ struct ast_union uniondecl;
+ struct ast_func function;
+ } tl;
};
struct ast_unit {
- struct ast_import *imports;
struct ast_toplevel *tops;
- int impsz, implen;
int topsz, toplen;
};