├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── arrow.sublime-syntax ├── examples ├── argtest.ar ├── balls.ar ├── balls2.ar ├── binary.ar ├── ca.ar ├── cell30.ar ├── conway.ar ├── creature.ar ├── eightQueens.ar ├── factorial.ar ├── fib.ar ├── fluid.ar ├── forest.ar ├── forest2.ar ├── forest3.ar ├── gen.ar ├── lists.ar ├── mandelbrot.ar ├── reverse.ar ├── snake.ar ├── snake10.ar ├── snake11.ar ├── snake2.ar ├── snake3.ar ├── snake4.ar ├── snake5.ar ├── snake6.ar ├── snake7.ar ├── snake8.ar ├── snake9.ar ├── sudoku.ar ├── water.ar ├── water2.ar └── wildcard_match.ar ├── src ├── builtin │ ├── ArgExpression.cpp │ ├── ArgExpression.hpp │ ├── BuiltInFunctionExpression.hpp │ ├── BuiltInFunctionExpressionBuilder.hpp │ ├── LengthExpression.cpp │ ├── LengthExpression.hpp │ ├── MapContainsFunctionExpression.cpp │ ├── MapContainsFunctionExpression.hpp │ ├── MapKeysFunctionExpression.cpp │ ├── MapKeysFunctionExpression.hpp │ ├── RandomFunctionExpression.cpp │ ├── RandomFunctionExpression.hpp │ ├── RegexFunctionExpression.cpp │ ├── RegexFunctionExpression.hpp │ ├── SqrtFunctionExpression.cpp │ ├── SqrtFunctionExpression.hpp │ ├── StringInputExpression.cpp │ ├── StringInputExpression.hpp │ ├── SystemCommandExpression.cpp │ ├── SystemCommandExpression.hpp │ ├── ToIntFunctionExpression.cpp │ ├── ToIntFunctionExpression.hpp │ ├── TokenizeFunctionExpression.cpp │ ├── TokenizeFunctionExpression.hpp │ ├── TrimStringFunctionExpression.cpp │ ├── TrimStringFunctionExpression.hpp │ ├── TypeExpression.cpp │ ├── TypeExpression.hpp │ ├── WildcardEqExpression.cpp │ ├── WildcardEqExpression.hpp │ ├── evaluator │ │ ├── ArgExpressionEvaluator.cpp │ │ ├── ArgExpressionEvaluator.hpp │ │ ├── LengthExpressionEvaluator.cpp │ │ ├── LengthExpressionEvaluator.hpp │ │ ├── MapContainsFunctionExpressionEvaluator.cpp │ │ ├── MapContainsFunctionExpressionEvaluator.hpp │ │ ├── MapKeysFunctionExpressionEvaluator.cpp │ │ ├── MapKeysFunctionExpressionEvaluator.hpp │ │ ├── RandomFunctionExpressionEvaluator.cpp │ │ ├── RandomFunctionExpressionEvaluator.hpp │ │ ├── RegexFunctionExpressionEvaluator.cpp │ │ ├── RegexFunctionExpressionEvaluator.hpp │ │ ├── SqrtFunctionExpressionEvaluator.cpp │ │ ├── SqrtFunctionExpressionEvaluator.hpp │ │ ├── StringInputExpressionEvaluator.cpp │ │ ├── StringInputExpressionEvaluator.hpp │ │ ├── SystemCommandExpressionEvaluator.cpp │ │ ├── SystemCommandExpressionEvaluator.hpp │ │ ├── ToIntFunctionExpressionEvaluator.cpp │ │ ├── ToIntFunctionExpressionEvaluator.hpp │ │ ├── TokenizeFunctionExpressionEvaluator.cpp │ │ ├── TokenizeFunctionExpressionEvaluator.hpp │ │ ├── TrimStringFunctionExpressionEvaluator.cpp │ │ ├── TrimStringFunctionExpressionEvaluator.hpp │ │ ├── TypeExpressionEvaluator.cpp │ │ ├── TypeExpressionEvaluator.hpp │ │ ├── WildcardEqExpressionEvaluator.cpp │ │ ├── WildcardEqExpressionEvaluator.hpp │ │ └── WildcardMatch.hpp │ └── filesystem │ │ ├── FileReadBytesFunctionExpression.cpp │ │ ├── FileReadBytesFunctionExpression.hpp │ │ ├── FileReadLinesFunctionExpression.cpp │ │ ├── FileReadLinesFunctionExpression.hpp │ │ ├── FileReceiver.cpp │ │ ├── FileReceiver.hpp │ │ ├── FolderListFunctionExpression.cpp │ │ ├── FolderListFunctionExpression.hpp │ │ ├── FolderListRecursiveFunctionExpression.cpp │ │ ├── FolderListRecursiveFunctionExpression.hpp │ │ └── evaluator │ │ ├── FileReadBytesFunctionExpressionEvaluator.cpp │ │ ├── FileReadBytesFunctionExpressionEvaluator.hpp │ │ ├── FileReadLinesFunctionExpressionEvaluator.cpp │ │ ├── FileReadLinesFunctionExpressionEvaluator.hpp │ │ ├── FileReceiverEvaluator.cpp │ │ ├── FileReceiverEvaluator.hpp │ │ ├── FolderListFunctionExpressionEvaluator.cpp │ │ ├── FolderListFunctionExpressionEvaluator.hpp │ │ ├── FolderListRecursiveFunctionExpressionEvaluator.cpp │ │ └── FolderListRecursiveFunctionExpressionEvaluator.hpp ├── expressions │ ├── BooleanExpression.cpp │ ├── BooleanExpression.hpp │ ├── BracedExpressionCollectionExpression.cpp │ ├── BracedExpressionCollectionExpression.hpp │ ├── DoubleEqualExpression.cpp │ ├── DoubleEqualExpression.hpp │ ├── Expression.cpp │ ├── Expression.hpp │ ├── ExpressionCollectionExpression.cpp │ ├── ExpressionCollectionExpression.hpp │ ├── FunctionExpression.cpp │ ├── FunctionExpression.hpp │ ├── GroupedExpression.cpp │ ├── GroupedExpression.hpp │ ├── HatHatStringExpression.cpp │ ├── HatHatStringExpression.hpp │ ├── HatStringExpression.cpp │ ├── HatStringExpression.hpp │ ├── IdentifierExpression.cpp │ ├── IdentifierExpression.hpp │ ├── IndexExpression.cpp │ ├── IndexExpression.hpp │ ├── ListExpression.cpp │ ├── ListExpression.hpp │ ├── ListWordExpression.cpp │ ├── ListWordExpression.hpp │ ├── LiteralCharExpression.cpp │ ├── LiteralCharExpression.hpp │ ├── LiteralIntExpression.cpp │ ├── LiteralIntExpression.hpp │ ├── LiteralRealExpression.cpp │ ├── LiteralRealExpression.hpp │ ├── LiteralStringExpression.cpp │ ├── LiteralStringExpression.hpp │ ├── MatchesExpression.cpp │ ├── MatchesExpression.hpp │ ├── MathExpression.cpp │ ├── MathExpression.hpp │ ├── NegativeNumberExpression.cpp │ ├── NegativeNumberExpression.hpp │ ├── OperatorExpression.cpp │ ├── OperatorExpression.hpp │ ├── QQStringExpression.cpp │ ├── QQStringExpression.hpp │ ├── QStringExpression.cpp │ ├── QStringExpression.hpp │ ├── SingleEqualExpression.cpp │ ├── SingleEqualExpression.hpp │ └── evaluator │ │ ├── BooleanExpressionEvaluator.cpp │ │ ├── BooleanExpressionEvaluator.hpp │ │ ├── ExpressionEvaluator.hpp │ │ ├── FunctionExpressionEvaluator.cpp │ │ ├── FunctionExpressionEvaluator.hpp │ │ ├── IdentifierEvaluator.cpp │ │ ├── IdentifierEvaluator.hpp │ │ ├── ListExpressionEvaluator.cpp │ │ ├── ListExpressionEvaluator.hpp │ │ ├── MatchesExpressionEvaluator.cpp │ │ ├── MatchesExpressionEvaluator.hpp │ │ ├── MathExpressionEvaluator.cpp │ │ ├── MathExpressionEvaluator.hpp │ │ ├── NegativeNumberEvaluator.cpp │ │ └── NegativeNumberEvaluator.hpp ├── heavy │ ├── HTTPReadExpression.cpp │ ├── HTTPReadExpression.hpp │ └── evaluator │ │ ├── HTTPReadExpressionEvaluator.cpp │ │ └── HTTPReadExpressionEvaluator.hpp ├── lexer │ ├── Lexeme.cpp │ ├── Lexeme.hpp │ ├── Lexer.cpp │ ├── Lexer.hpp │ └── Token.hpp ├── main.cpp ├── parser │ ├── BuiltInFunctionExpressionParser.cpp │ ├── BuiltInFunctionExpressionParser.hpp │ ├── ExpressionParser.cpp │ ├── ExpressionParser.hpp │ ├── LanguageException.hpp │ ├── Node.hpp │ ├── Parser.cpp │ ├── Parser.hpp │ ├── ReceiverParser.cpp │ ├── ReceiverParser.hpp │ ├── TokenManager.cpp │ └── TokenManager.hpp ├── receivers │ ├── ArrayAccessorReceiver.cpp │ ├── ArrayAccessorReceiver.hpp │ ├── DollarIdentifierReceiver.cpp │ ├── DollarIdentifierReceiver.hpp │ ├── IdentifierReceiver.cpp │ ├── IdentifierReceiver.hpp │ ├── Receiver.cpp │ ├── Receiver.hpp │ └── evaluator │ │ ├── ArrayAccessorReceiverEvaluator.cpp │ │ ├── ArrayAccessorReceiverEvaluator.hpp │ │ ├── DollarIdentifierReceiverEvaluator.cpp │ │ ├── DollarIdentifierReceiverEvaluator.hpp │ │ ├── IdentifierReceiverEvaluator.cpp │ │ ├── IdentifierReceiverEvaluator.hpp │ │ └── ReceiverEvaluator.hpp ├── representation │ ├── Environment.cpp │ ├── Environment.hpp │ ├── PodType.cpp │ ├── PodType.hpp │ ├── Type.hpp │ ├── TypeDescriptor.hpp │ ├── VariantType.hpp │ └── real.hpp ├── statements │ ├── AnsiStatement.cpp │ ├── AnsiStatement.hpp │ ├── ArrowlessStatement.cpp │ ├── ArrowlessStatement.hpp │ ├── AsyncStatement.cpp │ ├── AsyncStatement.hpp │ ├── EchoStatement.cpp │ ├── EchoStatement.hpp │ ├── ElseIfStatement.cpp │ ├── ElseIfStatement.hpp │ ├── ElseStatement.cpp │ ├── ElseStatement.hpp │ ├── EraseStatement.cpp │ ├── EraseStatement.hpp │ ├── ExitStatement.cpp │ ├── ExitStatement.hpp │ ├── ForStatement.cpp │ ├── ForStatement.hpp │ ├── FunctionStatement.cpp │ ├── FunctionStatement.hpp │ ├── IfStatement.cpp │ ├── IfStatement.hpp │ ├── LoopBreakStatement.cpp │ ├── LoopBreakStatement.hpp │ ├── PodStatement.cpp │ ├── PodStatement.hpp │ ├── ReleaseStatement.cpp │ ├── ReleaseStatement.hpp │ ├── RepeatStatement.cpp │ ├── RepeatStatement.hpp │ ├── ReturnStatement.cpp │ ├── ReturnStatement.hpp │ ├── ScopedBlockStatement.cpp │ ├── ScopedBlockStatement.hpp │ ├── SimpleArrowStatement.cpp │ ├── SimpleArrowStatement.hpp │ ├── SingleExpressionStatement.cpp │ ├── SingleExpressionStatement.hpp │ ├── StartStatement.cpp │ ├── StartStatement.hpp │ ├── Statement.hpp │ ├── StringToIntStatement.cpp │ ├── StringToIntStatement.hpp │ ├── WhileStatement.cpp │ ├── WhileStatement.hpp │ └── evaluator │ │ ├── ForStatementEvaluator.cpp │ │ ├── ForStatementEvaluator.hpp │ │ ├── FunctionStatementEvaluator.cpp │ │ ├── FunctionStatementEvaluator.hpp │ │ ├── IfStatementEvaluator.cpp │ │ ├── IfStatementEvaluator.hpp │ │ ├── PodStatementEvaluator.cpp │ │ ├── PodStatementEvaluator.hpp │ │ ├── RepeatStatementEvaluator.cpp │ │ ├── RepeatStatementEvaluator.hpp │ │ ├── ScopedBlockStatementEvaluator.cpp │ │ ├── ScopedBlockStatementEvaluator.hpp │ │ ├── SimpleArrowStatementEvaluator.cpp │ │ ├── SimpleArrowStatementEvaluator.hpp │ │ ├── StatementEvaluator.hpp │ │ ├── WhileStatementEvaluator.cpp │ │ └── WhileStatementEvaluator.hpp └── utility │ ├── ThreadManager.cpp │ ├── ThreadManager.hpp │ └── from_string.hpp └── tests └── test.ar /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/benhj/arrow/c5830849101deab9a6fd4f5bf1ac95dfddea2cf0/.gitmodules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ben H D Jones 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/argtest.ar: -------------------------------------------------------------------------------- 1 | start { 2 | arg(0) -> a; 3 | prn a; 4 | } -------------------------------------------------------------------------------- /examples/binary.ar: -------------------------------------------------------------------------------- 1 | ;;; put helpers in some standard helper file? 2 | fn reverse(str) -> reversed { 3 | ;;; reverse the string now since was constructed 4 | ;;; in reverse order 5 | [] -> chars; 6 | for i in str { 7 | [^i ^^chars] -> chars; 8 | } 9 | "" -> reversed; 10 | for i in chars { 11 | reversed + i -> reversed; 12 | } 13 | } 14 | 15 | fn binary (number) -> binaryString { 16 | 17 | ;;; make a string to store the binary string. 18 | ;;; starts out empty 19 | " " -> binaryString; 20 | 21 | while (number > 0 ) { 22 | number % 2 -> bit; 23 | number / 2 -> number; 24 | binaryString + bit -> binaryString; 25 | } 26 | reverse(binaryString) -> binaryString; 27 | } 28 | 29 | ;;; requires an input program argument. 30 | start { 31 | ;;; get first program argument 32 | arg(0) -> a; 33 | 34 | ;;; convert to a binary representation 35 | prn binary(a); 36 | } 37 | -------------------------------------------------------------------------------- /examples/cell30.ar: -------------------------------------------------------------------------------- 1 | fn rule30(left, center, right) -> result { 2 | ' ' -> result; 3 | if (left = 'X' && center = ' ' && right = ' ') { 4 | 'X' -> result; 5 | } elseif (left = ' ' && center = 'X' && right = ' ') { 6 | 'X' -> result; 7 | } elseif (left = ' ' && center = ' ' && right = 'X') { 8 | 'X' -> result; 9 | } elseif (left = ' ' && center = 'X' && right = 'X') { 10 | 'X' -> result; 11 | } 12 | } 13 | 14 | fn initialize(size) -> state { 15 | [] -> state; 16 | 0 -> i; 17 | while i < size { 18 | ' ' -> $state; 19 | i + 1 -> i; 20 | } 21 | size / 2 -> mid; 22 | 'X' -> state:mid; 23 | } 24 | 25 | fn print(state) { 26 | prn state; 27 | } 28 | 29 | fn list_length(list) -> length { 30 | 0 -> length; 31 | for i in list { 32 | length + 1 -> length; 33 | } 34 | } 35 | 36 | fn update(state) -> new_state { 37 | [] -> new_state; 38 | list_length(state) -> size; 39 | 0 -> i; 40 | while i < size { 41 | 0 -> left; 42 | 0 -> right; 43 | 0 -> center; 44 | if i = 0 { 45 | state:(size - 1) -> left; 46 | } else { 47 | state:(i - 1) -> left; 48 | } 49 | state:i -> center; 50 | if i = size - 1 { 51 | state:0 -> right; 52 | } else { 53 | state:(i + 1) -> right; 54 | } 55 | rule30(left, center, right) -> $new_state; 56 | i + 1 -> i; 57 | } 58 | } 59 | 60 | start { 61 | arg(0) -> size; 62 | arg(1) -> steps; 63 | initialize(size) -> state; 64 | print(state); 65 | 0 -> i; 66 | while i < steps { 67 | update(state) -> state; 68 | print(state); 69 | i + 1 -> i; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /examples/eightQueens.ar: -------------------------------------------------------------------------------- 1 | fn canPlaceQueen(r, c, x) -> yes { 2 | true -> yes; 3 | 0 -> i; 4 | while(i < r) { 5 | x:i -> qcol; 6 | if qcol = c || (i - r = qcol - c) || (i - r = c - qcol) { 7 | false -> yes; 8 | return; 9 | } 10 | i + 1 -> i; 11 | } 12 | } 13 | 14 | fn printQueens(N, x) { 15 | for row in x { 16 | 0 -> j; 17 | while j < N { 18 | if row = j { 19 | pr "Q "; 20 | } else { 21 | pr "* "; 22 | } 23 | j + 1 -> j; 24 | } 25 | say "\n"; 26 | } 27 | } 28 | 29 | fn placeNQueens(r, n, x) { 30 | if r = n { 31 | printQueens(n, x); 32 | exit 1; 33 | } 34 | 35 | 0 -> c; 36 | while c < n { 37 | if canPlaceQueen(r, c, x) { 38 | c -> x:r; 39 | placeNQueens(r + 1, n, x); 40 | } 41 | c + 1 -> c; 42 | } 43 | } 44 | 45 | start { 46 | arg(0) -> N; 47 | ;;; Initialize x as N-length array of -1 (unset columns) 48 | [] -> x; 49 | repeat N times { 50 | -1 -> $x; 51 | } 52 | placeNQueens(0, N, x); 53 | } 54 | -------------------------------------------------------------------------------- /examples/factorial.ar: -------------------------------------------------------------------------------- 1 | fn factorial(n) -> f { 2 | 1 -> f; 3 | if (n > 1) { 4 | n * factorial(n - 1) -> f; 5 | } 6 | } 7 | 8 | start { 9 | arg(0) -> N; 10 | pr "result: "; prn factorial(N); 11 | } 12 | -------------------------------------------------------------------------------- /examples/fib.ar: -------------------------------------------------------------------------------- 1 | ;;; Note, all int types are signed 64 bit 2 | 3 | fn fib () { 4 | 5 | ;;; create some variables to store state 6 | 1 -> x; 7 | x -> oldx; 8 | x -> olderx; 9 | 10 | ;;; perform the sequence a number of times 11 | repeat 70 times { 12 | 13 | pr x; 14 | pr " "; 15 | 16 | oldx -> olderx; 17 | x -> oldx; 18 | 19 | ;;; compute new x value 20 | (olderx + oldx) -> x; 21 | } 22 | 23 | prn " "; 24 | 25 | } 26 | 27 | start { 28 | 29 | prn "Calling block fib"; 30 | fib(); 31 | 32 | } -------------------------------------------------------------------------------- /examples/lists.ar: -------------------------------------------------------------------------------- 1 | ;;; will return all nested-list elements in collection that 2 | ;;; match the given pattern 3 | fn find(collection, pattern) -> found { 4 | [] -> found; 5 | for i in collection { 6 | i matches pattern -> yes; 7 | if(yes) { 8 | [^^found ^i] -> found; 9 | } 10 | } 11 | } 12 | 13 | ;;; returns the next item after item in list 14 | fn next_item(item, list) -> next { 15 | false -> next; 16 | list matches [ == ^item ?found ==] -> m; 17 | if (m) { 18 | found -> next; 19 | } 20 | } 21 | 22 | start { 23 | 24 | ;;; trying out some pattern-matcher / list ideas 25 | [name sue age 30 job teacher home york] -> person; 26 | next_item("age", person) -> result; 27 | prn result; 28 | 29 | next_item("home", person) -> result; 30 | prn result; 31 | 32 | next_item("height", person) -> result; 33 | prn result; 34 | 35 | [[animal cat][vehicle car][animal dog]] -> collection; 36 | find(collection, [vehicle ==]) -> found; 37 | prn found; 38 | 39 | } -------------------------------------------------------------------------------- /examples/reverse.ar: -------------------------------------------------------------------------------- 1 | 2 | 3 | fn reverse(str) -> out { 4 | [] -> list; 5 | for i in str { 6 | [^i ^^list] -> list; 7 | } 8 | "" -> out; 9 | for i in list { 10 | out + i -> out; 11 | } 12 | prn out; 13 | } 14 | 15 | start { 16 | reverse("hello") -> result; 17 | prn result; 18 | } 19 | -------------------------------------------------------------------------------- /src/builtin/ArgExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "ArgExpression.hpp" 4 | #include "evaluator/ArgExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | ArgExpression::ArgExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr ArgExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void ArgExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr const & 23 | ArgExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string ArgExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/ArgExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class ArgExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | ArgExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class ArgExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "arg"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/BuiltInFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/Expression.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class BuiltInFunctionExpression 11 | { 12 | public: 13 | virtual void setExpression(std::shared_ptr) = 0; 14 | }; 15 | } -------------------------------------------------------------------------------- /src/builtin/BuiltInFunctionExpressionBuilder.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/Expression.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class BuiltInFunctionExpressionBuilder 12 | { 13 | public: 14 | virtual std::string getName() const = 0; 15 | virtual std::shared_ptr build(long const lineNumber) const = 0; 16 | }; 17 | } -------------------------------------------------------------------------------- /src/builtin/LengthExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "LengthExpression.hpp" 4 | #include "evaluator/LengthExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | LengthExpression::LengthExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr LengthExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void LengthExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr const & 23 | LengthExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string LengthExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/LengthExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class LengthExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | LengthExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class LengthExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "length"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/MapContainsFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "MapContainsFunctionExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/MapContainsFunctionExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | MapContainsFunctionExpression::MapContainsFunctionExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr MapContainsFunctionExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void MapContainsFunctionExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | MapContainsFunctionExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string MapContainsFunctionExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/MapContainsFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class MapContainsFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | MapContainsFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class MapContainsFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "map_contains"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/MapKeysFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "MapKeysFunctionExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/MapKeysFunctionExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | MapKeysFunctionExpression::MapKeysFunctionExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr MapKeysFunctionExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void MapKeysFunctionExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | MapKeysFunctionExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string MapKeysFunctionExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/MapKeysFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class MapKeysFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | MapKeysFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class MapKeysFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "map_keys"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/RandomFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "RandomFunctionExpression.hpp" 4 | #include "evaluator/RandomFunctionExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | RandomFunctionExpression::RandomFunctionExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr RandomFunctionExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void RandomFunctionExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr const & 23 | RandomFunctionExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string RandomFunctionExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/RandomFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class RandomFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | RandomFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class RandomFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "random"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/RegexFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "RegexFunctionExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/RegexFunctionExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | RegexFunctionExpression::RegexFunctionExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr RegexFunctionExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void RegexFunctionExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | RegexFunctionExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string RegexFunctionExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/RegexFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class RegexFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | RegexFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class RegexFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "regex"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/SqrtFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "SqrtFunctionExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/SqrtFunctionExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | SqrtFunctionExpression::SqrtFunctionExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr SqrtFunctionExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void SqrtFunctionExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | SqrtFunctionExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string SqrtFunctionExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/SqrtFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class SqrtFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | SqrtFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class SqrtFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "sqrt"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/StringInputExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "StringInputExpression.hpp" 4 | #include "evaluator/StringInputExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | StringInputExpression::StringInputExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr StringInputExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void StringInputExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr const & 23 | StringInputExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string StringInputExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/StringInputExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class StringInputExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | StringInputExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class StringInputExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "input"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/SystemCommandExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "SystemCommandExpression.hpp" 4 | #include "evaluator/SystemCommandExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | SystemCommandExpression::SystemCommandExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr SystemCommandExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void SystemCommandExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr const & 23 | SystemCommandExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string SystemCommandExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/SystemCommandExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class SystemCommandExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | SystemCommandExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class SystemCommandExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "exec"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/ToIntFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2025 - present 2 | 3 | #include "ToIntFunctionExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/ToIntFunctionExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | ToIntFunctionExpression::ToIntFunctionExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr ToIntFunctionExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void ToIntFunctionExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | ToIntFunctionExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string ToIntFunctionExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/ToIntFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2025 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class ToIntFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | ToIntFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class ToIntFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "to_int"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/TokenizeFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "TokenizeFunctionExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/TokenizeFunctionExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | TokenizeFunctionExpression::TokenizeFunctionExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr TokenizeFunctionExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void TokenizeFunctionExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | TokenizeFunctionExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string TokenizeFunctionExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/TokenizeFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class TokenizeFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | TokenizeFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class TokenizeFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "tokenize"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/TrimStringFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "TrimStringFunctionExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/TrimStringFunctionExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | TrimStringFunctionExpression::TrimStringFunctionExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr TrimStringFunctionExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void TrimStringFunctionExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | TrimStringFunctionExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string TrimStringFunctionExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/TrimStringFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class TrimStringFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | TrimStringFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class TrimStringFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "trim"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/TypeExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "TypeExpression.hpp" 4 | #include "evaluator/TypeExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | TypeExpression::TypeExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr TypeExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void TypeExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr const & 23 | TypeExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string TypeExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/TypeExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class TypeExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | TypeExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class TypeExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "type"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/WildcardEqExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "WildcardEqExpression.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/WildcardEqExpressionEvaluator.hpp" 6 | #include "parser/LanguageException.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | WildcardEqExpression::WildcardEqExpression(long const lineNumber) 12 | : Expression(lineNumber) 13 | { 14 | } 15 | std::shared_ptr WildcardEqExpression::getEvaluator() const 16 | { 17 | return std::make_shared(*this); 18 | } 19 | 20 | void WildcardEqExpression::setExpression(std::shared_ptr expression) 21 | { 22 | m_expression = std::move(expression); 23 | } 24 | std::shared_ptr const & 25 | WildcardEqExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | 30 | std::string WildcardEqExpression::toString() const 31 | { 32 | return ""; // todo 33 | } 34 | } -------------------------------------------------------------------------------- /src/builtin/WildcardEqExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "BuiltInFunctionExpression.hpp" 6 | #include "BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class WildcardEqExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | WildcardEqExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr const & getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class WildcardEqExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "wildcard_eq"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/ArgExpressionEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "parser/LanguageException.hpp" 6 | #include "parser/Parser.hpp" 7 | #include "ArgExpressionEvaluator.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | 12 | ArgExpressionEvaluator::ArgExpressionEvaluator(ArgExpression expression) 13 | : m_expression(std::move(expression)) 14 | { 15 | } 16 | Type ArgExpressionEvaluator::evaluate(Environment & environment) const 17 | { 18 | // Pull out the name of the function 19 | auto const callLineNumber = m_expression.getLineNumber(); 20 | 21 | // Pull out the arguments being passed into the function 22 | auto const expression = m_expression.getExpression(); 23 | auto const col = expression->getEvaluator()->evaluate(environment); 24 | auto & expressionCollEval = std::get>(col.m_variantType); 25 | if(expressionCollEval.empty()) { 26 | throw LanguageException("Expected argument", m_expression.getLineNumber()); 27 | } 28 | auto & t = expressionCollEval[0]; 29 | if(t.m_descriptor != TypeDescriptor::Int) { 30 | throw LanguageException("Expected an integer index", callLineNumber); 31 | } 32 | 33 | auto const index = std::get(t.m_variantType); 34 | try { 35 | return environment.getProgramArgument(index); 36 | } catch (...) { 37 | throw LanguageException("Error obtaining argument", callLineNumber); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/ArgExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/ArgExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class ArgExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit ArgExpressionEvaluator(ArgExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | ArgExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/LengthExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/LengthExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class LengthExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit LengthExpressionEvaluator(LengthExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | LengthExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/MapContainsFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/MapContainsFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class MapContainsFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit MapContainsFunctionExpressionEvaluator(MapContainsFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | MapContainsFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/MapKeysFunctionExpressionEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "MapKeysFunctionExpressionEvaluator.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "parser/LanguageException.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | 11 | MapKeysFunctionExpressionEvaluator::MapKeysFunctionExpressionEvaluator(MapKeysFunctionExpression expression) 12 | : m_expression(std::move(expression)) 13 | { 14 | } 15 | Type MapKeysFunctionExpressionEvaluator::evaluate(Environment & environment) const 16 | { 17 | auto const expression = m_expression.getExpression(); 18 | auto const col = expression->getEvaluator()->evaluate(environment); 19 | auto & expressionCollEval = std::get>(col.m_variantType); 20 | if(expressionCollEval.empty()) { 21 | throw LanguageException("Expected argument", m_expression.getLineNumber()); 22 | } 23 | auto const mapEval = expressionCollEval[0]; 24 | if(mapEval.m_descriptor != TypeDescriptor::Map) { 25 | throw LanguageException("Not a map", m_expression.getLineNumber()); 26 | } 27 | 28 | auto & themap = std::get>(mapEval.m_variantType); 29 | std::vector keys; 30 | for(auto const & entry : themap) { 31 | keys.push_back(entry.first); 32 | } 33 | return {TypeDescriptor::Strings, keys}; 34 | } 35 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/MapKeysFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/MapKeysFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class MapKeysFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit MapKeysFunctionExpressionEvaluator(MapKeysFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | MapKeysFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/RandomFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/RandomFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class RandomFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit RandomFunctionExpressionEvaluator(RandomFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | RandomFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/RegexFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/RegexFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class RegexFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit RegexFunctionExpressionEvaluator(RegexFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | RegexFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/SqrtFunctionExpressionEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "SqrtFunctionExpressionEvaluator.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "parser/LanguageException.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | 11 | SqrtFunctionExpressionEvaluator::SqrtFunctionExpressionEvaluator(SqrtFunctionExpression expression) 12 | : m_expression(std::move(expression)) 13 | { 14 | } 15 | Type SqrtFunctionExpressionEvaluator::evaluate(Environment & environment) const 16 | { 17 | auto const expression = m_expression.getExpression(); 18 | auto const col = expression->getEvaluator()->evaluate(environment); 19 | auto const expressionCollEval = std::get>(col.m_variantType); 20 | if(expressionCollEval.empty()) { 21 | throw LanguageException("Expected argument", m_expression.getLineNumber()); 22 | } 23 | auto const eval = expressionCollEval[0]; 24 | if(eval.m_descriptor == TypeDescriptor::Int) { 25 | auto casted = std::get(eval.m_variantType); 26 | auto val = static_cast(sqrt(casted)); 27 | return {TypeDescriptor::Int, val}; 28 | } else if(eval.m_descriptor == TypeDescriptor::Real) { 29 | auto casted = std::get(eval.m_variantType); 30 | auto val = static_cast(sqrt(casted)); 31 | return {TypeDescriptor::Real, val}; 32 | } else { 33 | throw LanguageException("Bad type for sqrt", m_expression.getLineNumber()); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/SqrtFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/SqrtFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class SqrtFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit SqrtFunctionExpressionEvaluator(SqrtFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | SqrtFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/StringInputExpressionEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "StringInputExpressionEvaluator.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "statements/evaluator/StatementEvaluator.hpp" 6 | #include "expressions/evaluator/IdentifierEvaluator.hpp" 7 | #include "expressions/IdentifierExpression.hpp" 8 | #include "parser/Parser.hpp" 9 | #include "parser/LanguageException.hpp" 10 | #include "statements/FunctionStatement.hpp" 11 | #include "utility/ThreadManager.hpp" 12 | #include 13 | #include 14 | 15 | namespace arrow { 16 | 17 | StringInputExpressionEvaluator::StringInputExpressionEvaluator(StringInputExpression expression) 18 | : m_expression(std::move(expression)) 19 | { 20 | } 21 | Type StringInputExpressionEvaluator::evaluate(Environment & environment) const 22 | { 23 | // Pull out the name of the function 24 | auto const callLineNumber = m_expression.getLineNumber(); 25 | 26 | // Pull out the arguments being passed into the function 27 | 28 | auto const expression = m_expression.getExpression(); 29 | auto const col = expression->getEvaluator()->evaluate(environment); 30 | auto const expressionCollEval = std::get>(col.m_variantType); 31 | if(expressionCollEval.empty()) { 32 | throw LanguageException("Expected argument", m_expression.getLineNumber()); 33 | } 34 | auto const t = expressionCollEval[0]; 35 | environment.getOutputStream()< 7 | #include 8 | 9 | namespace arrow { 10 | 11 | ToIntFunctionExpressionEvaluator::ToIntFunctionExpressionEvaluator(ToIntFunctionExpression expression) 12 | : m_expression(std::move(expression)) 13 | { 14 | } 15 | Type ToIntFunctionExpressionEvaluator::evaluate(Environment & environment) const 16 | { 17 | auto const expression = m_expression.getExpression(); 18 | auto const col = expression->getEvaluator()->evaluate(environment); 19 | auto const expressionCollEval = std::get>(col.m_variantType); 20 | if(expressionCollEval.empty()) { 21 | throw LanguageException("Expected argument", m_expression.getLineNumber()); 22 | } 23 | auto const eval = expressionCollEval[0]; 24 | if(eval.m_descriptor == TypeDescriptor::Int) { 25 | auto casted = std::get(eval.m_variantType); 26 | return {TypeDescriptor::Int, casted}; 27 | } else if(eval.m_descriptor == TypeDescriptor::Real) { 28 | auto casted = std::get(eval.m_variantType); 29 | auto val = static_cast(casted); 30 | return {TypeDescriptor::Int, val}; 31 | } else { 32 | throw LanguageException("Bad type for to_int", m_expression.getLineNumber()); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/ToIntFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2025 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/ToIntFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class ToIntFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit ToIntFunctionExpressionEvaluator(ToIntFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | ToIntFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/TokenizeFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/TokenizeFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class TokenizeFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit TokenizeFunctionExpressionEvaluator(TokenizeFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | TokenizeFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/TrimStringFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/TrimStringFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class TrimStringFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit TrimStringFunctionExpressionEvaluator(TrimStringFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | TrimStringFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/TypeExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/TypeExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class TypeExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit TypeExpressionEvaluator(TypeExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | TypeExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/WildcardEqExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/WildcardEqExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class WildcardEqExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit WildcardEqExpressionEvaluator(WildcardEqExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | WildcardEqExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/evaluator/WildcardMatch.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace arrow { 6 | // Not mine -- copied directly from 7 | // https://stackoverflow.com/questions/3300419/file-name-matching-with-wildcard 8 | inline bool wildcardMatch(char const *needle, char const *haystack) 9 | { 10 | for (; *needle != '\0'; ++needle) { 11 | switch (*needle) { 12 | case '?': 13 | if (*haystack == '\0') 14 | return false; 15 | ++haystack; 16 | break; 17 | case '*': { 18 | if (needle[1] == '\0') 19 | return true; 20 | size_t max = strlen(haystack); 21 | for (size_t i = 0; i < max; i++) 22 | if (wildcardMatch(needle + 1, haystack + i)) 23 | return true; 24 | return false; 25 | } 26 | default: 27 | if (*haystack != *needle) 28 | return false; 29 | ++haystack; 30 | } 31 | } 32 | return *haystack == '\0'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/builtin/filesystem/FileReadBytesFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "FileReadBytesFunctionExpression.hpp" 4 | #include "evaluator/FileReadBytesFunctionExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | FileReadBytesFunctionExpression::FileReadBytesFunctionExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr FileReadBytesFunctionExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void FileReadBytesFunctionExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr 23 | FileReadBytesFunctionExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string FileReadBytesFunctionExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FileReadBytesFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "builtin/BuiltInFunctionExpression.hpp" 6 | #include "builtin/BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class FileReadBytesFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | FileReadBytesFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class FileReadBytesFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "file"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FileReadLinesFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "FileReadLinesFunctionExpression.hpp" 4 | #include "evaluator/FileReadLinesFunctionExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | FileReadLinesFunctionExpression::FileReadLinesFunctionExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr FileReadLinesFunctionExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void FileReadLinesFunctionExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr 23 | FileReadLinesFunctionExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string FileReadLinesFunctionExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FileReadLinesFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "builtin/BuiltInFunctionExpression.hpp" 6 | #include "builtin/BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class FileReadLinesFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | FileReadLinesFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class FileReadLinesFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "file_read_lines"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FileReceiver.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "FileReceiver.hpp" 4 | #include "evaluator/FileReceiverEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | FileReceiver::FileReceiver(long const lineNumber) 9 | : Receiver(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr FileReceiver::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void FileReceiver::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr 23 | FileReceiver::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string FileReceiver::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FileReceiver.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "expressions/Expression.hpp" 6 | #include "receivers/Receiver.hpp" 7 | #include "receivers/evaluator/ReceiverEvaluator.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | class FileReceiver : public Receiver 14 | { 15 | public: 16 | FileReceiver(long const lineNumber); 17 | void setExpression(std::shared_ptr expression); 18 | std::shared_ptr getExpression() const; 19 | std::shared_ptr getEvaluator() const override; 20 | std::string toString() const override; 21 | private: 22 | std::shared_ptr m_expression; 23 | }; 24 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FolderListFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "FolderListFunctionExpression.hpp" 4 | #include "evaluator/FolderListFunctionExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | FolderListFunctionExpression::FolderListFunctionExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr FolderListFunctionExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void FolderListFunctionExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr 23 | FolderListFunctionExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string FolderListFunctionExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FolderListFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "builtin/BuiltInFunctionExpression.hpp" 6 | #include "builtin/BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class FolderListFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | FolderListFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class FolderListFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "folder_list"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FolderListRecursiveFunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "FolderListRecursiveFunctionExpression.hpp" 4 | #include "evaluator/FolderListRecursiveFunctionExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | FolderListRecursiveFunctionExpression::FolderListRecursiveFunctionExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr FolderListRecursiveFunctionExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void FolderListRecursiveFunctionExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr 23 | FolderListRecursiveFunctionExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string FolderListRecursiveFunctionExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/FolderListRecursiveFunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "builtin/BuiltInFunctionExpression.hpp" 6 | #include "builtin/BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class FolderListRecursiveFunctionExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | FolderListRecursiveFunctionExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class FolderListRecursiveFunctionExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "folder_list_r"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/evaluator/FileReadBytesFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/filesystem/FileReadBytesFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class FileReadBytesFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit FileReadBytesFunctionExpressionEvaluator(FileReadBytesFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | FileReadBytesFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/evaluator/FileReadLinesFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/filesystem/FileReadLinesFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class FileReadLinesFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit FileReadLinesFunctionExpressionEvaluator(FileReadLinesFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | FileReadLinesFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/evaluator/FileReceiverEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "receivers/evaluator/ReceiverEvaluator.hpp" 6 | #include "builtin/filesystem/FileReceiver.hpp" 7 | #include "representation/Environment.hpp" 8 | #include "representation/Type.hpp" 9 | 10 | namespace arrow { 11 | class FileReceiverEvaluator : public ReceiverEvaluator 12 | { 13 | public: 14 | explicit FileReceiverEvaluator(FileReceiver receiver); 15 | void evaluate(Type incoming, Environment & environment) const override; 16 | private: 17 | FileReceiver m_receiver; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/evaluator/FolderListFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/filesystem/FolderListFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class FolderListFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit FolderListFunctionExpressionEvaluator(FolderListFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | FolderListFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/builtin/filesystem/evaluator/FolderListRecursiveFunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "builtin/filesystem/FolderListRecursiveFunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class FolderListRecursiveFunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit FolderListRecursiveFunctionExpressionEvaluator(FolderListRecursiveFunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | FolderListRecursiveFunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/expressions/BooleanExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "BooleanExpression.hpp" 4 | #include "evaluator/BooleanExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | BooleanExpression::BooleanExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | , m_operatorExp(std::make_shared(lineNumber)) 11 | { 12 | } 13 | 14 | std::shared_ptr BooleanExpression::getEvaluator() const 15 | { 16 | return std::make_shared(*this); 17 | } 18 | 19 | BooleanExpression & 20 | BooleanExpression::withLeft(std::shared_ptr expressionLeft) 21 | { 22 | m_operatorExp->withLeft(std::move(expressionLeft)); 23 | return *this; 24 | } 25 | BooleanExpression & 26 | BooleanExpression::withRight(std::shared_ptr expressionRight) 27 | { 28 | m_operatorExp->withRight(std::move(expressionRight)); 29 | return *this; 30 | } 31 | BooleanExpression & BooleanExpression::withOperator(Token op) 32 | { 33 | m_operatorExp->withOperator(std::move(op)); 34 | return *this; 35 | } 36 | std::shared_ptr const & BooleanExpression::getExpressionLeft() const 37 | { 38 | return m_operatorExp->getExpressionLeft(); 39 | } 40 | std::shared_ptr const & BooleanExpression::getExpressionRight() const 41 | { 42 | return m_operatorExp->getExpressionRight(); 43 | } 44 | Token const & BooleanExpression::getOperator() const 45 | { 46 | return m_operatorExp->getOperator(); 47 | } 48 | std::string BooleanExpression::toString() const 49 | { 50 | return m_operatorExp->toString(); 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /src/expressions/BooleanExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "OperatorExpression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | 12 | class BooleanExpression : public Expression 13 | { 14 | public: 15 | BooleanExpression(long const lineNumber); 16 | 17 | std::shared_ptr getEvaluator() const override; 18 | BooleanExpression & withLeft(std::shared_ptr expressionLeft); 19 | BooleanExpression & withRight(std::shared_ptr expressionRight); 20 | BooleanExpression & withOperator(Token op); 21 | std::shared_ptr const & getExpressionLeft() const; 22 | std::shared_ptr const & getExpressionRight() const; 23 | Token const & getOperator() const; 24 | std::string toString() const override; 25 | 26 | private: 27 | std::shared_ptr m_operatorExp; 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /src/expressions/BracedExpressionCollectionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | 11 | /// For storing a set of expressions, e.g. 12 | /// {a, b, c} 13 | class BracedExpressionCollectionExpression : public Expression 14 | { 15 | public: 16 | BracedExpressionCollectionExpression(long const lineNumber); 17 | 18 | std::shared_ptr getEvaluator() const override; 19 | void addExpression(std::shared_ptr expression); 20 | std::vector> const & getExpressionCollection() const; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | std::vector> m_expressions; 26 | }; 27 | 28 | } -------------------------------------------------------------------------------- /src/expressions/DoubleEqualExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "DoubleEqualExpression.hpp" 4 | #include "evaluator/ExpressionEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | DoubleEqualExpression::DoubleEqualExpression(long const lineNumber) 10 | : Expression(lineNumber) 11 | , m_token() 12 | { 13 | } 14 | 15 | std::shared_ptr DoubleEqualExpression::getEvaluator() const 16 | { 17 | struct DoubleEqualEvaluator : public ExpressionEvaluator 18 | { 19 | Type evaluate(Environment & environment) const override 20 | { 21 | return {TypeDescriptor::DoubleEqual, std::string("==")}; 22 | } 23 | }; 24 | return std::make_shared(); 25 | } 26 | 27 | DoubleEqualExpression & DoubleEqualExpression::withToken(Token token) 28 | { 29 | m_token = std::move(token); 30 | return *this; 31 | } 32 | 33 | std::string DoubleEqualExpression::toString() const 34 | { 35 | return ""; // TODO 36 | } 37 | } -------------------------------------------------------------------------------- /src/expressions/DoubleEqualExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | 10 | namespace arrow { 11 | class DoubleEqualExpression : public Expression 12 | { 13 | public: 14 | DoubleEqualExpression(long const lineNumber); 15 | std::shared_ptr getEvaluator() const override; 16 | DoubleEqualExpression & withToken(Token token); 17 | std::string toString() const override; 18 | 19 | private: 20 | Token m_token; 21 | }; 22 | } -------------------------------------------------------------------------------- /src/expressions/Expression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "Expression.hpp" 4 | #include "parser/LanguageException.hpp" 5 | 6 | namespace arrow { 7 | Expression::Expression(long const lineNumber) 8 | : Node() 9 | , m_lineNumber(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr Expression::getEvaluator() const 14 | { 15 | throw LanguageException("Cannot evaluate expression", m_lineNumber); 16 | } 17 | 18 | long Expression::getLineNumber() const 19 | { 20 | return m_lineNumber; 21 | } 22 | 23 | char const * Expression::getTypeString() const 24 | { 25 | return ""; 26 | } 27 | } -------------------------------------------------------------------------------- /src/expressions/Expression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "parser/Node.hpp" 6 | #include "representation/Type.hpp" 7 | #include 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class ExpressionEvaluator; 13 | 14 | class Expression : public Node 15 | { 16 | public: 17 | Expression(long const lineNumber); 18 | 19 | /// Returns an Evaluator that can be used to evaluate this 20 | virtual std::shared_ptr getEvaluator() const; 21 | 22 | /// For debugging purposes 23 | virtual std::string toString() const = 0; 24 | 25 | // A plain char string indicating the 'type of this' 26 | virtual char const * getTypeString() const; 27 | 28 | long getLineNumber() const; 29 | 30 | protected: 31 | long m_lineNumber; 32 | }; 33 | } -------------------------------------------------------------------------------- /src/expressions/ExpressionCollectionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | 11 | /// For storing a set of expressions, e.g. 12 | /// (a, b, c) 13 | class ExpressionCollectionExpression : public Expression 14 | { 15 | public: 16 | ExpressionCollectionExpression(long const lineNumber); 17 | 18 | std::shared_ptr getEvaluator() const override; 19 | 20 | void addExpression(std::shared_ptr expression); 21 | std::vector> const & getExpressionCollection() const; 22 | 23 | std::string toString() const override; 24 | 25 | private: 26 | std::vector> m_expressions; 27 | }; 28 | 29 | } -------------------------------------------------------------------------------- /src/expressions/FunctionExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "FunctionExpression.hpp" 4 | #include "evaluator/FunctionExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | FunctionExpression::FunctionExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr FunctionExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | FunctionExpression & FunctionExpression::withFunctionNameToken(Token token) 19 | { 20 | m_nameToken = std::move(token); 21 | return *this; 22 | } 23 | FunctionExpression & 24 | FunctionExpression::withExpressionCollection(std::shared_ptr expression) 25 | { 26 | m_expressionCollection = std::move(expression); 27 | return *this; 28 | } 29 | std::shared_ptr const & 30 | FunctionExpression::getExpressionCollection() const 31 | { 32 | return m_expressionCollection; 33 | } 34 | 35 | Token const & FunctionExpression::getName() const 36 | { 37 | return m_nameToken; 38 | } 39 | 40 | std::string FunctionExpression::toString() const 41 | { 42 | return ""; // todo 43 | } 44 | } -------------------------------------------------------------------------------- /src/expressions/FunctionExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class FunctionExpression : public Expression 13 | { 14 | public: 15 | FunctionExpression(long const lineNumber); 16 | FunctionExpression & withFunctionNameToken(Token token); 17 | FunctionExpression & 18 | withExpressionCollection(std::shared_ptr expression); 19 | std::shared_ptr getEvaluator() const override; 20 | std::string toString() const override; 21 | std::shared_ptr const & getExpressionCollection() const; 22 | Token const & getName() const; 23 | private: 24 | Token m_nameToken; 25 | std::shared_ptr m_expressionCollection; 26 | }; 27 | 28 | } -------------------------------------------------------------------------------- /src/expressions/GroupedExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "GroupedExpression.hpp" 4 | 5 | namespace arrow { 6 | 7 | GroupedExpression::GroupedExpression(long const lineNumber) 8 | : Expression(lineNumber) 9 | , m_expression{nullptr} 10 | { 11 | } 12 | 13 | std::shared_ptr GroupedExpression::getEvaluator() const 14 | { 15 | return m_expression->getEvaluator(); 16 | } 17 | 18 | GroupedExpression & GroupedExpression::withExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | return *this; 22 | } 23 | 24 | std::shared_ptr const & GroupedExpression::getExpression() const 25 | { 26 | return m_expression; 27 | } 28 | std::string GroupedExpression::toString() const 29 | { 30 | std::string str("\nBegin grouped expression"); 31 | str.append(m_expression->toString()); 32 | str.append("\nEnd grouped expression"); 33 | return str; 34 | } 35 | } -------------------------------------------------------------------------------- /src/expressions/GroupedExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class GroupedExpression : public Expression 12 | { 13 | public: 14 | GroupedExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | GroupedExpression & withExpression(std::shared_ptr expression); 19 | 20 | std::shared_ptr const & getExpression() const; 21 | std::string toString() const override; 22 | 23 | private: 24 | std::shared_ptr m_expression; 25 | }; 26 | 27 | } -------------------------------------------------------------------------------- /src/expressions/HatHatStringExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | 10 | namespace arrow { 11 | class HatHatStringExpression : public Expression 12 | { 13 | public: 14 | HatHatStringExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | HatHatStringExpression & withHatHatStringToken(Token hatHatStringToken); 19 | 20 | Token const & getHatHatStringToken() const; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_hatHatStringToken; 26 | }; 27 | } -------------------------------------------------------------------------------- /src/expressions/HatStringExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | 10 | namespace arrow { 11 | class HatStringExpression : public Expression 12 | { 13 | public: 14 | HatStringExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | HatStringExpression & withHatStringToken(Token hatStringToken); 19 | 20 | Token const & getHatStringToken() const; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_hatStringToken; 26 | }; 27 | } -------------------------------------------------------------------------------- /src/expressions/IdentifierExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class IdentifierExpression : public Expression 12 | { 13 | public: 14 | IdentifierExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | IdentifierExpression & withIdentifierToken(Token identifier); 19 | 20 | Token const & getIdentifierToken() const; 21 | 22 | std::string toString() const override; 23 | 24 | char const * getTypeString() const override; 25 | 26 | private: 27 | Token m_identifier; 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /src/expressions/IndexExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | /// An expression of the form 12 | /// identifier:expression, e.g. a:1 13 | class IndexExpression : public Expression 14 | { 15 | public: 16 | IndexExpression(long const lineNumber); 17 | 18 | std::shared_ptr getEvaluator() const override; 19 | 20 | IndexExpression & withIdentifierToken(Token identifier); 21 | IndexExpression & withIndexExpression(std::shared_ptr identifier); 22 | 23 | Token const & getIdentifierToken() const; 24 | std::shared_ptr const & getIndexExpression() const; 25 | 26 | std::string toString() const override; 27 | 28 | char const * getTypeString() const override; 29 | 30 | private: 31 | Token m_identifier; 32 | std::shared_ptr m_indexExpression; 33 | }; 34 | 35 | } -------------------------------------------------------------------------------- /src/expressions/ListExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ListExpression.hpp" 4 | #include "evaluator/ListExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | ListExpression::ListExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | , m_parts{} 11 | { 12 | } 13 | 14 | std::shared_ptr ListExpression::getEvaluator() const 15 | { 16 | return std::make_shared(*this); 17 | } 18 | 19 | void ListExpression::addPart(std::shared_ptr expression) 20 | { 21 | m_parts.emplace_back(std::move(expression)); 22 | } 23 | 24 | int ListExpression::getPartsCount() const 25 | { 26 | return m_parts.size(); 27 | } 28 | 29 | std::vector> const & ListExpression::getParts() const 30 | { 31 | return m_parts; 32 | } 33 | 34 | std::string ListExpression::toString() const 35 | { 36 | std::string str("\nBegin list expression"); 37 | for(auto const & part : m_parts) { 38 | str.append("\n"); 39 | str.append(part->toString()); 40 | } 41 | str.append("\nEnd list expression"); 42 | return str; 43 | } 44 | } -------------------------------------------------------------------------------- /src/expressions/ListExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class ListExpression : public Expression 13 | { 14 | public: 15 | ListExpression(long const lineNumber); 16 | 17 | std::shared_ptr getEvaluator() const override; 18 | 19 | void addPart(std::shared_ptr expression); 20 | int getPartsCount() const; 21 | 22 | std::vector> const & getParts() const; 23 | 24 | std::string toString() const override; 25 | 26 | private: 27 | std::vector> m_parts; 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /src/expressions/ListWordExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ListWordExpression.hpp" 4 | #include "evaluator/ExpressionEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | ListWordExpression::ListWordExpression(long const lineNumber) 10 | : Expression(lineNumber) 11 | , m_word() 12 | { 13 | } 14 | 15 | std::shared_ptr 16 | ListWordExpression::getEvaluator() const 17 | { 18 | struct ListWordEvaluator : public ExpressionEvaluator { 19 | ListWordEvaluator(Token tok) : m_tok(std::move(tok)) 20 | { 21 | } 22 | 23 | Type evaluate(Environment & environment) const override 24 | { 25 | return {TypeDescriptor::ListWord, m_tok.raw}; 26 | } 27 | private: 28 | Token m_tok; 29 | }; 30 | return std::make_shared(m_word); 31 | } 32 | 33 | ListWordExpression & ListWordExpression::withWordToken(Token word) 34 | { 35 | m_word = std::move(word); 36 | return *this; 37 | } 38 | 39 | Token const & ListWordExpression::getWordToken() const 40 | { 41 | return m_word; 42 | } 43 | 44 | std::string ListWordExpression::toString() const 45 | { 46 | std::string str("\nList word expression: "); 47 | return str.append(m_word.raw); 48 | } 49 | } -------------------------------------------------------------------------------- /src/expressions/ListWordExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class ListWordExpression : public Expression 12 | { 13 | public: 14 | ListWordExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | ListWordExpression & withWordToken(Token identifier); 19 | 20 | Token const & getWordToken() const; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_word; 26 | }; 27 | 28 | } -------------------------------------------------------------------------------- /src/expressions/LiteralCharExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "LiteralCharExpression.hpp" 4 | #include "evaluator/ExpressionEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | LiteralCharExpression::LiteralCharExpression(long const lineNumber) 10 | : Expression(lineNumber) 11 | , m_stringToken() 12 | { 13 | } 14 | 15 | std::shared_ptr LiteralCharExpression::getEvaluator() const 16 | { 17 | struct LiteralCharEvaluator : public ExpressionEvaluator { 18 | LiteralCharEvaluator(Token tok) : m_tok(std::move(tok)) 19 | { 20 | } 21 | 22 | Type evaluate(Environment &) const override 23 | { 24 | return {TypeDescriptor::Byte, m_tok.raw[0]}; 25 | } 26 | private: 27 | Token m_tok; 28 | }; 29 | return std::make_shared(m_stringToken); 30 | } 31 | 32 | LiteralCharExpression & LiteralCharExpression::withStringToken(Token stringToken) 33 | { 34 | m_stringToken = std::move(stringToken); 35 | return *this; 36 | } 37 | 38 | Token const & LiteralCharExpression::getStringToken() const 39 | { 40 | return m_stringToken; 41 | } 42 | 43 | std::string LiteralCharExpression::toString() const 44 | { 45 | std::string str("\nLiteral char expression: "); 46 | return str.append(m_stringToken.raw); 47 | } 48 | } -------------------------------------------------------------------------------- /src/expressions/LiteralCharExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class LiteralCharExpression : public Expression 12 | { 13 | public: 14 | LiteralCharExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | LiteralCharExpression & withStringToken(Token stringToken); 19 | 20 | Token const & getStringToken() const; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_stringToken; 26 | }; 27 | 28 | } -------------------------------------------------------------------------------- /src/expressions/LiteralIntExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "LiteralIntExpression.hpp" 4 | #include "evaluator/ExpressionEvaluator.hpp" 5 | #include "utility/from_string.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | LiteralIntExpression::LiteralIntExpression(long const lineNumber) 11 | : Expression(lineNumber) 12 | , m_intToken() 13 | { 14 | } 15 | 16 | std::shared_ptr LiteralIntExpression::getEvaluator() const 17 | { 18 | struct IntEvaluator : public ExpressionEvaluator { 19 | IntEvaluator(Token tok) : m_tok(std::move(tok)) 20 | { 21 | } 22 | 23 | Type evaluate(Environment &) const override 24 | { 25 | return {TypeDescriptor::Int, {from_string(m_tok.raw)}}; 26 | } 27 | private: 28 | Token m_tok; 29 | }; 30 | return std::make_shared(m_intToken); 31 | } 32 | 33 | LiteralIntExpression & LiteralIntExpression::withIntToken(Token intToken) 34 | { 35 | m_intToken = std::move(intToken); 36 | return *this; 37 | } 38 | 39 | Token const & LiteralIntExpression::getIntToken() const 40 | { 41 | return m_intToken; 42 | } 43 | 44 | std::string LiteralIntExpression::toString() const 45 | { 46 | std::string str("\nLiteral int expression: "); 47 | return str.append(m_intToken.raw); 48 | } 49 | } -------------------------------------------------------------------------------- /src/expressions/LiteralIntExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class LiteralIntExpression : public Expression 12 | { 13 | public: 14 | LiteralIntExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | LiteralIntExpression & withIntToken(Token intToken); 19 | 20 | Token const & getIntToken() const; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_intToken; 26 | }; 27 | 28 | } -------------------------------------------------------------------------------- /src/expressions/LiteralRealExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "LiteralRealExpression.hpp" 4 | #include "evaluator/ExpressionEvaluator.hpp" 5 | #include "utility/from_string.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | LiteralRealExpression::LiteralRealExpression(long const lineNumber) 11 | : Expression(lineNumber) 12 | , m_realToken() 13 | { 14 | } 15 | 16 | std::shared_ptr LiteralRealExpression::getEvaluator() const 17 | { 18 | struct RealEvaluator : public ExpressionEvaluator { 19 | RealEvaluator(Token tok) : m_tok(std::move(tok)) 20 | { 21 | } 22 | 23 | Type evaluate(Environment &) const override 24 | { 25 | return {TypeDescriptor::Real, {from_string(m_tok.raw)}}; 26 | } 27 | private: 28 | Token m_tok; 29 | }; 30 | return std::make_shared(m_realToken); 31 | } 32 | 33 | LiteralRealExpression & LiteralRealExpression::withRealToken(Token realToken) 34 | { 35 | m_realToken = std::move(realToken); 36 | return *this; 37 | } 38 | 39 | Token const & LiteralRealExpression::getRealToken() const 40 | { 41 | return m_realToken; 42 | } 43 | 44 | std::string LiteralRealExpression::toString() const 45 | { 46 | std::string str("\nLiteral real expression: "); 47 | return str.append(m_realToken.raw); 48 | } 49 | } -------------------------------------------------------------------------------- /src/expressions/LiteralRealExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class LiteralRealExpression : public Expression 13 | { 14 | public: 15 | LiteralRealExpression(long const lineNumber); 16 | 17 | std::shared_ptr getEvaluator() const override; 18 | 19 | LiteralRealExpression & withRealToken(Token realToken); 20 | 21 | Token const & getRealToken() const; 22 | 23 | std::string toString() const override; 24 | 25 | private: 26 | Token m_realToken; 27 | }; 28 | 29 | } -------------------------------------------------------------------------------- /src/expressions/LiteralStringExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "LiteralStringExpression.hpp" 4 | #include "evaluator/ExpressionEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | LiteralStringExpression::LiteralStringExpression(long const lineNumber) 10 | : Expression(lineNumber) 11 | , m_stringToken() 12 | { 13 | } 14 | 15 | std::shared_ptr LiteralStringExpression::getEvaluator() const 16 | { 17 | struct StringEvaluator : public ExpressionEvaluator { 18 | StringEvaluator(Token tok) : m_tok(std::move(tok)) 19 | { 20 | } 21 | 22 | Type evaluate(Environment &) const override 23 | { 24 | return {TypeDescriptor::String, m_tok.raw}; 25 | } 26 | private: 27 | Token m_tok; 28 | }; 29 | return std::make_shared(m_stringToken); 30 | } 31 | 32 | LiteralStringExpression & LiteralStringExpression::withStringToken(Token stringToken) 33 | { 34 | m_stringToken = std::move(stringToken); 35 | return *this; 36 | } 37 | 38 | Token const & LiteralStringExpression::getStringToken() const 39 | { 40 | return m_stringToken; 41 | } 42 | 43 | std::string LiteralStringExpression::toString() const 44 | { 45 | std::string str("\nLiteral string expression: "); 46 | return str.append(m_stringToken.raw); 47 | } 48 | } -------------------------------------------------------------------------------- /src/expressions/LiteralStringExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class LiteralStringExpression : public Expression 12 | { 13 | public: 14 | LiteralStringExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | LiteralStringExpression & withStringToken(Token stringToken); 19 | 20 | Token const & getStringToken() const; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_stringToken; 26 | }; 27 | 28 | } -------------------------------------------------------------------------------- /src/expressions/MatchesExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "MatchesExpression.hpp" 4 | #include "evaluator/MatchesExpressionEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | MatchesExpression::MatchesExpression(long const lineNumber) 10 | : Expression(lineNumber) 11 | { 12 | } 13 | std::shared_ptr MatchesExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | MatchesExpression & MatchesExpression::withLeftExpression(std::shared_ptr expression) 18 | { 19 | m_left = std::move(expression); 20 | return *this; 21 | } 22 | MatchesExpression & MatchesExpression::withRightExpression(std::shared_ptr expression) 23 | { 24 | m_right = std::move(expression); 25 | return *this; 26 | } 27 | std::shared_ptr const & MatchesExpression::getLeftExpression() const 28 | { 29 | return m_left; 30 | } 31 | std::shared_ptr const & MatchesExpression::getRightExpression() const 32 | { 33 | return m_right; 34 | } 35 | std::string MatchesExpression::toString() const 36 | { 37 | return ""; //todo 38 | } 39 | } -------------------------------------------------------------------------------- /src/expressions/MatchesExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class MatchesExpression : public Expression 13 | { 14 | public: 15 | MatchesExpression(long const lineNumber); 16 | 17 | std::shared_ptr getEvaluator() const override; 18 | MatchesExpression & withLeftExpression(std::shared_ptr expression); 19 | MatchesExpression & withRightExpression(std::shared_ptr expression); 20 | std::shared_ptr const & getLeftExpression() const; 21 | std::shared_ptr const & getRightExpression() const; 22 | std::string toString() const override; 23 | 24 | private: 25 | std::shared_ptr m_left; 26 | std::shared_ptr m_right; 27 | }; 28 | 29 | } -------------------------------------------------------------------------------- /src/expressions/MathExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "MathExpression.hpp" 4 | #include "evaluator/MathExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | MathExpression::MathExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | , m_operatorExp(std::make_shared(lineNumber)) 11 | { 12 | } 13 | 14 | std::shared_ptr MathExpression::getEvaluator() const 15 | { 16 | return std::make_shared(*this); 17 | } 18 | 19 | MathExpression & MathExpression::withLeft(std::shared_ptr expressionLeft) 20 | { 21 | m_operatorExp->withLeft(std::move(expressionLeft)); 22 | return *this; 23 | } 24 | MathExpression & MathExpression::withRight(std::shared_ptr expressionRight) 25 | { 26 | m_operatorExp->withRight(std::move(expressionRight)); 27 | return *this; 28 | } 29 | MathExpression & MathExpression::withOperator(Token op) 30 | { 31 | m_operatorExp->withOperator(std::move(op)); 32 | return *this; 33 | } 34 | std::shared_ptr const & MathExpression::getExpressionLeft() const 35 | { 36 | return m_operatorExp->getExpressionLeft(); 37 | } 38 | std::shared_ptr const & MathExpression::getExpressionRight() const 39 | { 40 | return m_operatorExp->getExpressionRight(); 41 | } 42 | Token const & MathExpression::getOperator() const 43 | { 44 | return m_operatorExp->getOperator(); 45 | } 46 | std::string MathExpression::toString() const 47 | { 48 | return m_operatorExp->toString(); 49 | } 50 | } -------------------------------------------------------------------------------- /src/expressions/MathExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "OperatorExpression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class MathExpression : public Expression 12 | { 13 | public: 14 | MathExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | MathExpression & withLeft(std::shared_ptr expressionLeft); 19 | MathExpression & withRight(std::shared_ptr expressionRight); 20 | MathExpression & withOperator(Token op); 21 | std::shared_ptr const & getExpressionLeft() const; 22 | std::shared_ptr const & getExpressionRight() const; 23 | Token const & getOperator() const; 24 | std::string toString() const override; 25 | 26 | private: 27 | std::shared_ptr m_operatorExp; 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /src/expressions/NegativeNumberExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "NegativeNumberExpression.hpp" 4 | #include "evaluator/NegativeNumberEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | NegativeNumberExpression::NegativeNumberExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | , m_expression{nullptr} 11 | { 12 | } 13 | 14 | std::shared_ptr NegativeNumberExpression::getEvaluator() const 15 | { 16 | return std::make_shared(m_expression->getEvaluator(), m_lineNumber); 17 | } 18 | 19 | NegativeNumberExpression & NegativeNumberExpression::withExpression(std::shared_ptr expression) 20 | { 21 | m_expression = std::move(expression); 22 | return *this; 23 | } 24 | 25 | std::shared_ptr const & NegativeNumberExpression::getExpression() const 26 | { 27 | return m_expression; 28 | } 29 | std::string NegativeNumberExpression::toString() const 30 | { 31 | return ""; // TODO 32 | } 33 | } -------------------------------------------------------------------------------- /src/expressions/NegativeNumberExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class NegativeNumberExpression : public Expression 12 | { 13 | public: 14 | NegativeNumberExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | NegativeNumberExpression & withExpression(std::shared_ptr expression); 19 | 20 | std::shared_ptr const & getExpression() const; 21 | std::string toString() const override; 22 | 23 | private: 24 | std::shared_ptr m_expression; 25 | }; 26 | 27 | } -------------------------------------------------------------------------------- /src/expressions/OperatorExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "OperatorExpression.hpp" 4 | 5 | namespace arrow { 6 | 7 | OperatorExpression::OperatorExpression(long const lineNumber) 8 | : Expression(lineNumber) 9 | , m_expressionLeft{nullptr} 10 | , m_op() 11 | , m_expressionRight{nullptr} 12 | { 13 | } 14 | 15 | OperatorExpression & OperatorExpression::withLeft(std::shared_ptr expressionLeft) 16 | { 17 | m_expressionLeft = std::move(expressionLeft); 18 | return *this; 19 | } 20 | OperatorExpression & OperatorExpression::withRight(std::shared_ptr expressionRight) 21 | { 22 | m_expressionRight = std::move(expressionRight); 23 | return *this; 24 | } 25 | OperatorExpression & OperatorExpression::withOperator(Token op) 26 | { 27 | m_op = std::move(op); 28 | return *this; 29 | } 30 | std::shared_ptr const & OperatorExpression::getExpressionLeft() const 31 | { 32 | return m_expressionLeft; 33 | } 34 | std::shared_ptr const & OperatorExpression::getExpressionRight() const 35 | { 36 | return m_expressionRight; 37 | } 38 | Token const & OperatorExpression::getOperator() const 39 | { 40 | return m_op; 41 | } 42 | std::string OperatorExpression::toString() const 43 | { 44 | std::string str("\nBegin expression: "); 45 | str.append("\nLeft: "); 46 | str.append(m_expressionLeft->toString()); 47 | str.append("\nOperator: "); 48 | str.append(m_op.raw); 49 | str.append("\nRight: "); 50 | str.append(m_expressionRight->toString()); 51 | str.append("\nEnd expression"); 52 | return str; 53 | } 54 | } -------------------------------------------------------------------------------- /src/expressions/OperatorExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class OperatorExpression : public Expression 12 | { 13 | public: 14 | OperatorExpression(long const lineNumber); 15 | 16 | OperatorExpression & withLeft(std::shared_ptr expressionLeft); 17 | OperatorExpression & withRight(std::shared_ptr expressionRight); 18 | OperatorExpression & withOperator(Token op); 19 | std::shared_ptr const & getExpressionLeft() const; 20 | std::shared_ptr const & getExpressionRight() const; 21 | Token const & getOperator() const; 22 | std::string toString() const override; 23 | 24 | private: 25 | std::shared_ptr m_expressionLeft; 26 | Token m_op; 27 | std::shared_ptr m_expressionRight; 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /src/expressions/QQStringExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "QQStringExpression.hpp" 4 | #include 5 | 6 | namespace arrow { 7 | 8 | QQStringExpression::QQStringExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | , m_qQStringToken() 11 | { 12 | } 13 | 14 | QQStringExpression & QQStringExpression::withQQStringToken(Token qQStringToken) 15 | { 16 | m_qQStringToken = std::move(qQStringToken); 17 | return *this; 18 | } 19 | 20 | Token const & QQStringExpression::getQQStringToken() const 21 | { 22 | return m_qQStringToken; 23 | } 24 | 25 | std::shared_ptr 26 | QQStringExpression::getEvaluator() const 27 | { 28 | struct QQStringExpressionEvaluator : public ExpressionEvaluator 29 | { 30 | QQStringExpressionEvaluator(QQStringExpression expression) 31 | : m_expression(std::move(expression)) 32 | { 33 | } 34 | 35 | Type evaluate(Environment &) const override 36 | { 37 | auto const token = m_expression.getQQStringToken(); 38 | return {TypeDescriptor::QQString, token.raw}; 39 | } 40 | 41 | private: 42 | QQStringExpression m_expression; 43 | }; 44 | return std::make_shared(*this); 45 | } 46 | 47 | std::string QQStringExpression::toString() const 48 | { 49 | std::string str("\n?? string expression: "); 50 | return str.append(m_qQStringToken.raw); 51 | } 52 | } -------------------------------------------------------------------------------- /src/expressions/QQStringExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "evaluator/ExpressionEvaluator.hpp" 7 | #include "lexer/Token.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class QQStringExpression : public Expression 12 | { 13 | public: 14 | QQStringExpression(long const lineNumber); 15 | 16 | QQStringExpression & withQQStringToken(Token qQStringToken); 17 | 18 | Token const & getQQStringToken() const; 19 | 20 | std::shared_ptr getEvaluator() const override; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_qQStringToken; 26 | }; 27 | } -------------------------------------------------------------------------------- /src/expressions/QStringExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "QStringExpression.hpp" 4 | #include 5 | 6 | namespace arrow { 7 | 8 | QStringExpression::QStringExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | , m_qStringToken() 11 | { 12 | } 13 | 14 | QStringExpression & QStringExpression::withQStringToken(Token qStringToken) 15 | { 16 | m_qStringToken = std::move(qStringToken); 17 | return *this; 18 | } 19 | 20 | Token const & QStringExpression::getQStringToken() const 21 | { 22 | return m_qStringToken; 23 | } 24 | 25 | std::shared_ptr 26 | QStringExpression::getEvaluator() const 27 | { 28 | struct QStringExpressionEvaluator : public ExpressionEvaluator 29 | { 30 | QStringExpressionEvaluator(QStringExpression expression) 31 | : m_expression(std::move(expression)) 32 | { 33 | } 34 | 35 | Type evaluate(Environment &) const override 36 | { 37 | auto const token = m_expression.getQStringToken(); 38 | return {TypeDescriptor::QString, token.raw}; 39 | } 40 | 41 | private: 42 | QStringExpression m_expression; 43 | }; 44 | return std::make_shared(*this); 45 | } 46 | 47 | std::string QStringExpression::toString() const 48 | { 49 | std::string str("\n? string expression: "); 50 | return str.append(m_qStringToken.raw); 51 | } 52 | } -------------------------------------------------------------------------------- /src/expressions/QStringExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "evaluator/ExpressionEvaluator.hpp" 7 | #include "lexer/Token.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class QStringExpression : public Expression 12 | { 13 | public: 14 | QStringExpression(long const lineNumber); 15 | 16 | QStringExpression & withQStringToken(Token qStringToken); 17 | 18 | Token const & getQStringToken() const; 19 | 20 | std::shared_ptr getEvaluator() const override; 21 | 22 | std::string toString() const override; 23 | 24 | private: 25 | Token m_qStringToken; 26 | }; 27 | } -------------------------------------------------------------------------------- /src/expressions/SingleEqualExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "SingleEqualExpression.hpp" 4 | #include "evaluator/ExpressionEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | SingleEqualExpression::SingleEqualExpression(long const lineNumber) 10 | : Expression(lineNumber) 11 | , m_token() 12 | { 13 | } 14 | 15 | std::shared_ptr SingleEqualExpression::getEvaluator() const 16 | { 17 | struct SingleEqualEvaluator : public ExpressionEvaluator 18 | { 19 | Type evaluate(Environment & environment) const override 20 | { 21 | return {TypeDescriptor::SingleEqual, std::string("=")}; 22 | } 23 | }; 24 | return std::make_shared(); 25 | } 26 | 27 | SingleEqualExpression & SingleEqualExpression::withToken(Token token) 28 | { 29 | m_token = std::move(token); 30 | return *this; 31 | } 32 | 33 | std::string SingleEqualExpression::toString() const 34 | { 35 | return ""; // TODO 36 | } 37 | } -------------------------------------------------------------------------------- /src/expressions/SingleEqualExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Expression.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | 10 | namespace arrow { 11 | class SingleEqualExpression : public Expression 12 | { 13 | public: 14 | SingleEqualExpression(long const lineNumber); 15 | 16 | std::shared_ptr getEvaluator() const override; 17 | 18 | SingleEqualExpression & withToken(Token token); 19 | 20 | std::string toString() const override; 21 | 22 | private: 23 | Token m_token; 24 | }; 25 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/BooleanExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ExpressionEvaluator.hpp" 6 | #include "expressions/BooleanExpression.hpp" 7 | #include "representation/Type.hpp" 8 | 9 | namespace arrow { 10 | 11 | class BooleanExpressionEvaluator : public ExpressionEvaluator 12 | { 13 | public: 14 | BooleanExpressionEvaluator(BooleanExpression expression); 15 | Type evaluate(Environment&) const override; 16 | private: 17 | BooleanExpression m_expression; 18 | }; 19 | 20 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/ExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "representation/Type.hpp" 6 | #include "representation/Environment.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | class ExpressionEvaluator 11 | { 12 | public: 13 | virtual Type evaluate(Environment&) const = 0; 14 | }; 15 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/FunctionExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ExpressionEvaluator.hpp" 6 | #include "expressions/FunctionExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class FunctionExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit FunctionExpressionEvaluator(FunctionExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | FunctionExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/IdentifierEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "IdentifierEvaluator.hpp" 4 | #include "parser/LanguageException.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | IdentifierEvaluator::IdentifierEvaluator(Token tok) 10 | : m_tok(std::move(tok)) 11 | { 12 | } 13 | 14 | Type IdentifierEvaluator::evaluate(Environment & environment) const 15 | { 16 | auto const & environmentKey = m_tok.raw; 17 | if(!environment.has(environmentKey)) { 18 | throw LanguageException("Identifier not found", 19 | m_tok.lineNumber); 20 | } 21 | return environment.get(environmentKey); 22 | } 23 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/IdentifierEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ExpressionEvaluator.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | 11 | struct IdentifierEvaluator : public ExpressionEvaluator { 12 | IdentifierEvaluator(Token tok); 13 | Type evaluate(Environment & environment) const override; 14 | private: 15 | Token m_tok; 16 | }; 17 | 18 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/ListExpressionEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "ListExpressionEvaluator.hpp" 4 | #include "expressions/ListExpression.hpp" 5 | #include 6 | #include 7 | 8 | namespace arrow { 9 | ListExpressionEvaluator::ListExpressionEvaluator(ListExpression listExpression) 10 | : m_listExpression(std::move(listExpression)) 11 | { 12 | } 13 | Type ListExpressionEvaluator::evaluate(Environment & environment) const 14 | { 15 | std::vector elements; 16 | auto const & parts = m_listExpression.getParts(); 17 | for(auto const & part : parts) { 18 | auto const evaluated = part->getEvaluator()->evaluate(environment); 19 | if(evaluated.m_descriptor == TypeDescriptor::BracketlessList) { 20 | auto & innerParts = std::get>(evaluated.m_variantType); 21 | for(auto const & inner : innerParts) { 22 | elements.push_back(inner); 23 | } 24 | } else { 25 | elements.push_back(evaluated); 26 | } 27 | } 28 | return {TypeDescriptor::List, std::move(elements)}; 29 | } 30 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/ListExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ExpressionEvaluator.hpp" 6 | #include "expressions/ListExpression.hpp" 7 | #include "representation/Type.hpp" 8 | #include "representation/Environment.hpp" 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class ListExpressionEvaluator : public ExpressionEvaluator 14 | { 15 | public: 16 | explicit ListExpressionEvaluator(ListExpression listExpression); 17 | Type evaluate(Environment&) const override; 18 | private: 19 | ListExpression m_listExpression; 20 | }; 21 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/MatchesExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ExpressionEvaluator.hpp" 6 | #include "expressions/MatchesExpression.hpp" 7 | #include "representation/Type.hpp" 8 | #include "representation/Environment.hpp" 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class MatchesExpressionEvaluator : public ExpressionEvaluator 14 | { 15 | public: 16 | explicit MatchesExpressionEvaluator(MatchesExpression expression); 17 | Type evaluate(Environment&) const override; 18 | private: 19 | MatchesExpression m_expression; 20 | }; 21 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/MathExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ExpressionEvaluator.hpp" 6 | #include "expressions/MathExpression.hpp" 7 | #include "representation/Type.hpp" 8 | 9 | namespace arrow { 10 | 11 | class MathExpressionEvaluator : public ExpressionEvaluator 12 | { 13 | public: 14 | MathExpressionEvaluator(MathExpression expression); 15 | Type evaluate(Environment & environment) const override; 16 | private: 17 | MathExpression m_expression; 18 | }; 19 | 20 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/NegativeNumberEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "NegativeNumberEvaluator.hpp" 4 | #include "parser/LanguageException.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | NegativeNumberEvaluator::NegativeNumberEvaluator(std::shared_ptr innerEvaluator, 10 | long const lineNumber) 11 | : m_innerEvaluator(std::move(innerEvaluator)) 12 | , m_lineNumber(lineNumber) 13 | { 14 | } 15 | 16 | Type NegativeNumberEvaluator::evaluate(Environment & environment) const 17 | { 18 | 19 | auto evaluated = m_innerEvaluator->evaluate(environment); 20 | if(evaluated.m_descriptor == TypeDescriptor::Real) { 21 | auto const val = -(std::get(evaluated.m_variantType)); 22 | return {TypeDescriptor::Real, val}; 23 | } 24 | if(evaluated.m_descriptor == TypeDescriptor::Int) { 25 | auto const val = -(std::get(evaluated.m_variantType)); 26 | return {TypeDescriptor::Int, val}; 27 | } 28 | throw LanguageException("Bad type ", m_lineNumber); 29 | } 30 | } -------------------------------------------------------------------------------- /src/expressions/evaluator/NegativeNumberEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "ExpressionEvaluator.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | 11 | struct NegativeNumberEvaluator : public ExpressionEvaluator { 12 | NegativeNumberEvaluator(std::shared_ptr innerEvaluator, 13 | long const lineNumber); 14 | Type evaluate(Environment & environment) const override; 15 | private: 16 | std::shared_ptr m_innerEvaluator; 17 | long m_lineNumber; 18 | }; 19 | 20 | } -------------------------------------------------------------------------------- /src/heavy/HTTPReadExpression.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "HTTPReadExpression.hpp" 4 | #include "evaluator/HTTPReadExpressionEvaluator.hpp" 5 | 6 | namespace arrow { 7 | 8 | HTTPReadExpression::HTTPReadExpression(long const lineNumber) 9 | : Expression(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr HTTPReadExpression::getEvaluator() const 14 | { 15 | return std::make_shared(*this); 16 | } 17 | 18 | void HTTPReadExpression::setExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | } 22 | std::shared_ptr 23 | HTTPReadExpression::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | 28 | std::string HTTPReadExpression::toString() const 29 | { 30 | return ""; // todo 31 | } 32 | } -------------------------------------------------------------------------------- /src/heavy/HTTPReadExpression.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "builtin/BuiltInFunctionExpression.hpp" 6 | #include "builtin/BuiltInFunctionExpressionBuilder.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | class HTTPReadExpression : public Expression, public BuiltInFunctionExpression 15 | { 16 | public: 17 | HTTPReadExpression(long const lineNumber); 18 | void setExpression(std::shared_ptr expression) override; 19 | std::shared_ptr getExpression() const; 20 | std::shared_ptr getEvaluator() const override; 21 | std::string toString() const override; 22 | private: 23 | std::shared_ptr m_expression; 24 | }; 25 | 26 | class HTTPReadExpressionBuilder : public BuiltInFunctionExpressionBuilder 27 | { 28 | public: 29 | std::string getName() const override { 30 | return "http_read"; 31 | } 32 | std::shared_ptr build(long const ln) const override { 33 | return std::make_shared(ln); 34 | } 35 | }; 36 | } -------------------------------------------------------------------------------- /src/heavy/evaluator/HTTPReadExpressionEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 6 | #include "heavy/HTTPReadExpression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | class HTTPReadExpressionEvaluator : public ExpressionEvaluator 11 | { 12 | public: 13 | explicit HTTPReadExpressionEvaluator(HTTPReadExpression expression); 14 | Type evaluate(Environment&) const override; 15 | private: 16 | HTTPReadExpression m_expression; 17 | }; 18 | } -------------------------------------------------------------------------------- /src/lexer/Lexeme.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace arrow { 8 | enum class Lexeme { 9 | // Single char 10 | PLUS, MINUS, STAR, EQUAL, DIVIDE, 11 | COLON, SEMICOLON, OPEN_PAREN, CLOSE_PAREN, 12 | OPEN_SQUARE, CLOSE_SQUARE, OPEN_CURLY, CLOSE_CURLY, 13 | GREATER, LESS, COMMA, PERCENT, XOR, DOLLAR, 14 | 15 | // Double or tipple char lexemes 16 | NOT_EQUAL, GREATER_EQUAL, LESS_EQUAL, ARROW, COMMENT, 17 | EQUAL_EQUAL, AND, OR, NIL, 18 | 19 | // Literals 20 | GENERIC_STRING, LITERAL_STRING, INTEGER_NUM, REAL_NUM, 21 | HAT_STRING, HAT_HAT_STRING, Q_STRING, Q_Q_STRING, 22 | LITERAL_CHAR, 23 | 24 | // Keywords 25 | FOR, EACH, REPEAT, TIMES, IF, START, FN, BOOL, 26 | INTEGER, REAL, STRING, IN, LIST, TRUE, FALSE, 27 | SAY, PR, PRN, INPUT, WHILE, PUT, ELSE, CALL 28 | 29 | // Built-ins 30 | }; 31 | 32 | bool isOperator(Lexeme const lexeme); 33 | bool isBooleanOperator(Lexeme const lexeme); 34 | bool isMathOperator(Lexeme const lexeme); 35 | } 36 | 37 | std::ostream& operator<<(std::ostream& out, arrow::Lexeme const value); -------------------------------------------------------------------------------- /src/lexer/Lexer.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Token.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | class Lexer { 11 | 12 | public: 13 | static std::vector tokenize(std::istream & stream); 14 | static std::vector tokenizeProgArgs(std::istream & stream); 15 | 16 | }; 17 | } -------------------------------------------------------------------------------- /src/lexer/Token.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Lexeme.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | struct Token { 11 | 12 | Token() 13 | : lexeme(Lexeme::NIL) 14 | , raw("") 15 | , lineNumber(0) 16 | { 17 | } 18 | 19 | Token(Lexeme lex, std::string str, long const ln) 20 | : lexeme(std::move(lex)) 21 | , raw(std::move(str)) 22 | , lineNumber(ln) 23 | { 24 | } 25 | 26 | Token(Token const & other) 27 | : lexeme(other.lexeme) 28 | , raw(other.raw) 29 | , lineNumber(other.lineNumber) 30 | { 31 | } 32 | 33 | Lexeme lexeme; 34 | std::string raw; 35 | long lineNumber; 36 | }; 37 | } -------------------------------------------------------------------------------- /src/parser/BuiltInFunctionExpressionParser.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "TokenManager.hpp" 6 | #include "expressions/Expression.hpp" 7 | #include "lexer/Token.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class BuiltInFunctionExpressionBuilder; 14 | class BuiltInFunctionExpressionParser 15 | { 16 | public: 17 | BuiltInFunctionExpressionParser(TokenManager & tm); 18 | BuiltInFunctionExpressionParser() = delete; 19 | std::shared_ptr parseExpression(std::string name); 20 | 21 | private: 22 | TokenManager & m_tm; 23 | static std::vector> m_builtins; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /src/parser/LanguageException.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | class LanguageException : public std::exception 11 | { 12 | public: 13 | LanguageException(std::string errorString, 14 | long const lineNumber = -1) 15 | : m_errorString(std::move(errorString)) 16 | , m_lineNumber(lineNumber) 17 | { 18 | update(); 19 | } 20 | ~LanguageException() throw() {} 21 | 22 | LanguageException & withErrorString(std::string errorString) 23 | { 24 | m_errorString = std::move(errorString); 25 | update(); 26 | return *this; 27 | } 28 | LanguageException & withLineNumber(long const lineNumber) 29 | { 30 | m_lineNumber = lineNumber; 31 | update(); 32 | return *this; 33 | } 34 | char const * report(bool const withLineNumber) const{ 35 | return withLineNumber ? m_errorStringWithLineNum.c_str() : m_errorString.c_str(); 36 | } 37 | 38 | char const * what() const throw (){ 39 | return report(true); 40 | } 41 | 42 | private: 43 | std::string m_errorString, m_errorStringWithLineNum; 44 | long m_lineNumber; 45 | 46 | void update() { 47 | m_errorStringWithLineNum = m_errorString + " on line number " + std::to_string(m_lineNumber); 48 | } 49 | }; 50 | } -------------------------------------------------------------------------------- /src/parser/Node.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | namespace arrow { 6 | class Node 7 | { 8 | public: 9 | Node(){} 10 | }; 11 | } -------------------------------------------------------------------------------- /src/parser/ReceiverParser.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include "ExpressionParser.hpp" 6 | #include "TokenManager.hpp" 7 | #include "receivers/Receiver.hpp" 8 | #include "lexer/Token.hpp" 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class ReceiverParser 14 | { 15 | public: 16 | ReceiverParser(TokenManager & tm); 17 | ReceiverParser() = delete; 18 | std::shared_ptr parseReceiver(); 19 | std::shared_ptr parseIdentifierReceiver(); 20 | std::shared_ptr parseDollarIdentifierReceiver(); 21 | std::shared_ptr parseArrayAccessorReceiver(); 22 | std::shared_ptr parseFileReceiver(); 23 | private: 24 | TokenManager & m_tm; 25 | ExpressionParser m_ep; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /src/parser/TokenManager.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "TokenManager.hpp" 4 | #include "LanguageException.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | TokenManager::TokenManager(std::vector tokens) 10 | : m_tokens(std::move(tokens)) 11 | , m_current(std::begin(m_tokens)) 12 | , m_end(std::end(m_tokens)) 13 | { 14 | } 15 | 16 | bool TokenManager::notAtEnd() const 17 | { 18 | return m_current != m_end; 19 | } 20 | bool TokenManager::tokenPlusOneNotAtEnd() const 21 | { 22 | return (m_current + 1) != m_end; 23 | } 24 | void TokenManager::advanceTokenIterator() 25 | { 26 | if(m_current == m_end) { 27 | throw LanguageException("Parse error"); 28 | } 29 | ++m_current; 30 | // skip over comments 31 | while(m_current != m_end && m_current->lexeme == Lexeme::COMMENT) { 32 | ++m_current; 33 | } 34 | } 35 | Token TokenManager::currentToken() const 36 | { 37 | if(m_current == m_end) { 38 | throw LanguageException("Parse error"); 39 | } 40 | return *m_current; 41 | } 42 | Token TokenManager::nextToken() const 43 | { 44 | if((m_current + 1) == m_end) { 45 | throw LanguageException("Parse error"); 46 | } 47 | return *(m_current + 1); 48 | } 49 | 50 | std::vector::iterator 51 | TokenManager::retrieveIt() const 52 | { 53 | return m_current; 54 | } 55 | void TokenManager::revert(std::vector::iterator orig) 56 | { 57 | m_current = orig; 58 | } 59 | } -------------------------------------------------------------------------------- /src/parser/TokenManager.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "lexer/Token.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class TokenManager 11 | { 12 | public: 13 | explicit TokenManager(std::vector tokens); 14 | TokenManager() = delete; 15 | bool notAtEnd() const; 16 | bool tokenPlusOneNotAtEnd() const; 17 | void advanceTokenIterator(); 18 | Token currentToken() const; 19 | Token nextToken() const; 20 | std::vector::iterator retrieveIt() const; 21 | void revert(std::vector::iterator orig); 22 | private: 23 | std::vector m_tokens; 24 | std::vector::iterator m_current; 25 | std::vector::iterator m_end; 26 | int mutable m_called; 27 | }; 28 | } -------------------------------------------------------------------------------- /src/receivers/ArrayAccessorReceiver.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ArrayAccessorReceiver.hpp" 4 | #include "evaluator/ArrayAccessorReceiverEvaluator.hpp" 5 | #include "parser/LanguageException.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | ArrayAccessorReceiver::ArrayAccessorReceiver(long const lineNumber) 11 | : Receiver(lineNumber) 12 | , m_identifier() 13 | { 14 | } 15 | 16 | std::shared_ptr 17 | ArrayAccessorReceiver::getEvaluator() const 18 | { 19 | return std::make_shared(m_identifier, m_expression); 20 | } 21 | 22 | ArrayAccessorReceiver & ArrayAccessorReceiver::withIdentifierToken(Token identifier) 23 | { 24 | m_identifier = std::move(identifier); 25 | return *this; 26 | } 27 | ArrayAccessorReceiver & ArrayAccessorReceiver::withExpression(std::shared_ptr expression) 28 | { 29 | m_expression = std::move(expression); 30 | return *this; 31 | } 32 | 33 | Token const & ArrayAccessorReceiver::getIdentifierToken() const 34 | { 35 | return m_identifier; 36 | } 37 | std::shared_ptr const & ArrayAccessorReceiver::getExpression() const 38 | { 39 | return m_expression; 40 | } 41 | 42 | std::string ArrayAccessorReceiver::toString() const 43 | { 44 | return ""; // TODO 45 | } 46 | } -------------------------------------------------------------------------------- /src/receivers/ArrayAccessorReceiver.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Receiver.hpp" 6 | #include "expressions/Expression.hpp" 7 | #include "lexer/Token.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class ArrayAccessorReceiver : public Receiver 13 | { 14 | public: 15 | ArrayAccessorReceiver(long const lineNumber); 16 | std::shared_ptr getEvaluator() const override; 17 | ArrayAccessorReceiver & withIdentifierToken(Token identifier); 18 | ArrayAccessorReceiver & withExpression(std::shared_ptr); 19 | Token const & getIdentifierToken() const; 20 | std::shared_ptr const & getExpression() const; 21 | std::string toString() const override; 22 | private: 23 | Token m_identifier; 24 | std::shared_ptr m_expression; 25 | }; 26 | 27 | } -------------------------------------------------------------------------------- /src/receivers/DollarIdentifierReceiver.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "DollarIdentifierReceiver.hpp" 4 | #include "evaluator/DollarIdentifierReceiverEvaluator.hpp" 5 | #include "parser/LanguageException.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | DollarIdentifierReceiver::DollarIdentifierReceiver(long const lineNumber) 11 | : Receiver(lineNumber) 12 | { 13 | } 14 | 15 | std::shared_ptr 16 | DollarIdentifierReceiver::getEvaluator() const 17 | { 18 | return std::make_shared(m_expression); 19 | } 20 | 21 | DollarIdentifierReceiver & DollarIdentifierReceiver::withExpression(std::shared_ptr expression) 22 | { 23 | m_expression = std::move(expression); 24 | return *this; 25 | } 26 | 27 | std::shared_ptr const & DollarIdentifierReceiver::getExpression() const 28 | { 29 | return m_expression; 30 | } 31 | 32 | std::string DollarIdentifierReceiver::toString() const 33 | { 34 | return ""; // TODO 35 | } 36 | } -------------------------------------------------------------------------------- /src/receivers/DollarIdentifierReceiver.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Receiver.hpp" 6 | #include "expressions/Expression.hpp" 7 | #include "lexer/Token.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class DollarIdentifierReceiver : public Receiver 13 | { 14 | public: 15 | DollarIdentifierReceiver(long const lineNumber); 16 | std::shared_ptr getEvaluator() const override; 17 | DollarIdentifierReceiver & withExpression(std::shared_ptr); 18 | std::shared_ptr const & getExpression() const; 19 | std::string toString() const override; 20 | private: 21 | std::shared_ptr m_expression; 22 | }; 23 | 24 | } -------------------------------------------------------------------------------- /src/receivers/IdentifierReceiver.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "IdentifierReceiver.hpp" 4 | #include "evaluator/IdentifierReceiverEvaluator.hpp" 5 | #include "parser/LanguageException.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | IdentifierReceiver::IdentifierReceiver(long const lineNumber) 11 | : Receiver(lineNumber) 12 | , m_identifier() 13 | { 14 | } 15 | 16 | std::shared_ptr 17 | IdentifierReceiver::getEvaluator() const 18 | { 19 | return std::make_shared(m_identifier); 20 | } 21 | 22 | IdentifierReceiver & IdentifierReceiver::withIdentifierToken(Token identifier) 23 | { 24 | m_identifier = std::move(identifier); 25 | return *this; 26 | } 27 | 28 | Token const & IdentifierReceiver::getIdentifierToken() const 29 | { 30 | return m_identifier; 31 | } 32 | 33 | std::string IdentifierReceiver::toString() const 34 | { 35 | std::string str("\nIdentifier expression: "); 36 | return str.append(m_identifier.raw); 37 | } 38 | } -------------------------------------------------------------------------------- /src/receivers/IdentifierReceiver.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Receiver.hpp" 6 | #include "lexer/Token.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class IdentifierReceiver : public Receiver 12 | { 13 | public: 14 | IdentifierReceiver(long const lineNumber); 15 | std::shared_ptr getEvaluator() const override; 16 | IdentifierReceiver & withIdentifierToken(Token identifier); 17 | Token const & getIdentifierToken() const; 18 | std::string toString() const override; 19 | private: 20 | Token m_identifier; 21 | }; 22 | 23 | } -------------------------------------------------------------------------------- /src/receivers/Receiver.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "Receiver.hpp" 4 | #include "parser/LanguageException.hpp" 5 | 6 | namespace arrow { 7 | Receiver::Receiver(long const lineNumber) 8 | : Node() 9 | , m_lineNumber(lineNumber) 10 | { 11 | } 12 | 13 | std::shared_ptr Receiver::getEvaluator() const 14 | { 15 | throw LanguageException("Cannot evaluate expression", m_lineNumber); 16 | } 17 | 18 | long Receiver::getLineNumber() const 19 | { 20 | return m_lineNumber; 21 | } 22 | } -------------------------------------------------------------------------------- /src/receivers/Receiver.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "parser/Node.hpp" 6 | #include "representation/Type.hpp" 7 | #include 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class ReceiverEvaluator; 13 | 14 | class Receiver : public Node 15 | { 16 | public: 17 | Receiver(long const lineNumber); 18 | 19 | /// Returns an Evaluator that can be used to evaluate this 20 | virtual std::shared_ptr getEvaluator() const; 21 | 22 | /// For debugging purposes 23 | virtual std::string toString() const = 0; 24 | 25 | long getLineNumber() const; 26 | 27 | protected: 28 | long m_lineNumber; 29 | }; 30 | } -------------------------------------------------------------------------------- /src/receivers/evaluator/ArrayAccessorReceiverEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ReceiverEvaluator.hpp" 6 | #include "expressions/Expression.hpp" 7 | #include "lexer/Token.hpp" 8 | #include "representation/Environment.hpp" 9 | 10 | namespace arrow { 11 | 12 | struct ArrayAccessorReceiverEvaluator : public ReceiverEvaluator { 13 | ArrayAccessorReceiverEvaluator(Token tok, std::shared_ptr expression); 14 | void evaluate(Type incoming, Environment & environment) const override; 15 | private: 16 | Token m_tok; 17 | std::shared_ptr m_expression; 18 | }; 19 | 20 | } -------------------------------------------------------------------------------- /src/receivers/evaluator/DollarIdentifierReceiverEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "ReceiverEvaluator.hpp" 6 | #include "expressions/Expression.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | 11 | class IdentifierExpression; 12 | class IndexExpression; 13 | 14 | struct DollarIdentifierReceiverEvaluator : public ReceiverEvaluator { 15 | explicit DollarIdentifierReceiverEvaluator(std::shared_ptr expression); 16 | void evaluate(Type incoming, Environment & environment) const override; 17 | private: 18 | std::shared_ptr m_expression; 19 | 20 | /// Likely identifies a vector 21 | void handleIdentifierExpression(Type evaluated, 22 | Environment & environment, 23 | IdentifierExpression * expr) const; 24 | 25 | /// An index expression could represent a map or a pod 26 | void handleIndexExpression(Type evaluated, 27 | Environment & environment, 28 | IndexExpression * expr) const; 29 | }; 30 | 31 | } -------------------------------------------------------------------------------- /src/receivers/evaluator/IdentifierReceiverEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "IdentifierReceiverEvaluator.hpp" 4 | #include "parser/LanguageException.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | IdentifierReceiverEvaluator::IdentifierReceiverEvaluator(Token tok) 10 | : m_tok(std::move(tok)) 11 | { 12 | } 13 | 14 | void IdentifierReceiverEvaluator::evaluate(Type incoming, Environment & environment) const 15 | { 16 | // automatically does a replace 17 | environment.add(m_tok.raw, std::move(incoming)); 18 | } 19 | } -------------------------------------------------------------------------------- /src/receivers/evaluator/IdentifierReceiverEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "ReceiverEvaluator.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "representation/Environment.hpp" 8 | 9 | namespace arrow { 10 | 11 | struct IdentifierReceiverEvaluator : public ReceiverEvaluator { 12 | IdentifierReceiverEvaluator(Token tok); 13 | void evaluate(Type incoming, Environment & environment) const override; 14 | private: 15 | Token m_tok; 16 | }; 17 | 18 | } -------------------------------------------------------------------------------- /src/receivers/evaluator/ReceiverEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "representation/Type.hpp" 6 | #include "representation/Environment.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | class ReceiverEvaluator 11 | { 12 | public: 13 | virtual void evaluate(Type, Environment&) const = 0; 14 | }; 15 | } -------------------------------------------------------------------------------- /src/representation/PodType.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "PodType.hpp" 4 | #include "Type.hpp" 5 | 6 | namespace arrow { 7 | bool PodType::operator==(PodType const & other) const 8 | { 9 | return m_namedData == other.m_namedData; 10 | } 11 | bool PodType::operator!=(PodType const & other) const 12 | { 13 | return m_namedData != other.m_namedData; 14 | } 15 | 16 | void PodType::add(std::string identifier, Type t) 17 | { 18 | m_namedData.emplace(std::move(identifier), std::move(t)); 19 | } 20 | 21 | bool PodType::has(std::string identifier) 22 | { 23 | auto found = m_namedData.find(std::move(identifier)); 24 | if(found == std::end(m_namedData)) { 25 | return false; 26 | } 27 | return true; 28 | } 29 | 30 | Type PodType::get(std::string identifier) 31 | { 32 | auto found = m_namedData.find(std::move(identifier)); 33 | return found->second; 34 | } 35 | } -------------------------------------------------------------------------------- /src/representation/PodType.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class Type; 11 | 12 | /// To support rudimentary object orientation, include a 13 | /// pod (plain old data type). When fully integrated, this 14 | /// will allow the following syntax in arrow: 15 | /// pod p(one two three); 16 | /// p(1, [one two], 3) -> ident; 17 | /// ident:two -> ret; ;;; ret is [one two] 18 | struct PodType { 19 | 20 | /// For storing the pod data. Every string key 21 | /// is the name of the bit of data. 22 | std::map m_namedData; 23 | bool operator==(PodType const & other) const; 24 | bool operator!=(PodType const & other) const; 25 | 26 | /// Add a data member 27 | void add(std::string identifier, Type t); 28 | 29 | /// Test membership 30 | bool has(std::string identifier); 31 | 32 | /// Retrieve a data member 33 | Type get(std::string identifier); 34 | }; 35 | } -------------------------------------------------------------------------------- /src/representation/TypeDescriptor.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | namespace arrow { 6 | 7 | /// Describes a given type 8 | enum class TypeDescriptor { 9 | Int, Bool, Real, Byte, String, List, BracketlessList, 10 | Ints, Bools, Reals, Bytes, Strings, None, SingleEqual, 11 | DoubleEqual, ExpressionCollection, BracedExpressionCollection, 12 | Nil, QString, QQString, ListWord, Map, Pod, Pods, Arrays 13 | }; 14 | 15 | } -------------------------------------------------------------------------------- /src/representation/VariantType.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "real.hpp" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace arrow { 13 | 14 | /// Represents the set of built-in types 15 | class Type; 16 | class PodType; 17 | using VariantType = std::variant, 20 | std::vector, 21 | std::vector, 22 | std::vector, 23 | std::vector, 24 | char, bool, 25 | std::vector, 26 | std::map, 27 | PodType, 28 | std::vector>; 29 | } -------------------------------------------------------------------------------- /src/representation/real.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace arrow { 4 | // Default precision for double. Might want to 5 | // compiler-switch on this (@jp) 6 | using real = long double; 7 | } -------------------------------------------------------------------------------- /src/statements/AnsiStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "ArrowlessStatement.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class AnsiStatement : public Statement 11 | { 12 | public: 13 | AnsiStatement(long const lineNumber, 14 | std::shared_ptr statement); 15 | Token getToken() const; 16 | std::shared_ptr const & getExpression() const; 17 | std::string toString() const override; 18 | std::shared_ptr getEvaluator() const override; 19 | private: 20 | std::shared_ptr m_statement; 21 | }; 22 | } -------------------------------------------------------------------------------- /src/statements/ArrowlessStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ArrowlessStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | ArrowlessStatement::ArrowlessStatement(long const lineNumber) 10 | : Statement(lineNumber) 11 | { 12 | } 13 | ArrowlessStatement & ArrowlessStatement::withToken(Token token) 14 | { 15 | m_keywordToken = std::move(token); 16 | return *this; 17 | } 18 | ArrowlessStatement& 19 | ArrowlessStatement::withExpression(std::shared_ptr expression) 20 | { 21 | m_expression = std::move(expression); 22 | return *this; 23 | } 24 | Token ArrowlessStatement::getToken() const 25 | { 26 | return m_keywordToken; 27 | } 28 | std::shared_ptr const & ArrowlessStatement::getExpression() const 29 | { 30 | return m_expression; 31 | } 32 | 33 | std::string ArrowlessStatement::toString() const 34 | { 35 | std::string str("\nKeyword: "); 36 | str.append(m_keywordToken.raw); 37 | str.append("\nExpression: "); 38 | str.append(m_expression->toString()); 39 | return str; 40 | } 41 | 42 | std::shared_ptr ArrowlessStatement::getEvaluator() const 43 | { 44 | return nullptr; 45 | } 46 | } -------------------------------------------------------------------------------- /src/statements/ArrowlessStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | 12 | class ArrowlessStatement : public Statement 13 | { 14 | public: 15 | ArrowlessStatement(long const lineNumber); 16 | ArrowlessStatement & withToken(Token token); 17 | ArrowlessStatement & withExpression(std::shared_ptr expression); 18 | Token getToken() const; 19 | std::shared_ptr const & getExpression() const; 20 | std::string toString() const override; 21 | std::shared_ptr getEvaluator() const override; 22 | private: 23 | Token m_keywordToken; // the keyword (e.g. prn) 24 | std::shared_ptr m_expression; 25 | }; 26 | 27 | } -------------------------------------------------------------------------------- /src/statements/AsyncStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | class AsyncStatement : public Statement 13 | { 14 | public: 15 | AsyncStatement(long const lineNumber); 16 | AsyncStatement & withToken(Token token); 17 | void addBodyStatement(std::shared_ptr bodyStatement); 18 | std::string toString() const override; 19 | std::shared_ptr getEvaluator() const override; 20 | std::vector> const & getBodyStatements() const; 21 | private: 22 | Token m_keywordToken; // start keyword 23 | std::vector> m_bodyStatements; 24 | }; 25 | 26 | } -------------------------------------------------------------------------------- /src/statements/EchoStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "ArrowlessStatement.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class EchoStatement : public Statement 11 | { 12 | public: 13 | EchoStatement(long const lineNumber, 14 | std::shared_ptr statement); 15 | Token getToken() const; 16 | std::shared_ptr const & getExpression() const; 17 | std::string toString() const override; 18 | std::shared_ptr getEvaluator() const override; 19 | private: 20 | std::shared_ptr m_statement; 21 | }; 22 | 23 | } -------------------------------------------------------------------------------- /src/statements/ElseIfStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ElseIfStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | ElseIfStatement::ElseIfStatement(long const lineNumber) 10 | : Statement(lineNumber) 11 | { 12 | } 13 | ElseIfStatement & ElseIfStatement::withToken(Token token) 14 | { 15 | m_keywordToken = std::move(token); 16 | return *this; 17 | } 18 | ElseIfStatement & ElseIfStatement::withExpression(std::shared_ptr expression) 19 | { 20 | m_expression = std::move(expression); 21 | return *this; 22 | } 23 | std::shared_ptr const & ElseIfStatement::getExpression() const 24 | { 25 | return m_expression; 26 | } 27 | ElseIfStatement & ElseIfStatement::withInnerStatement(std::shared_ptr innerStatement) 28 | { 29 | m_innerStatement = std::move(innerStatement); 30 | return *this; 31 | } 32 | std::shared_ptr const & ElseIfStatement::getInnerStatement() const 33 | { 34 | return m_innerStatement; 35 | } 36 | 37 | std::string ElseIfStatement::toString() const 38 | { 39 | return ""; // TODO 40 | } 41 | 42 | std::shared_ptr ElseIfStatement::getEvaluator() const 43 | { 44 | return nullptr; 45 | } 46 | } -------------------------------------------------------------------------------- /src/statements/ElseIfStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | 13 | /// Note, an ElseIfStatement can only be part 14 | /// of an IfStatement 15 | class ElseIfStatement : public Statement 16 | { 17 | public: 18 | ElseIfStatement(long const lineNumber); 19 | ElseIfStatement & withToken(Token token); 20 | ElseIfStatement & withExpression(std::shared_ptr expression); 21 | std::shared_ptr const & getExpression() const; 22 | ElseIfStatement & withInnerStatement(std::shared_ptr innerStatement); 23 | std::shared_ptr const & getInnerStatement() const; 24 | 25 | std::string toString() const override; 26 | std::shared_ptr getEvaluator() const override; 27 | 28 | private: 29 | Token m_keywordToken; // the elseif keyword 30 | std::shared_ptr m_expression; 31 | std::shared_ptr m_innerStatement; 32 | }; 33 | 34 | } -------------------------------------------------------------------------------- /src/statements/ElseStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ElseStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | ElseStatement::ElseStatement(long const lineNumber) 10 | : Statement(lineNumber) 11 | { 12 | } 13 | ElseStatement & ElseStatement::withToken(Token token) 14 | { 15 | m_keywordToken = std::move(token); 16 | return *this; 17 | } 18 | ElseStatement & ElseStatement::withInnerStatement(std::shared_ptr innerStatement) 19 | { 20 | m_innerStatement = std::move(innerStatement); 21 | return *this; 22 | } 23 | std::shared_ptr const & ElseStatement::getInnerStatement() const 24 | { 25 | return m_innerStatement; 26 | } 27 | std::string ElseStatement::toString() const 28 | { 29 | return ""; // TODO 30 | } 31 | 32 | std::shared_ptr ElseStatement::getEvaluator() const 33 | { 34 | return nullptr; 35 | } 36 | } -------------------------------------------------------------------------------- /src/statements/ElseStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | 13 | /// Note, an ElseStatement can only be part 14 | /// of an IfStatement or ElseIfStatement 15 | class ElseStatement : public Statement 16 | { 17 | public: 18 | ElseStatement(long const lineNumber); 19 | ElseStatement & withToken(Token token); 20 | ElseStatement & withInnerStatement(std::shared_ptr innerStatement); 21 | std::string toString() const override; 22 | std::shared_ptr getEvaluator() const override; 23 | std::shared_ptr const & getInnerStatement() const; 24 | private: 25 | Token m_keywordToken; // the else keyword 26 | std::shared_ptr m_innerStatement; 27 | }; 28 | 29 | } -------------------------------------------------------------------------------- /src/statements/EraseStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "ArrowlessStatement.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class EraseStatement : public Statement 11 | { 12 | public: 13 | EraseStatement(long const lineNumber, 14 | std::shared_ptr statement); 15 | Token getToken() const; 16 | std::shared_ptr const & getExpression() const; 17 | std::string toString() const override; 18 | std::shared_ptr getEvaluator() const override; 19 | private: 20 | std::shared_ptr m_statement; 21 | }; 22 | 23 | } -------------------------------------------------------------------------------- /src/statements/ExitStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ExitStatement.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/StatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | ExitStatement::ExitStatement(long const lineNumber, 11 | std::shared_ptr statement) 12 | : Statement(lineNumber) 13 | , m_statement(std::move(statement)) 14 | { 15 | 16 | } 17 | Token ExitStatement::getToken() const 18 | { 19 | return m_statement->getToken(); 20 | } 21 | std::shared_ptr const & ExitStatement::getExpression() const 22 | { 23 | return m_statement->getExpression(); 24 | } 25 | std::string ExitStatement::toString() const 26 | { 27 | return m_statement->toString(); 28 | } 29 | 30 | std::shared_ptr ExitStatement::getEvaluator() const 31 | { 32 | 33 | struct ExitStatementEvaluator : public StatementEvaluator 34 | { 35 | ExitStatementEvaluator(ExitStatement statement) 36 | : m_statement(std::move(statement)) 37 | { 38 | } 39 | StatementResult evaluate(Environment & environment) const override 40 | { 41 | return StatementResult::Exit; 42 | } 43 | private: 44 | ExitStatement m_statement; 45 | }; 46 | 47 | return std::make_shared(*this); 48 | } 49 | } -------------------------------------------------------------------------------- /src/statements/ExitStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "ArrowlessStatement.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class ExitStatement : public Statement 11 | { 12 | public: 13 | ExitStatement(long const lineNumber, 14 | std::shared_ptr statement); 15 | Token getToken() const; 16 | std::shared_ptr const & getExpression() const; 17 | std::string toString() const override; 18 | std::shared_ptr getEvaluator() const override; 19 | private: 20 | std::shared_ptr m_statement; 21 | }; 22 | 23 | } -------------------------------------------------------------------------------- /src/statements/ForStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ForStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include "evaluator/ForStatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | ForStatement::ForStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | } 14 | ForStatement & ForStatement::withToken(Token token) 15 | { 16 | m_keywordToken = std::move(token); 17 | return *this; 18 | } 19 | ForStatement & ForStatement::addIndexer(Token token) 20 | { 21 | m_indices.push_back(token); 22 | return *this; 23 | } 24 | ForStatement & ForStatement::withIdentifier(Token token) 25 | { 26 | m_identifier = std::move(token); 27 | return *this; 28 | } 29 | ForStatement & ForStatement::withInnerStatement(std::shared_ptr innerStatement) 30 | { 31 | m_innerStatement= std::move(innerStatement); 32 | return *this; 33 | } 34 | std::shared_ptr const & ForStatement::getInnerStatement() const 35 | { 36 | return m_innerStatement; 37 | } 38 | 39 | std::string ForStatement::toString() const 40 | { 41 | return ""; // TODO 42 | } 43 | std::vector const & ForStatement::getIndices() const 44 | { 45 | return m_indices; 46 | } 47 | Token const & ForStatement::getIdentifier() const 48 | { 49 | return m_identifier; 50 | } 51 | std::shared_ptr ForStatement::getEvaluator() const 52 | { 53 | return std::make_shared(*this); 54 | } 55 | } -------------------------------------------------------------------------------- /src/statements/ForStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class ForStatement : public Statement 14 | { 15 | public: 16 | ForStatement(long const lineNumber); 17 | ForStatement & withToken(Token token); 18 | ForStatement & addIndexer(Token token); 19 | ForStatement & withIdentifier(Token token); 20 | ForStatement & withInnerStatement(std::shared_ptr innerStatement); 21 | std::string toString() const override; 22 | std::shared_ptr getEvaluator() const override; 23 | std::vector const & getIndices() const; 24 | Token const & getIdentifier() const; 25 | std::shared_ptr const & getInnerStatement() const; 26 | private: 27 | Token m_keywordToken; // the while keyword 28 | std::vector m_indices; 29 | Token m_identifier; 30 | std::shared_ptr m_innerStatement; 31 | }; 32 | 33 | } -------------------------------------------------------------------------------- /src/statements/FunctionStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | class FunctionStatement : public Statement 13 | { 14 | public: 15 | FunctionStatement(long const lineNumber); 16 | FunctionStatement & withToken(Token token); 17 | FunctionStatement & withNameToken(Token token); 18 | FunctionStatement & withReturnIdentifierToken(Token token); 19 | FunctionStatement & 20 | withExpressionCollection(std::shared_ptr expression); 21 | FunctionStatement & withInnerStatement(std::shared_ptr innerStatement); 22 | std::string toString() const override; 23 | std::shared_ptr getEvaluator() const override; 24 | Token const & getName() const; 25 | std::shared_ptr const & getExpressionCollection() const; 26 | Token const & getReturnIdentifier() const; 27 | std::shared_ptr const & getInnerStatement() const; 28 | private: 29 | Token m_keywordToken; // fn keyword 30 | Token m_typeToken; // return type 31 | Token m_nameToken; 32 | std::shared_ptr m_expressionCollection; 33 | Token m_returnIdentifier; 34 | std::shared_ptr m_innerStatement; 35 | }; 36 | 37 | } -------------------------------------------------------------------------------- /src/statements/IfStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "ElseIfStatement.hpp" 6 | #include "ElseStatement.hpp" 7 | #include "Statement.hpp" 8 | #include "lexer/Token.hpp" 9 | #include "expressions/Expression.hpp" 10 | #include 11 | #include 12 | 13 | namespace arrow { 14 | 15 | /// Note, an IfStatement can contain optional 16 | /// ElseIfStatement parts an an optional 17 | /// ElseStatement part 18 | class IfStatement : public Statement 19 | { 20 | public: 21 | IfStatement(long const lineNumber); 22 | IfStatement & withToken(Token token); 23 | IfStatement & withExpression(std::shared_ptr expression); 24 | std::shared_ptr const & getExpression() const; 25 | IfStatement & withInnerStatement(std::shared_ptr innerStatement); 26 | void addElseIfPart(std::shared_ptr elseIfPart); 27 | IfStatement & withElsePart(std::shared_ptr elsePart); 28 | std::string toString() const override; 29 | std::shared_ptr getEvaluator() const override; 30 | std::shared_ptr const & getInnerStatement() const; 31 | std::vector> const & getElseIfParts() const; 32 | std::shared_ptr const & getElsePart() const; 33 | private: 34 | Token m_keywordToken; // the if keyword 35 | std::shared_ptr m_expression; 36 | std::shared_ptr m_innerStatement; 37 | std::vector> m_elseIfParts; 38 | std::shared_ptr m_elsePart; 39 | }; 40 | 41 | } -------------------------------------------------------------------------------- /src/statements/LoopBreakStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "LoopBreakStatement.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/StatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | LoopBreakStatement::LoopBreakStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | 14 | } 15 | std::string LoopBreakStatement::toString() const 16 | { 17 | return ""; // todo 18 | } 19 | 20 | std::shared_ptr LoopBreakStatement::getEvaluator() const 21 | { 22 | struct LoopBreakStatementEvaluator : public StatementEvaluator 23 | { 24 | StatementResult evaluate(Environment &) const override 25 | { 26 | return StatementResult::Break; 27 | } 28 | }; 29 | return std::make_shared(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/statements/LoopBreakStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "evaluator/StatementEvaluator.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class LoopBreakStatement : public Statement 12 | { 13 | public: 14 | LoopBreakStatement(long const lineNumber); 15 | std::string toString() const override; 16 | std::shared_ptr getEvaluator() const override; 17 | }; 18 | 19 | } -------------------------------------------------------------------------------- /src/statements/PodStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "PodStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include "evaluator/PodStatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | PodStatement::PodStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | } 14 | PodStatement & PodStatement::withToken(Token token) 15 | { 16 | m_keywordToken = std::move(token); 17 | return *this; 18 | } 19 | PodStatement & PodStatement::withNameToken(Token token) 20 | { 21 | m_nameToken = std::move(token); 22 | return *this; 23 | } 24 | PodStatement & 25 | PodStatement::withExpressionCollection(std::shared_ptr expression) 26 | { 27 | m_expressionCollection = std::move(expression); 28 | return *this; 29 | } 30 | 31 | Token const & PodStatement::getName() const 32 | { 33 | return m_nameToken; 34 | } 35 | std::shared_ptr const & PodStatement::getExpressionCollection() const 36 | { 37 | return m_expressionCollection; 38 | } 39 | 40 | std::string PodStatement::toString() const 41 | { 42 | return ""; // TODO 43 | } 44 | 45 | std::shared_ptr PodStatement::getEvaluator() const 46 | { 47 | return std::make_shared(*this); 48 | } 49 | } -------------------------------------------------------------------------------- /src/statements/PodStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | class PodStatement : public Statement 13 | { 14 | public: 15 | PodStatement(long const lineNumber); 16 | 17 | PodStatement & withToken(Token token); 18 | PodStatement & withNameToken(Token token); 19 | PodStatement & 20 | withExpressionCollection(std::shared_ptr expression); 21 | std::string toString() const override; 22 | std::shared_ptr getEvaluator() const override; 23 | Token const & getName() const; 24 | std::shared_ptr const & getExpressionCollection() const; 25 | private: 26 | Token m_keywordToken; // pod keyword 27 | Token m_nameToken; 28 | std::shared_ptr m_expressionCollection; 29 | }; 30 | 31 | } -------------------------------------------------------------------------------- /src/statements/ReleaseStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "ArrowlessStatement.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | class ReleaseStatement : public Statement 11 | { 12 | public: 13 | ReleaseStatement(long const lineNumber); 14 | ReleaseStatement & withToken(Token token); 15 | ReleaseStatement & withIdentifier(Token token); 16 | Token const & getToken() const; 17 | Token const & getIdentifier() const; 18 | std::string toString() const override; 19 | std::shared_ptr getEvaluator() const override; 20 | private: 21 | Token m_token; 22 | Token m_identifier; 23 | }; 24 | 25 | } -------------------------------------------------------------------------------- /src/statements/RepeatStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "RepeatStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include "evaluator/RepeatStatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | RepeatStatement::RepeatStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | } 14 | RepeatStatement & RepeatStatement::withToken(Token token) 15 | { 16 | m_keywordToken = std::move(token); 17 | return *this; 18 | } 19 | RepeatStatement & RepeatStatement::withExpression(std::shared_ptr expression) 20 | { 21 | m_expression = std::move(expression); 22 | return *this; 23 | } 24 | RepeatStatement & RepeatStatement::withInnerStatement(std::shared_ptr innerStatement) 25 | { 26 | m_innerStatement = std::move(innerStatement); 27 | return *this; 28 | } 29 | 30 | std::string RepeatStatement::toString() const 31 | { 32 | return ""; // TODO 33 | } 34 | std::shared_ptr const & RepeatStatement::getExpression() const 35 | { 36 | return m_expression; 37 | } 38 | std::shared_ptr const & RepeatStatement::getInnerStatement() const 39 | { 40 | return m_innerStatement; 41 | } 42 | 43 | std::shared_ptr RepeatStatement::getEvaluator() const 44 | { 45 | return std::make_shared(*this); 46 | } 47 | } -------------------------------------------------------------------------------- /src/statements/RepeatStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class RepeatStatement : public Statement 14 | { 15 | public: 16 | RepeatStatement(long const lineNumber); 17 | RepeatStatement & withToken(Token token); 18 | RepeatStatement & withExpression(std::shared_ptr expression); 19 | RepeatStatement & withInnerStatement(std::shared_ptr innerStatement); 20 | std::string toString() const override; 21 | std::shared_ptr getEvaluator() const override; 22 | std::shared_ptr const & getExpression() const; 23 | std::shared_ptr const & getInnerStatement() const; 24 | private: 25 | Token m_keywordToken; // the repeat keyword 26 | std::shared_ptr m_expression; 27 | std::shared_ptr m_innerStatement; 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /src/statements/ReturnStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ReturnStatement.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/StatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | ReturnStatement::ReturnStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | 14 | } 15 | std::string ReturnStatement::toString() const 16 | { 17 | return ""; // todo 18 | } 19 | 20 | std::shared_ptr ReturnStatement::getEvaluator() const 21 | { 22 | struct ReturnStatementEvaluator : public StatementEvaluator 23 | { 24 | StatementResult evaluate(Environment &) const override 25 | { 26 | return StatementResult::Return; 27 | } 28 | }; 29 | return std::make_shared(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/statements/ReturnStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "evaluator/StatementEvaluator.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class ReturnStatement : public Statement 12 | { 13 | public: 14 | ReturnStatement(long const lineNumber); 15 | std::string toString() const override; 16 | std::shared_ptr getEvaluator() const override; 17 | }; 18 | 19 | } -------------------------------------------------------------------------------- /src/statements/ScopedBlockStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ScopedBlockStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include "evaluator/ScopedBlockStatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | ScopedBlockStatement::ScopedBlockStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | } 14 | void ScopedBlockStatement::addBodyStatement(std::shared_ptr bodyStatement) 15 | { 16 | m_bodyStatements.emplace_back(std::move(bodyStatement)); 17 | } 18 | 19 | std::string ScopedBlockStatement::toString() const 20 | { 21 | return ""; // TODO 22 | } 23 | std::vector> const & 24 | ScopedBlockStatement::getBodyStatements() const 25 | { 26 | return m_bodyStatements; 27 | } 28 | std::shared_ptr ScopedBlockStatement::getEvaluator() const 29 | { 30 | return std::make_shared(*this); 31 | } 32 | } -------------------------------------------------------------------------------- /src/statements/ScopedBlockStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class ScopedBlockStatement : public Statement 14 | { 15 | public: 16 | ScopedBlockStatement(long const lineNumber); 17 | void addBodyStatement(std::shared_ptr bodyStatement); 18 | std::string toString() const override; 19 | std::shared_ptr getEvaluator() const override; 20 | std::vector> const & getBodyStatements() const; 21 | private: 22 | std::vector> m_bodyStatements; 23 | }; 24 | 25 | } -------------------------------------------------------------------------------- /src/statements/SimpleArrowStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "SimpleArrowStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include "evaluator/SimpleArrowStatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | SimpleArrowStatement::SimpleArrowStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | } 14 | 15 | SimpleArrowStatement & 16 | SimpleArrowStatement::withExpression(std::shared_ptr expression) 17 | { 18 | m_expression = std::move(expression); 19 | return *this; 20 | } 21 | SimpleArrowStatement & SimpleArrowStatement::withIdentifier(std::shared_ptr identifier) 22 | { 23 | m_identifier = std::move(identifier); 24 | return *this; 25 | } 26 | SimpleArrowStatement & 27 | SimpleArrowStatement::withIndexExpression(std::shared_ptr expression) 28 | { 29 | m_indexExpression = std::move(expression); 30 | return *this; 31 | } 32 | 33 | std::shared_ptr const & SimpleArrowStatement::getExpression() const 34 | { 35 | return m_expression; 36 | } 37 | std::shared_ptr const & SimpleArrowStatement::getIndexExpression() const 38 | { 39 | return m_indexExpression; 40 | } 41 | 42 | std::shared_ptr const & SimpleArrowStatement::getIdentifier() const 43 | { 44 | return m_identifier; 45 | } 46 | 47 | std::string SimpleArrowStatement::toString() const 48 | { 49 | return ""; // TODO 50 | } 51 | 52 | std::shared_ptr SimpleArrowStatement::getEvaluator() const 53 | { 54 | return std::make_shared(*this); 55 | } 56 | } -------------------------------------------------------------------------------- /src/statements/SimpleArrowStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include "receivers/Receiver.hpp" 9 | 10 | #include 11 | 12 | namespace arrow { 13 | 14 | // Describes a statement of the form 15 | // expression -> identifier; 16 | // or 17 | // expression -> identifier[expression]; 18 | class SimpleArrowStatement : public Statement 19 | { 20 | public: 21 | SimpleArrowStatement(long const lineNumber); 22 | SimpleArrowStatement & withExpression(std::shared_ptr expression); 23 | SimpleArrowStatement & withIdentifier(std::shared_ptr identifier); 24 | SimpleArrowStatement & withIndexExpression(std::shared_ptr expression); 25 | 26 | std::shared_ptr const & getIdentifier() const; 27 | std::shared_ptr const & getExpression() const; 28 | std::shared_ptr const & getIndexExpression() const; 29 | 30 | std::string toString() const override; 31 | std::shared_ptr getEvaluator() const override; 32 | 33 | private: 34 | std::shared_ptr m_expression; 35 | std::shared_ptr m_identifier; 36 | std::shared_ptr m_indexExpression; 37 | }; 38 | 39 | } -------------------------------------------------------------------------------- /src/statements/SingleExpressionStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "SingleExpressionStatement.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "evaluator/StatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | SingleExpressionStatement::SingleExpressionStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | } 14 | SingleExpressionStatement& 15 | SingleExpressionStatement::withExpression(std::shared_ptr expression) 16 | { 17 | m_expression = std::move(expression); 18 | return *this; 19 | } 20 | std::shared_ptr const & SingleExpressionStatement::getExpression() const 21 | { 22 | return m_expression; 23 | } 24 | 25 | std::string SingleExpressionStatement::toString() const 26 | { 27 | return ""; // todo 28 | } 29 | 30 | std::shared_ptr SingleExpressionStatement::getEvaluator() const 31 | { 32 | struct SingleExpressionStatementEvaluator : public StatementEvaluator 33 | { 34 | SingleExpressionStatementEvaluator(SingleExpressionStatement statement) 35 | : m_statement(std::move(statement)) 36 | {} 37 | StatementResult evaluate(Environment & environment) const override 38 | { 39 | auto const expression = m_statement.getExpression(); 40 | (void)expression->getEvaluator()->evaluate(environment); 41 | return StatementResult::Continue; 42 | } 43 | private: 44 | SingleExpressionStatement m_statement; 45 | }; 46 | return std::make_shared(*this); 47 | } 48 | } -------------------------------------------------------------------------------- /src/statements/SingleExpressionStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "expressions/Expression.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class SingleExpressionStatement : public Statement 12 | { 13 | public: 14 | SingleExpressionStatement(long const lineNumber); 15 | SingleExpressionStatement & withExpression(std::shared_ptr expression); 16 | std::shared_ptr const & getExpression() const; 17 | std::string toString() const override; 18 | std::shared_ptr getEvaluator() const override; 19 | private: 20 | std::shared_ptr m_expression; 21 | }; 22 | 23 | } -------------------------------------------------------------------------------- /src/statements/StartStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "StartStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | StartStatement::StartStatement(long const lineNumber) 9 | : Statement(lineNumber) 10 | { 11 | } 12 | StartStatement & StartStatement::withToken(Token token) 13 | { 14 | m_keywordToken = std::move(token); 15 | return *this; 16 | } 17 | StartStatement & StartStatement::withInnerStatement(std::shared_ptr innerStatement) 18 | { 19 | m_innerStatement = std::move(innerStatement); 20 | return *this; 21 | } 22 | 23 | std::shared_ptr const & StartStatement::getInnerStatement() const 24 | { 25 | return m_innerStatement; 26 | } 27 | 28 | std::string StartStatement::toString() const 29 | { 30 | return ""; // TODO 31 | } 32 | 33 | std::shared_ptr StartStatement::getEvaluator() const 34 | { 35 | 36 | struct StartStatementEvaluator : public StatementEvaluator 37 | { 38 | explicit StartStatementEvaluator(StartStatement statement) 39 | : m_statement(std::move(statement)) 40 | { 41 | } 42 | 43 | StatementResult evaluate(Environment & environment) const override 44 | { 45 | auto innerStatement = m_statement.getInnerStatement(); 46 | return innerStatement->getEvaluator()->evaluate(environment); 47 | } 48 | private: 49 | StartStatement m_statement; 50 | }; 51 | 52 | return std::make_shared(*this); 53 | } 54 | } -------------------------------------------------------------------------------- /src/statements/StartStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | class StartStatement : public Statement 13 | { 14 | public: 15 | StartStatement(long const lineNumber); 16 | StartStatement & withToken(Token token); 17 | StartStatement & withInnerStatement(std::shared_ptr innerStatement); 18 | std::string toString() const override; 19 | std::shared_ptr getEvaluator() const override; 20 | std::shared_ptr const & getInnerStatement() const; 21 | private: 22 | Token m_keywordToken; // start keyword 23 | std::shared_ptr m_innerStatement; 24 | }; 25 | 26 | } -------------------------------------------------------------------------------- /src/statements/Statement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "parser/Node.hpp" 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | 11 | class StatementEvaluator; 12 | class Statement : public Node 13 | { 14 | public: 15 | Statement(long const lineNumber) 16 | : Node() 17 | , m_lineNumber(lineNumber) 18 | { 19 | } 20 | 21 | /// Returns an Evaluator that can be used to evaluate this 22 | virtual std::shared_ptr getEvaluator() const 23 | { 24 | return nullptr; 25 | } 26 | 27 | /// For debugging purposes 28 | virtual std::string toString() const = 0; 29 | 30 | long getLineNumber() const 31 | { 32 | return m_lineNumber; 33 | } 34 | protected: 35 | long m_lineNumber; 36 | }; 37 | 38 | } -------------------------------------------------------------------------------- /src/statements/StringToIntStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | // TODO: obsolete code (convert to a built-in expression type) 4 | 5 | /* 6 | #pragma once 7 | 8 | #include "lexer/Token.hpp" 9 | #include "expressions/Expression.hpp" 10 | #include 11 | 12 | namespace arrow { 13 | class StringToIntStatement : public Statement 14 | { 15 | public: 16 | StringToIntStatement(long const lineNumber, ArrowStatement arrowStatement); 17 | std::string toString() const override; 18 | std::shared_ptr getEvaluator() const override; 19 | StringToIntStatement const & withToken(Token token) const; 20 | Token getToken() const; 21 | std::shared_ptr getExpression() const; 22 | Token getIdentifier() const; 23 | private: 24 | ArrowStatement mutable m_arrowStatement; 25 | 26 | }; 27 | } 28 | */ -------------------------------------------------------------------------------- /src/statements/WhileStatement.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "WhileStatement.hpp" 4 | #include "evaluator/StatementEvaluator.hpp" 5 | #include "evaluator/WhileStatementEvaluator.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | WhileStatement::WhileStatement(long const lineNumber) 11 | : Statement(lineNumber) 12 | { 13 | } 14 | WhileStatement & WhileStatement::withToken(Token token) 15 | { 16 | m_keywordToken = std::move(token); 17 | return *this; 18 | } 19 | WhileStatement & WhileStatement::withExpression(std::shared_ptr expression) 20 | { 21 | m_expression = std::move(expression); 22 | return *this; 23 | } 24 | WhileStatement & WhileStatement::withInnerStatement(std::shared_ptr innerStatement) 25 | { 26 | m_innerStatement = std::move(innerStatement); 27 | return *this; 28 | } 29 | std::shared_ptr const & WhileStatement::getInnerStatement() const 30 | { 31 | return m_innerStatement; 32 | } 33 | 34 | std::string WhileStatement::toString() const 35 | { 36 | return ""; // TODO 37 | } 38 | std::shared_ptr const & WhileStatement::getExpression() const 39 | { 40 | return m_expression; 41 | } 42 | std::shared_ptr WhileStatement::getEvaluator() const 43 | { 44 | return std::make_shared(*this); 45 | } 46 | } -------------------------------------------------------------------------------- /src/statements/WhileStatement.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "Statement.hpp" 6 | #include "lexer/Token.hpp" 7 | #include "expressions/Expression.hpp" 8 | #include 9 | #include 10 | 11 | namespace arrow { 12 | 13 | class WhileStatement : public Statement 14 | { 15 | public: 16 | WhileStatement(long const lineNumber); 17 | WhileStatement & withToken(Token token); 18 | WhileStatement & withExpression(std::shared_ptr expression); 19 | WhileStatement & withInnerStatement(std::shared_ptr innerStatement); 20 | std::string toString() const override; 21 | std::shared_ptr getEvaluator() const override; 22 | std::shared_ptr const & getExpression() const; 23 | std::shared_ptr const & getInnerStatement() const; 24 | private: 25 | Token m_keywordToken; // the while keyword 26 | std::shared_ptr m_expression; 27 | std::shared_ptr m_innerStatement; 28 | }; 29 | 30 | } -------------------------------------------------------------------------------- /src/statements/evaluator/ForStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/ForStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class ForStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | explicit ForStatementEvaluator(ForStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | ForStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/statements/evaluator/FunctionStatementEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "FunctionStatementEvaluator.hpp" 4 | #include "parser/LanguageException.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | FunctionStatementEvaluator::FunctionStatementEvaluator(FunctionStatement statement) 9 | : m_statement(std::move(statement)) 10 | { 11 | } 12 | StatementResult FunctionStatementEvaluator::evaluate(Environment & environment) const 13 | { 14 | auto const name = m_statement.getName().raw; 15 | auto const innerStatement = m_statement.getInnerStatement(); 16 | auto const returnIdentifier = m_statement.getReturnIdentifier(); 17 | auto res = innerStatement->getEvaluator()->evaluate(environment); 18 | if(returnIdentifier.lexeme != Lexeme::NIL && !environment.has(returnIdentifier.raw)) { 19 | throw LanguageException("Can't find return value in function statement", 20 | returnIdentifier.lineNumber); 21 | } 22 | if(res == StatementResult::Exit) { 23 | return res; 24 | } 25 | return StatementResult::Continue; 26 | } 27 | } -------------------------------------------------------------------------------- /src/statements/evaluator/FunctionStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/FunctionStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class FunctionStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | explicit FunctionStatementEvaluator(FunctionStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | FunctionStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/statements/evaluator/IfStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/IfStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class IfStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | explicit IfStatementEvaluator(IfStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | IfStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/statements/evaluator/PodStatementEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 - present 2 | 3 | #include "PodStatementEvaluator.hpp" 4 | #include "parser/LanguageException.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | PodStatementEvaluator::PodStatementEvaluator(PodStatement statement) 9 | : m_statement(std::move(statement)) 10 | { 11 | } 12 | StatementResult PodStatementEvaluator::evaluate(Environment &) const 13 | { 14 | return StatementResult::Continue; 15 | } 16 | } -------------------------------------------------------------------------------- /src/statements/evaluator/PodStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2020 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/PodStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class PodStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | explicit PodStatementEvaluator(PodStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | PodStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/statements/evaluator/RepeatStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/RepeatStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class RepeatStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | explicit RepeatStatementEvaluator(RepeatStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | RepeatStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/statements/evaluator/ScopedBlockStatementEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ScopedBlockStatementEvaluator.hpp" 4 | #include "parser/LanguageException.hpp" 5 | #include 6 | 7 | namespace arrow { 8 | 9 | namespace { 10 | StatementResult evaluateBody(std::vector> bodyStatements, 11 | Environment & environment) 12 | { 13 | for(auto const & statement : bodyStatements) { 14 | auto const result = statement->getEvaluator()->evaluate(environment); 15 | if(result != StatementResult::Continue) { 16 | return result; 17 | } 18 | if(environment.getExitState()) { 19 | return StatementResult::Exit; 20 | } 21 | } 22 | return StatementResult::Continue; 23 | } 24 | } 25 | 26 | ScopedBlockStatementEvaluator::ScopedBlockStatementEvaluator(ScopedBlockStatement statement) 27 | : m_statement(std::move(statement)) 28 | { 29 | } 30 | 31 | StatementResult ScopedBlockStatementEvaluator::evaluate(Environment & environment) const 32 | { 33 | auto bodyStatements = m_statement.getBodyStatements(); 34 | auto const evaluated = evaluateBody(bodyStatements, environment); 35 | return evaluated; 36 | } 37 | } -------------------------------------------------------------------------------- /src/statements/evaluator/ScopedBlockStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/ScopedBlockStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class ScopedBlockStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | explicit ScopedBlockStatementEvaluator(ScopedBlockStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | ScopedBlockStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/statements/evaluator/SimpleArrowStatementEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "SimpleArrowStatementEvaluator.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "expressions/IndexExpression.hpp" 6 | #include "receivers/evaluator/ReceiverEvaluator.hpp" 7 | #include "parser/LanguageException.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | 12 | SimpleArrowStatementEvaluator::SimpleArrowStatementEvaluator(SimpleArrowStatement statement) 13 | : m_statement(std::move(statement)) 14 | { 15 | } 16 | StatementResult SimpleArrowStatementEvaluator::evaluate(Environment & environment) const 17 | { 18 | auto const expression = m_statement.getExpression(); 19 | auto evaluated = expression->getEvaluator()->evaluate(environment); 20 | auto receiver = m_statement.getIdentifier(); 21 | auto evaluator = receiver->getEvaluator(); 22 | evaluator->evaluate(std::move(evaluated), environment); 23 | return StatementResult::Continue; 24 | } 25 | } -------------------------------------------------------------------------------- /src/statements/evaluator/SimpleArrowStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/SimpleArrowStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class SimpleArrowStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | SimpleArrowStatementEvaluator(SimpleArrowStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | SimpleArrowStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/statements/evaluator/StatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "representation/Environment.hpp" 6 | #include 7 | 8 | namespace arrow { 9 | 10 | enum class StatementResult { 11 | Break, 12 | Return, 13 | Continue, 14 | Exit 15 | }; 16 | 17 | class StatementEvaluator 18 | { 19 | public: 20 | virtual StatementResult evaluate(Environment&) const = 0; 21 | }; 22 | } -------------------------------------------------------------------------------- /src/statements/evaluator/WhileStatementEvaluator.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #include "WhileStatementEvaluator.hpp" 4 | #include "expressions/evaluator/ExpressionEvaluator.hpp" 5 | #include "parser/LanguageException.hpp" 6 | #include "statements/ElseIfStatement.hpp" 7 | #include 8 | 9 | namespace arrow { 10 | 11 | WhileStatementEvaluator::WhileStatementEvaluator(WhileStatement statement) 12 | : m_statement(std::move(statement)) 13 | { 14 | } 15 | 16 | StatementResult WhileStatementEvaluator::evaluate(Environment & environment) const 17 | { 18 | auto expressionEvaluator = m_statement.getExpression()->getEvaluator(); 19 | auto resolved = expressionEvaluator->evaluate(environment); 20 | if(resolved.m_descriptor != TypeDescriptor::Bool) { 21 | throw LanguageException("Bad type or while statement expression", 22 | m_statement.getLineNumber()); 23 | } 24 | auto booleanVal = std::get(resolved.m_variantType); 25 | auto innerStatement = m_statement.getInnerStatement(); 26 | while(booleanVal) { 27 | environment.pushEnvironmentLayer(); 28 | auto evaluated = innerStatement->getEvaluator()->evaluate(environment); 29 | environment.popEnvironmentLayer(); 30 | if(evaluated == StatementResult::Break) { 31 | break; 32 | } else if(evaluated == StatementResult::Return || 33 | evaluated == StatementResult::Exit) { 34 | return evaluated; 35 | } 36 | resolved = expressionEvaluator->evaluate(environment); 37 | booleanVal = std::get(resolved.m_variantType); 38 | } 39 | return StatementResult::Continue; 40 | } 41 | } -------------------------------------------------------------------------------- /src/statements/evaluator/WhileStatementEvaluator.hpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 2 | 3 | #pragma once 4 | 5 | #include "StatementEvaluator.hpp" 6 | #include "statements/WhileStatement.hpp" 7 | #include "representation/Environment.hpp" 8 | #include 9 | 10 | namespace arrow { 11 | class WhileStatementEvaluator : public StatementEvaluator 12 | { 13 | public: 14 | explicit WhileStatementEvaluator(WhileStatement statement); 15 | StatementResult evaluate(Environment&) const override; 16 | private: 17 | WhileStatement m_statement; 18 | }; 19 | } -------------------------------------------------------------------------------- /src/utility/ThreadManager.cpp: -------------------------------------------------------------------------------- 1 | /// (c) Ben Jones 2019 - present 2 | 3 | #include "ThreadManager.hpp" 4 | 5 | namespace arrow { 6 | std::vector ThreadManager::m_threads; 7 | void ThreadManager::create(std::function f) 8 | { 9 | m_threads.emplace_back(std::move(f)); 10 | } 11 | void ThreadManager::joinAll() 12 | { 13 | for(auto & t : m_threads) { 14 | t.join(); 15 | } 16 | } 17 | void ThreadManager::clear() 18 | { 19 | m_threads.clear(); 20 | } 21 | } -------------------------------------------------------------------------------- /src/utility/ThreadManager.hpp: -------------------------------------------------------------------------------- 1 | /// Ben Jones 2019 - present 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace arrow { 10 | 11 | /// A hacky global thread manager for handling threads 12 | class ThreadManager 13 | { 14 | public: 15 | static void create(std::function f); 16 | static void joinAll(); 17 | static void clear(); 18 | private: 19 | static std::vector m_threads; 20 | }; 21 | } -------------------------------------------------------------------------------- /src/utility/from_string.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace arrow { 5 | template 6 | T from_string(std::string const & str) 7 | { 8 | T result; 9 | std::istringstream(str) >> result; 10 | return result; 11 | } 12 | } --------------------------------------------------------------------------------