summaryrefslogtreecommitdiff
path: root/parse.h
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-05-09 02:56:07 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2026-06-05 00:39:03 +0200
commitb113fc207851cb115b598a2f68883b408d75a891 (patch)
treef6e868e2678923d70c7a871d73ee2ac240ed287c /parse.h
downloadslcob-b113fc207851cb115b598a2f68883b408d75a891.tar.gz
Add project skeleton
Diffstat (limited to 'parse.h')
-rw-r--r--parse.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/parse.h b/parse.h
new file mode 100644
index 0000000..b1cfef5
--- /dev/null
+++ b/parse.h
@@ -0,0 +1,129 @@
+#ifndef PARSE_H
+#define PARSE_H
+
+#include "lex.h"
+
+struct u
+{
+ struct storage *storage;
+};
+
+struct s
+{
+ struct storage *storage;
+};
+
+union c
+{
+ unsigned long long uv;
+ long long v;
+};
+
+struct p
+{
+ struct fn *fn;
+};
+
+struct t
+{
+ const struct type *alias;
+};
+
+struct ptr
+{
+ const struct type *t;
+};
+
+struct ary
+{
+ unsigned long long n;
+ int etc;
+};
+
+struct builtin
+{
+ const char *name;
+};
+
+struct type
+{
+ enum {U, S, C, P, T, PTR, ARY, BUILTIN} type;
+ const struct tk *tk;
+ size_t sz, align;
+ int sign;
+ struct type *child, *next;
+
+ union
+ {
+ struct u u;
+ struct s s;
+ union c c;
+ struct p p;
+ struct t t;
+ struct ptr ptr;
+ struct ary ary;
+ struct builtin b;
+ } u;
+};
+
+struct param
+{
+ const struct tk *tk;
+ const struct stentry *entry;
+};
+
+struct pr
+{
+ const struct tk *tk;
+ struct param *params, *ret;
+ size_t nparams;
+ int variadic;
+};
+
+struct td
+{
+ const struct tk *tk;
+ struct type *types;
+ size_t ntypes;
+};
+
+struct fn
+{
+ const struct tk *tk;
+ const struct fn *parent;
+ enum linkage {EXTERNAL, STATIC} linkage;
+ struct storage *lk, *ws, *gl;
+ struct stmt *stmts;
+ struct im *imps;
+ struct pr *pr;
+ struct td *td;
+ size_t nstmts, nimps;
+};
+
+struct lit
+{
+ char *name;
+ const struct tk *tk;
+ const struct fn *fn;
+ struct lit *next;
+};
+
+struct ast
+{
+ struct fn *fns;
+ struct lit *lits, *lastlit;
+ struct type *types;
+ size_t nfns, litcnt;
+};
+
+struct im
+{
+ struct lex l;
+ struct ast ast;
+};
+
+int parse(const struct lex *l, struct ast *ast);
+int parse_im(const struct lex *l, struct ast *ast);
+void ast_free(struct ast *ast);
+
+#endif