Exemple #1
0
        ExpressionNode GetCompareNode(IList <Token> tokens, ref int index)
        {
            ExpressionNode node  = GetBitOperatorNode(tokens, ref index);
            int            count = tokens.Count;

            while (index < count)
            {
                Token token = tokens[index];

                switch (token.Type)
                {
                case TokenType.XTLO:
                case TokenType.XYLO:
                case TokenType.CLO:
                case TokenType.NIV:
                case TokenType.LLO:
                case TokenType.XOLO:
                case TokenType.XTLONYS:
                case TokenType.XYLONYS:
                case TokenType.LLONYS:
                case TokenType.XOLONYS:
                    index++;
                    {
                        var op = new BiOperatorNode
                        {
                            Operator = token.Type,
                            Left     = node,
                            Right    = GetBitOperatorNode(tokens, ref index),
                        };

                        if (op.Right == null || (op.Left == null && op.Right != null))
                        {
                            throw new ApplicationException($"Invalid arguments: {token.Type}(Left: {op.Left}, Right: {op.Right})");
                        }
                        else
                        {
                            node = op;
                        }
                    }
                    break;

                default:
                    return(node);
                }
            }

            return(node);
        }
Exemple #2
0
        private ExpressionNode GetArrayPosNode(IList <Token> tokens, ref int index)
        {
            ExpressionNode node  = GetValueNode(tokens, ref index);
            int            count = tokens.Count;

            while (index < count)
            {
                Token token = tokens[index];

                switch (token.Type)
                {
                case TokenType.ARRAY_SIGN:
                    index++;
                    {
                        var op = new BiOperatorNode
                        {
                            Operator = token.Type,
                            Left     = node,
                            Right    = GetArrayPosNode(tokens, ref index),
                        };

                        if (op.Right == null || ((op.Left == null || op.Left is ConstantNode) && op.Right != null))
                        {
                            throw new ApplicationException($"Invalid arguments: {token.Type}(Left: {op.Left}, Right: {op.Right})");
                        }
                        else
                        {
                            node = op;
                        }
                    }
                    break;

                default:
                    return(node);
                }
            }

            return(node);
        }