summaryrefslogtreecommitdiff
path: root/parser.h
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2016-07-30 18:26:24 +0200
committerTom Smeding <tom.smeding@gmail.com>2016-07-30 18:26:24 +0200
commit8b49e73d6089e4a9195ce01c3f4c95e85336397d (patch)
tree814dff997ccba703a5108e50520fdef52661d3a5 /parser.h
parent94fd6ce2902ebb8b933763bda8c3280914d6ae20 (diff)
Second
Diffstat (limited to 'parser.h')
-rw-r--r--parser.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/parser.h b/parser.h
new file mode 100644
index 0000000..d5f4978
--- /dev/null
+++ b/parser.h
@@ -0,0 +1,79 @@
+#pragma once
+
+#include <stdint.h>
+
+typedef enum ASTtype{
+ AST_BLOCK,
+ AST_OP,
+ AST_NUM,
+ AST_STR,
+ AST_VAR,
+ AST_CALL,
+ AST_IF,
+ AST_WHILE,
+} ASTtype;
+
+
+typedef struct AST AST;
+typedef struct ASTblock ASTblock;
+typedef struct ASTop ASTop;
+typedef struct ASTnum ASTnum;
+typedef struct ASTstr ASTstr;
+typedef struct ASTvar ASTvar;
+typedef struct ASTcall ASTcall;
+typedef struct ASTif ASTif;
+typedef struct ASTwhile ASTwhile;
+
+
+struct ASTblock{
+ int len;
+ AST *exprs;
+};
+struct ASTop{
+ const char *op; // Constant string, does not need to be freed
+ AST *left,*right;
+};
+struct ASTnum{
+ bool isint;
+ union {
+ int64_t i;
+ double d;
+ };
+};
+struct ASTstr{
+ int len; // Excludes terminating null char
+ char *str; // May contain null chars before terminating null char
+};
+struct ASTvar{
+ char *name;
+};
+struct ASTcall{
+ char *func;
+ int nargs;
+ AST *args; // Array<AST>
+};
+struct ASTif{
+ AST *cond;
+ AST *thenb,*elseb;
+};
+struct ASTwhile{
+ AST *cond;
+ AST *body;
+};
+
+typedef struct AST{
+ ASTtype type;
+ union {
+ ASTblock b;
+ ASTop o;
+ ASTnum n;
+ ASTstr s;
+ ASTvar v;
+ ASTcall c;
+ ASTif i;
+ ASTwhile w;
+ };
+} AST;
+
+
+AST* parse(const char *source);