summaryrefslogtreecommitdiff
path: root/ast.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-02-03 22:00:23 +0100
committertomsmeding <tom.smeding@gmail.com>2017-02-03 22:00:23 +0100
commit7c785439fca59b3801ca2a1118ae25a98d03750d (patch)
tree06ccaadec5dbfda16ec9e08bbb7026cc724e2eda /ast.h
Initial
Diffstat (limited to 'ast.h')
-rw-r--r--ast.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/ast.h b/ast.h
new file mode 100644
index 0000000..78abd55
--- /dev/null
+++ b/ast.h
@@ -0,0 +1,90 @@
+#pragma once
+
+#include <string>
+#include <vector>
+#include "global.h"
+
+using namespace std;
+
+
+class Statement;
+using Name = string;
+using StatementList = vector<Statement>;
+
+class Site{
+public:
+ string filename;
+ i64 lnum,linex;
+
+ Site();
+ Site(const string &filename,i64 lnum,i64 linex);
+};
+
+class Scope{
+public:
+ enum class Type{
+ direct,
+ lazy,
+ function,
+ async,
+ };
+
+ Type type;
+ StatementList body;
+ vector<Name> args;
+
+ Site site;
+
+ Scope();
+ Scope(Type type,const StatementList &body,const vector<Name> &args);
+};
+
+class Expression{
+public:
+ enum class Type{
+ binop, // name, args[0], args[1]
+ unop, // name, args[0]
+ call, // name, args
+ dive, // name, args, body
+ number, // numval
+ string, // strval
+ scope, // scope
+ };
+
+ Type type;
+ Name name;
+ vector<Expression> args;
+ double numval;
+ string strval;
+ Scope scope;
+ StatementList body;
+
+ Site site;
+
+ Expression();
+ Expression(Type type,const Name &name,const vector<Expression> &args); // binop, call
+ Expression(Type type,const Name &name,const Expression &arg); // unop
+ Expression(Type type,const Name &name,const vector<Expression> &args,const StatementList &body); // dive
+ Expression(Type type,double numval); // number
+ Expression(Type type,const string &strval); // string
+ Expression(Type type,const Scope &scope); // scope
+};
+
+class Statement{
+public:
+ enum class Type{
+ create, // dstvar, expr
+ assign, // dstvar, expr
+ expression, // expr
+ };
+
+ Type type;
+ Name dstvar;
+ Expression expr;
+
+ Site site;
+
+ Statement();
+ Statement(Type type,const Name &dstvar,const Expression &expr); // create, assign
+ Statement(Type type,const Expression &expr); // expr
+};