summaryrefslogtreecommitdiff
path: root/ast.h
diff options
context:
space:
mode:
Diffstat (limited to 'ast.h')
-rw-r--r--ast.h31
1 files changed, 23 insertions, 8 deletions
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 <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);