From 76500bc57fa7d27c73905739a12520706f817534 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 4 Feb 2017 23:26:05 +0100 Subject: Parses list.squig --- ast.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'ast.h') diff --git a/ast.h b/ast.h index 78abd55..de30d5a 100644 --- a/ast.h +++ b/ast.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include "global.h" @@ -8,6 +9,7 @@ using namespace std; class Statement; +class Expression; using Name = string; using StatementList = vector; @@ -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 args; + vector args; Site site; Scope(); - Scope(Type type,const StatementList &body,const vector &args); + Scope(Type type,const StatementList &body,const vector &args); + // Scope(Type type,const StatementList &body,const vector &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 &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,const Name &name,const vector &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 &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); -- cgit v1.2.3-70-g09d2