diff --git a/sjscript/src/sjscript/Expression.d b/sjscript/src/sjscript/Expression.d new file mode 100644 index 0000000..895a523 --- /dev/null +++ b/sjscript/src/sjscript/Expression.d @@ -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; +} diff --git a/sjscript/src/sjscript/ParametersBlock.d b/sjscript/src/sjscript/ParametersBlock.d new file mode 100644 index 0000000..bb91003 --- /dev/null +++ b/sjscript/src/sjscript/ParametersBlock.d @@ -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; +} diff --git a/sjscript/src/sjscript/Token.d b/sjscript/src/sjscript/Token.d index c02604f..0bdb0d4 100644 --- a/sjscript/src/sjscript/Token.d +++ b/sjscript/src/sjscript/Token.d @@ -7,6 +7,9 @@ import std.algorithm, import dast.tokenize; +/// +alias TokenPos = dast.tokenize.TokenPos; + /// enum TokenType { @TextFuncMatcher!((string text, string next) {