From 8c4f46dca6a1bb02082886beac46cbb8e4cf2bbb Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 9 May 2026 02:56:07 +0200 Subject: Add project skeleton --- div.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 div.c (limited to 'div.c') diff --git a/div.c b/div.c new file mode 100644 index 0000000..881234c --- /dev/null +++ b/div.c @@ -0,0 +1,90 @@ +#include "div.h" +#include "gl.h" +#include "im.h" +#include "lk.h" +#include "pr.h" +#include "td.h" +#include "ws.h" + +static const struct seq linkage = + {(struct step[]){{ID, "linkage"}, {0}}, .fn = lk}, + types = {(struct step[]){{ID, "types"}, {0}}, .fn = td}, + imports = + {(struct step[]){{ID, "imports"}, {LIT, NULL, 1}, {0}}, .fn = im}, + procedure = {(struct step[]){{ID, "procedure"}, {0}}, .fn = pr}; + +static const struct seq fnseq[] = +{ + linkage, + types, + imports, + procedure, + {(struct step[]){{ID, "storage"}, {0}}, .fn = ws}, + {(struct step[]){{ID, "globals"}, {0}}, .fn = gl}, + {0} +}; + +static const struct seq imseq[] = +{ + linkage, + types, + imports, + {0} +}; + +static const struct seq pseq[] = +{ + linkage, + procedure, + {0} +}; + +int div_fn(const struct lex *l, struct prv *p) +{ + struct pos init = + { + .seq = fnseq, + .stseq = fnseq, + .step = fnseq->steps + }; + + if (push(&init, p)) + return -1; + + p->stk = p->tk; + return 0; +} + +int div_im(const struct lex *l, struct prv *p) +{ + struct pos init = + { + .seq = imseq, + .stseq = imseq, + .step = imseq->steps + }; + + if (lex_eof(l, p->stk)) + return 0; + else if (push(&init, p)) + return -1; + + p->stk = p->tk; + return 1; +} + +int div_p(const struct lex *l, struct prv *p) +{ + struct pos init = + { + .seq = pseq, + .stseq = pseq, + .step = pseq->steps + }; + + if (push(&init, p)) + return -1; + + p->stk = p->tk; + return 1; +} -- cgit v1.2.3