Esempio n. 1
0
        public override TokenList Simplify(IToken first, IToken last)
        {
            if (first == null)
                throw new Exception($"Operation {Text} can not be unary.");

            TokenList lastList = last.Simplify();
            if (lastList == null || lastList.Count != 1)
                throw new Exception($"Second element of Operation {Text} is not unique.");

            IntToken intToken = lastList[0] as IntToken;
            if (intToken == null)
                throw new Exception($"Operation {Text} must have integer second element.");

            return new TokenList(first.Simplify()[intToken.Value]);
        }
Esempio n. 2
0
        public virtual TokenList Simplify(IToken first, IToken last)
        {
            if (first == null)
            {
                if (CanBeUnary)
                {
                    ITypeToken secondType = last?.Simplify()[0] as ITypeToken;
                    return secondType != null ? Evaluate(secondType) : new TokenList(new ExpressionToken(null, this, last));
                }
                throw new Exception($"Operation {Text} can not be unary.");
            }

            if (CanBeBinary)
            {
                ITypeToken firstType = first.Simplify()[0] as ITypeToken;
                ITypeToken secondType = last?.Simplify()[0] as ITypeToken;
                return firstType != null && secondType != null ? Evaluate(firstType, secondType) : new TokenList(new ExpressionToken(first, this, last));
            }

            throw new Exception($"Operation {Text} can not be binary.");
        }