Esempio n. 1
0
 public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                            IDictionary <string, VariableValue> variables,
                            IDictionary <string, CustomFunctionOverload> functions)
 {
     _variableName = element.Token.Text;
     _variables    = variables;
 }
Esempio n. 2
0
        public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                                   IDictionary <string, VariableValue> variables,
                                   IDictionary <string, CustomFunctionOverload> functions)
        {
            ValueType  = ValueType.Tuple;
            TupleValue = new List <Node>();

            if (!rpnStack.TryPop(out var rightNode) || !rpnStack.TryPop(out var leftNode))
            {
                throw new ParserException(element.Token, "Cannot find values to create parameter list");
            }

            if (leftNode.ValueType == ValueType.Tuple)
            {
                // unfold tuple list
                foreach (var parameter in leftNode.TupleValue)
                {
                    TupleValue.Add(parameter);
                }
            }
            else
            {
                TupleValue.Add(leftNode);
            }

            TupleValue.Add(rightNode);
        }
Esempio n. 3
0
 public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                            IDictionary <string, VariableValue> variables,
                            IDictionary <string, CustomFunctionOverload> functions)
 {
     if (!rpnStack.TryPop(out _rightNode) || !rpnStack.TryPop(out _leftNode))
     {
         throw new ParserException(element.Token, "Cannot find tokens to sequence");
     }
 }
Esempio n. 4
0
        public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                                   IDictionary <string, VariableValue> variables,
                                   IDictionary <string, CustomFunctionOverload> functions)
        {
            ValueType = ValueType.Boolean;

            if (!rpnStack.TryPop(out _childNode))
            {
                throw new ParserException(element.Token, "Cannot find value to perform negate operation on");
            }
        }
Esempio n. 5
0
        public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                                   IDictionary <string, VariableValue> variables,
                                   IDictionary <string, CustomFunctionOverload> functions)
        {
            if (!rpnStack.TryPop(out _rightNode) || !rpnStack.TryPop(out _leftNode))
            {
                throw new ParserException(element.Token, "Cannot find values to perform arithmetic operation on");
            }

            _operator = element.Type;
        }
        public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                                   IDictionary <string, VariableValue> variables,
                                   IDictionary <string, CustomFunctionOverload> functions)
        {
            ValueType      = ValueType.Boolean;
            _operationType = element.Type;

            if (!rpnStack.TryPop(out _rightNode) || !rpnStack.TryPop(out _leftNode))
            {
                throw new ParserException(element.Token, NodesNotAvailableErrorMessage);
            }
        }
Esempio n. 7
0
        public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                                   IDictionary <string, VariableValue> variables,
                                   IDictionary <string, CustomFunctionOverload> functions)
        {
            if ((options & Compiler.Options.Immutable) == Compiler.Options.Immutable)
            {
                throw new ParserException(element.Token, "An assignment operator cannot be used for an immutable script");
            }

            _assignmentType = element.Type;

            if (!rpnStack.TryPop(out _rightNode) || !rpnStack.TryPop(out _leftNode))
            {
                throw new ParserException(element.Token, "Cannot find elements to perform assignment operation on");
            }
        }
Esempio n. 8
0
        public static Node Build(List <Element> elements, Compiler.Options options,
                                 IDictionary <string, VariableValue> variables,
                                 IDictionary <string, CustomFunctionOverload> functions)
        {
            var rpnStack = new Stack <Node>();

            foreach (var element in elements)
            {
                var node = CreateNode(element.Type);
                node.Build(rpnStack, element, options, variables, functions);
                rpnStack.Push(node);
            }

            if (rpnStack.Count > 1)
            {
                throw new RuntimeException("Missing operator(s) to process all values");
            }

            return(rpnStack.Pop());
        }
Esempio n. 9
0
        public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                                   IDictionary <string, VariableValue> variables,
                                   IDictionary <string, CustomFunctionOverload> functions)
        {
            if (!functions.TryGetValue(element.Token.Text, out _functionOverload))
            {
                throw new ParserException(element.Token, $"Undefined function: {element.Token.Text}");
            }

            if (!rpnStack.TryPop(out var childNode))
            {
                throw new ParserException(element.Token, $"Cannot find parameters for calling function: {element.Token.Text}");
            }

            switch (childNode.ValueType)
            {
            case ValueType.Boolean:
            case ValueType.Float:
            case ValueType.Integer:
            case ValueType.Undefined:
                _parameters = new List <Node>();
                _parameters.Add(childNode);
                _parameterTypes = new Type[1];
                break;

            case ValueType.Tuple:
                _parameters     = childNode.TupleValue;
                _parameterTypes = new Type[_parameters.Count];
                break;

            case ValueType.Null:
                _parameterTypes = Array.Empty <Type>();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(childNode.ValueType), childNode.ValueType,
                                                      "Unsupported child not value type");
            }
        }
Esempio n. 10
0
 public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                            IDictionary <string, VariableValue> variables,
                            IDictionary <string, CustomFunctionOverload> functions)
 {
     ValueType = ValueType.Null;
 }
Esempio n. 11
0
 public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                            IDictionary <string, VariableValue> variables,
                            IDictionary <string, CustomFunctionOverload> functions)
 {
     Initialize(element.Type == ElementType.BooleanLiteralTrue);
 }
Esempio n. 12
0
 public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                            IDictionary <string, VariableValue> variables,
                            IDictionary <string, CustomFunctionOverload> functions)
 {
     Initialize(int.Parse(element.Token.Text));
 }
Esempio n. 13
0
 public abstract void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                            IDictionary <string, VariableValue> variables,
                            IDictionary <string, CustomFunctionOverload> functions);
Esempio n. 14
0
 public override void Build(Stack <Node> rpnStack, Element element, Compiler.Options options,
                            IDictionary <string, VariableValue> variables,
                            IDictionary <string, CustomFunctionOverload> functions)
 {
     throw new System.NotImplementedException("Fake nodes cannot be built from RPN srack");
 }