From 7c785439fca59b3801ca2a1118ae25a98d03750d Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 3 Feb 2017 22:00:23 +0100 Subject: Initial --- ast.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ast.h (limited to 'ast.h') 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 +#include +#include "global.h" + +using namespace std; + + +class Statement; +using Name = string; +using StatementList = vector; + +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 args; + + Site site; + + Scope(); + Scope(Type type,const StatementList &body,const vector &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 args; + double numval; + string strval; + Scope scope; + StatementList body; + + Site site; + + Expression(); + Expression(Type type,const Name &name,const vector &args); // binop, call + Expression(Type type,const Name &name,const Expression &arg); // unop + Expression(Type type,const Name &name,const vector &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 +}; -- cgit v1.2.3-54-g00ecf