aboutsummaryrefslogtreecommitdiff
path: root/include/expr.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/expr.h')
-rw-r--r--include/expr.h197
1 files changed, 197 insertions, 0 deletions
diff --git a/include/expr.h b/include/expr.h
new file mode 100644
index 0000000..93b9204
--- /dev/null
+++ b/include/expr.h
@@ -0,0 +1,197 @@
+#ifndef CERC_EXPR_H
+#define CERC_EXPR_H
+#include <stdbool.h>
+#include "lex.h"
+#include "type.h"
+
+struct grouping_e {
+ struct disjunction_e *inner;
+};
+
+struct number_e {
+ struct number value;
+ struct type type;
+};
+
+struct array_e {
+ struct cer_array meta;
+ struct disjunction_e *elems;
+ int elemsz, elemlen;
+};
+
+enum literal {
+ LIT_BOOL,
+ LIT_STRING,
+ LIT_NUMBER,
+ LIT_ARRAY,
+};
+
+struct literal_e {
+ enum literal kind;
+ union {
+ bool b;
+ const char *str;
+ struct number_e num;
+ struct array_e arr;
+ } lit;
+};
+
+struct path {
+ const char **segments;
+ int segsz, seglen;
+};
+
+struct call_e {
+ struct path path;
+ struct disjunction_e *args;
+ int argsz, arglen;
+};
+
+enum primary {
+ PRM_GROUPING,
+ PRM_LITERAL,
+ PRM_CALL,
+ PRM_PATH,
+};
+
+struct primary_e {
+ enum primary kind;
+ union {
+ struct grouping_e grp;
+ struct literal_e lit;
+ struct call_e call;
+ struct path path;
+ } prim;
+};
+
+enum unary_postfix {
+ UPS_DEREF,
+ UPS_TRY,
+ UPS_ASSERT,
+};
+
+struct unarypost_e {
+ enum unary_postfix op;
+ struct primary_e prim;
+};
+
+enum unary_prefix {
+ UPR_NUMNEG,
+ UPR_BOOLNEG,
+ UPR_BITNEG,
+};
+
+struct unarypre_e {
+ enum unary_prefix op;
+ struct unarypost_e post;
+};
+
+struct bitfactor_e {
+ struct unarypre_e lhs, *rhs;
+ int rhssz, rhslen;
+};
+
+struct bitsummand_e {
+ struct bitfactor_e lhs, *rhs;
+ int rhssz, rhslen;
+};
+
+struct bin_e {
+ struct bitsummand_e lhs, *rhs;
+ int rhssz, rhslen;
+};
+
+enum factor {
+ FCT_MUL,
+ FCT_DIV,
+ FCT_REM,
+};
+
+struct factor_rhs {
+ enum factor factor;
+ struct bin_e bin;
+};
+
+struct factor_e {
+ struct bin_e lhs;
+ struct factor_rhs *rhs;
+ int rhssz, rhslen;
+};
+
+enum numeral {
+ NUM_ADD,
+ NUM_SUB,
+};
+
+struct num_rhs {
+ enum numeral num;
+ struct factor_e factor;
+};
+
+struct num_e {
+ struct factor_e lhs;
+ struct num_rhs *rhs;
+ int rhssz, rhslen;
+};
+
+enum term {
+ TRM_NUM,
+ TRM_SHL,
+ TRM_SHR,
+};
+
+struct term_e {
+ enum term term;
+ struct num_e lhs, rhs;
+};
+
+enum comparison {
+ CMP_LT,
+ CMP_LE,
+ CMP_GT,
+ CMP_GE,
+};
+
+struct cmp_rhs {
+ enum comparison cmp;
+ struct term_e term;
+};
+
+struct cmp_e {
+ struct term_e lhs;
+ struct cmp_rhs *rhs;
+ int rhssz, rhslen;
+};
+
+struct eq_e {
+ bool invert;
+ struct cmp_e lhs, rhs;
+};
+
+enum boolean {
+ B_EQ,
+ B_CMP,
+};
+
+struct bool_e {
+ enum boolean kind;
+ union {
+ struct eq_e eq;
+ struct cmp_e cmp;
+ } cond;
+};
+
+struct conjunction_e {
+ // At least one required
+ struct bool_e *bools;
+ int boolsz, boollen;
+};
+
+// Entry point
+struct disjunction_e {
+ // At least one required
+ struct conjunction_e *cons;
+ int consz, conlen;
+};
+
+#endif