[add] Added AST types.

This commit is contained in:
falsycat 2019-10-04 00:00:00 +00:00
parent 6c34b1d24d
commit 6886416a30
3 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,51 @@
/// License: MIT
module sjscript.Expression;
import std.variant;
///
struct Expression {
public:
///
Term opBinary(string op : "+", T)(T rhs) const {
return Expression(terms ~ rhs);
}
///
Term opBinary(string op : "-", T)(T rhs) const {
return Expression(terms ~ rhs*(-1f));
}
///
Term[] terms;
}
///
struct Term {
public:
///
alias Value = Algebraic!(float, string, FunctionCall);
///
Term opBinary(string op : "*", T)(T rhs) const {
return Term(multipled_values ~ Value(rhs), divided_values);
}
///
Term opBinary(string op : "/", T)(T rhs) const {
return Term(multipled_values, divided_values ~ Value(rhs));
}
///
Value[] multipled_values;
///
Value[] divided_values;
}
///
struct FunctionCall {
public:
///
string name;
///
Expression[] args;
}

View File

@ -0,0 +1,53 @@
/// License: MIT
module sjscript.ParametersBlock;
import sjscript.Expression,
sjscript.Token;
///
struct ParametersBlock {
public:
///
string name;
///
Period period;
///
Parameter[] parameters;
///
TokenPos pos;
}
///
struct Period {
public:
///
size_t start;
///
size_t end;
}
///
enum ParameterType {
Assign,
AddAssign,
}
///
struct Parameter {
public:
///
string name;
///
ParameterType type;
///
Expression rhs;
///
TokenPos pos;
}

View File

@ -7,6 +7,9 @@ import std.algorithm,
import dast.tokenize;
///
alias TokenPos = dast.tokenize.TokenPos;
///
enum TokenType {
@TextFuncMatcher!((string text, string next) {