diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-02-04 23:26:05 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-02-04 23:26:05 +0100 |
commit | 76500bc57fa7d27c73905739a12520706f817534 (patch) | |
tree | 2a7f1661fbcc6ec164c5cbb7421198e71d1b4b6d /ast.h | |
parent | b3ad2e88c9462391fb6d323f6f7737ed5ceedb46 (diff) |
Parses list.squig
Diffstat (limited to 'ast.h')
-rw-r--r-- | ast.h | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -1,5 +1,6 @@ #pragma once +#include <iostream> #include <string> #include <vector> #include "global.h" @@ -8,6 +9,7 @@ using namespace std; class Statement; +class Expression; using Name = string; using StatementList = vector<Statement>; @@ -18,37 +20,45 @@ public: Site(); Site(const string &filename,i64 lnum,i64 linex); + + Site addX(i64 dx); }; +ostream& operator<<(ostream &os,Site site); + class Scope{ public: enum class Type{ direct, lazy, function, - async, + // async, }; Type type; StatementList body; - vector<Name> args; + vector<Expression> args; Site site; Scope(); - Scope(Type type,const StatementList &body,const vector<Name> &args); + Scope(Type type,const StatementList &body,const vector<Expression> &args); + // Scope(Type type,const StatementList &body,const vector<Name> &args); }; +ostream& operator<<(ostream &os,const Scope &scope); + class Expression{ public: enum class Type{ binop, // name, args[0], args[1] unop, // name, args[0] - call, // name, args - dive, // name, args, body + call, // name, args -- variable reference when args={} + dive, // name, args, scope -- variable dive when args={} number, // numval string, // strval scope, // scope + cond, // args[0] (cond), args[1] (then), args[2] (else) }; Type type; @@ -57,19 +67,21 @@ public: double numval; string strval; Scope scope; - StatementList body; Site site; - Expression(); + // 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,const Name &name,const vector<Expression> &args,const Scope &scope); // dive Expression(Type type,double numval); // number Expression(Type type,const string &strval); // string Expression(Type type,const Scope &scope); // scope + Expression(Type type,const vector<Expression> &args); // cond }; +ostream& operator<<(ostream &os,const Expression &expr); + class Statement{ public: enum class Type{ @@ -88,3 +100,6 @@ public: Statement(Type type,const Name &dstvar,const Expression &expr); // create, assign Statement(Type type,const Expression &expr); // expr }; + +ostream& operator<<(ostream &os,const Statement &st); +ostream& operator<<(ostream &os,const StatementList &stl); |