コード例 #1
0
        public static IStringable BuildStrNumNum(string name, List <Argument> args)
        {
            if (args.Count != 3)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 3 arguments: one text and two numbers.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);
            INumerable  inu1 = NumerableBuilder.Build(args[1].tokens);
            INumerable  inu2 = NumerableBuilder.Build(args[2].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (inu1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as number.");
            }
            if (inu2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Third argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("substring"))
            {
                return(new FuncSubstring__3args(istr, inu1, inu2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
コード例 #2
0
        // functions are grouped by their arguments
        // every set of arguments is one method below
        // exception for substring - has it's own methods

        public static IStringable BuildNum(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 numeric argument.");
            }

            INumerable inu = NumerableBuilder.Build(args[0].tokens);

            if (inu.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("hex"))
            {
                return(new FuncHex(inu));
            }
            else if (name.Equals("binary"))
            {
                return(new FuncBinary(inu));
            }
            else if (name.Equals("month"))
            {
                return(new FuncMonth(inu));
            }
            else if (name.Equals("weekday"))
            {
                return(new FuncWeekday(inu));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
コード例 #3
0
        public static IStringable BuildStrNum(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: one text and one number.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);
            INumerable  inu  = NumerableBuilder.Build(args[1].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (inu.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("filled") || name.Equals("fill"))
            {
                return(new FuncFilled(istr, inu));
            }
            else if (name.Equals("repeat") || name.Equals("repeated"))
            {
                return(new FuncRepeat(istr, inu));
            }
            else if (name.Equals("substring"))
            {
                return(new FuncSubstring__2args(istr, inu));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
コード例 #4
0
ファイル: TimeFunction.cs プロジェクト: nathaliefil/uroboros
        public static ITimeable BuildNumNum(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 numeric arguments.");
            }

            INumerable inu1 = NumerableBuilder.Build(args[0].tokens);
            INumerable inu2 = NumerableBuilder.Build(args[1].tokens);

            if (inu1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as number.");
            }
            if (inu2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("tomorrow"))
            {
                return(new FuncTomorrow__2args(inu1, inu2));
            }
            else if (name.Equals("yesterday"))
            {
                return(new FuncYesterday__2args(inu1, inu2));
            }
            else if (name.Equals("today"))
            {
                return(new FuncToday__2args(inu1, inu2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
コード例 #5
0
ファイル: TimeFunction.cs プロジェクト: nathaliefil/uroboros
        public static ITimeable BuildNum(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 numeric argument.");
            }

            INumerable inu = NumerableBuilder.Build(args[0].tokens);

            if (inu.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("newyear"))
            {
                return(new FuncNewyear(inu));
            }
            else if (name.Equals("christmas"))
            {
                return(new FuncChristmas(inu));
            }
            else if (name.Equals("easter"))
            {
                return(new FuncEaster(inu));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
コード例 #6
0
        public static IStringable BuildListElement(List <Token> tokens)
        {
            if (Brackets.ContainsIndependentBracketsPairs(tokens, BracketsType.Square))
            {
                return(null);
            }

            string name = tokens[0].GetContent();

            tokens.RemoveAt(tokens.Count - 1);
            tokens.RemoveAt(0);
            tokens.RemoveAt(0);

            if (!InterVariables.GetInstance().Contains(name, InterVarType.List))
            {
                throw new SyntaxErrorException("ERROR! List " + name + " not found. Impossible to take element from it.");
            }

            INumerable inu = NumerableBuilder.Build(tokens);

            if (inu.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Impossible to take element from list " + name + ". Index identificator cannot be read as number.");
            }
            else
            {
                return(new ListElementRefer(name, inu));
            }
        }
コード例 #7
0
        public static INumerable BuildNumericTernary(List <Token> tokens)
        {
            IBoolable condition = BoolableBuilder.Build(GetTernaryCondition(tokens));

            if (condition.IsNull())
            {
                return(null);
            }

            INumerable confirmationCase = NumerableBuilder.Build(GetTernaryConfirmation(tokens));

            if (confirmationCase.IsNull())
            {
                return(null);
            }

            INumerable negationCase = NumerableBuilder.Build(GetTernaryNegation(tokens));

            if (negationCase.IsNull())
            {
                return(null);
            }

            return(new NumericTernary(condition, confirmationCase, negationCase));
        }
コード例 #8
0
 public INumerable Multiply(INumerable num)
 {
     if (num is RealNumber)
     {
         return(new RealNumber(Value * ((RealNumber)num).Value));
     }
     else
     {
         return(new RealNumber(0));
     }
 }
コード例 #9
0
 public INumerable Subtract(INumerable num)
 {
     if (num is StreamableComplex compl)
     {
         return(new StreamableComplex(Value - compl.Value));
     }
     else
     {
         return(new StreamableComplex(0));
     }
 }
コード例 #10
0
 public INumerable Subtract(INumerable num)
 {
     if (num is StreamableNumber)
     {
         return(new StreamableNumber(Value - ((StreamableNumber)num).Value));
     }
     else
     {
         return(new StreamableNumber(0));
     }
 }
コード例 #11
0
 public INumerable Add(INumerable num)
 {
     if (num is StreamableNumber)
     {
         return(new StreamableNumber(Value + ((StreamableNumber)num).Value));
     }
     else
     {
         return(new StreamableNumber(0));
     }
 }
コード例 #12
0
 public INumerable Multiply(INumerable num)
 {
     if (num is StreamableNumber)
     {
         return(new StreamableNumber(Value * ((StreamableNumber)num).Value));
     }
     else
     {
         return(new StreamableNumber(0));
     }
 }
コード例 #13
0
 public INumerable Subtract(INumerable num)
 {
     if (num is RealNumber)
     {
         return(new RealNumber(Value - ((RealNumber)num).Value));
     }
     else
     {
         return(new RealNumber(0));
     }
 }
コード例 #14
0
 public INumerable Divide(INumerable num)
 {
     if (num is ComplexNumber compl)
     {
         return(new ComplexNumber(Value / compl.Value));
     }
     else
     {
         return(new ComplexNumber(0));
     }
 }
コード例 #15
0
 public INumerable Subtract(INumerable num)
 {
     if (num is ComplexNumber compl)
     {
         return(new ComplexNumber(Value - compl.Value));
     }
     else
     {
         return(new ComplexNumber(0));
     }
 }
コード例 #16
0
 public INumerable Multiply(INumerable num)
 {
     if (num is StreamableComplex compl)
     {
         return(new StreamableComplex(Value * compl.Value));
     }
     else
     {
         return(new StreamableComplex(0));
     }
 }
コード例 #17
0
 public INumerable Add(INumerable num)
 {
     if (num is StreamableComplex compl)
     {
         return(new StreamableComplex(Value + compl.Value));
     }
     else
     {
         return(new StreamableComplex(0));
     }
 }
コード例 #18
0
 public INumerable Multiply(INumerable num)
 {
     if (num is ComplexNumber compl)
     {
         return(new ComplexNumber(Value * compl.Value));
     }
     else
     {
         return(new ComplexNumber(0));
     }
 }
コード例 #19
0
 public INumerable Add(INumerable num)
 {
     if (num is RealNumber)
     {
         return(new RealNumber(Value + ((RealNumber)num).Value));
     }
     else
     {
         return(new RealNumber(0));
     }
 }
コード例 #20
0
 public static INumerable BuildNegated(INumerable inum)
 {
     if (inum is NumericConstant)
     {
         (inum as NumericConstant).SetNegative();
         return(inum);
     }
     else
     {
         return(new NegatedNumerable(inum));
     }
 }
コード例 #21
0
        public static ISubcommand BuildNumeric(List <Token> tokens, TokenType type)
        {
            INumerable inu = NumerableBuilder.Build(tokens);

            if (inu.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In list declaration there is something wrong with expression: " + GetName(type) + ".");
            }
            else
            {
                return(new NumericSubcommand(inu, GetNumericType(type)));
            }
        }
コード例 #22
0
        private static IBoolable BuildBetweenNumbers(INumerable num, List <Token> left, List <Token> right)
        {
            INumerable numLeft  = NumerableBuilder.Build(left);
            INumerable numRight = NumerableBuilder.Build(right);

            if (numLeft.IsNull() || numRight.IsNull())
            {
                return(null);
            }
            else
            {
                return(new BetweenNumbers(num, numLeft, numRight));
            }
        }
コード例 #23
0
ファイル: DiagonalMatrix.cs プロジェクト: sunshykin/OOP.Labs
        public INumerable Add(INumerable num)
        {
            if (num is DiagonalMatrix matr)
            {
                var newMatrix = new ComplexNumber[Dimension, Dimension];
                for (int i = 0; i < Dimension; i++)
                {
                    newMatrix[i, i] = Value[i, i].Add(matr.Value[i, i]) as ComplexNumber;
                }

                return(new DiagonalMatrix(newMatrix));
            }
            else
            {
                return(new DiagonalMatrix(1));
            }
        }
コード例 #24
0
        public static INumerable BuildNums(string name, List <Argument> args)
        {
            if (args.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have at least one numeric argument.");
            }

            List <INumerable> inus = new List <INumerable>();

            for (int i = 0; i < args.Count; i++)
            {
                INumerable inu = NumerableBuilder.Build(args[i].tokens);
                if (inu.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! Argument " + (i + 1) + " of function " + name + " cannot be read as number.");
                }
                else
                {
                    inus.Add(inu);
                }
            }

            if (name.Equals("max"))
            {
                return(new FuncMax(inus));
            }
            else if (name.Equals("min"))
            {
                return(new FuncMin(inus));
            }
            else if (name.Equals("average") || name.Equals("avg") || name.Equals("mean"))
            {
                return(new FuncAverage(inus));
            }
            else if (name.Equals("sum"))
            {
                return(new FuncSum(inus));
            }
            else if (name.Equals("product"))
            {
                return(new FuncProduct(inus));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
コード例 #25
0
        private static IBoolable BuildBetween(List <Token> tokens)
        {
            int betweenIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.Between);
            int andIndex     = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.And);

            if (andIndex < betweenIndex)
            {
                return(null);
            }

            if (betweenIndex == andIndex - 1)
            {
                throw new SyntaxErrorException("ERROR! Expression 'between' do not contain definition of value of left boundary.");
            }

            if (betweenIndex == 0)
            {
                throw new SyntaxErrorException("ERROR! Expression 'between' starts with keyword 'between' and thus do not contain comparing value.");
            }

            if (andIndex == tokens.Count - 1)
            {
                throw new SyntaxErrorException("ERROR! Expression 'between' ends with keyword 'and' and thus do not contain definition of value of right boundary.");
            }

            List <Token> valueTokens = tokens.Take(betweenIndex).ToList();
            List <Token> leftTokens  = tokens.GetRange(betweenIndex + 1, andIndex - betweenIndex - 1);
            List <Token> rightTokens = tokens.Skip(andIndex + 1).ToList();

            INumerable inum = NumerableBuilder.Build(valueTokens);

            if (!inum.IsNull())
            {
                return(BuildBetweenNumbers(inum, leftTokens, rightTokens));
            }

            ITimeable itim = TimeableBuilder.Build(valueTokens);

            if (!itim.IsNull())
            {
                return(BuildBetweenTimes(itim, leftTokens, rightTokens));
            }

            return(null);
        }
コード例 #26
0
        public static ICommand Build(List <Token> tokens)
        {
            tokens.RemoveAt(0);
            if (tokens.Count == 0)
            {
                return(new Sleep(new NumericConstant(1)));
            }
            INumerable inum = NumerableBuilder.Build(tokens);

            if (inum.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Sleeping time cannot be read as number.");
            }
            else
            {
                return(new Sleep(inum));
            }
        }
コード例 #27
0
        static void Main(string[] args)
        {
            var hands    = new HandHeldInventory(new Sword(), new Shield());
            var knapsack = new KnapsackInventory(new List <Item>(new Item[] {
                new Apple(),
                new Medicine(),
                new Potion(),
                new SpellBook(),
                new Wand()
            }));

            INumerable inventory = knapsack;
            INumerator numerator = inventory.GetNumerator();

            while (!numerator.IsDone())
            {
                Console.WriteLine(numerator.CurrentItem().ToString().Split('.').Last());
                numerator.Next();
            }
        }
コード例 #28
0
        public static ICommand Build(List <Token> tokens)
        {
            string name = tokens[0].GetContent();

            tokens.RemoveAt(0);
            tokens.RemoveAt(0);

            List <Token> indexTokens = new List <Token>();

            while (tokens.First().GetTokenType() != TokenType.SquareBracketOff)
            {
                indexTokens.Add(tokens.First());
                tokens.RemoveAt(0);
            }
            tokens.RemoveAt(0);

            INumerable index = NumerableBuilder.Build(indexTokens);

            if (index.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Index of element of list " + name + " cannot be read as number.");
            }
            if (tokens.First().GetTokenType() != TokenType.Equals)
            {
                return(null);
            }

            tokens.RemoveAt(0);

            IStringable newValue = StringableBuilder.Build(tokens);

            if (newValue.IsNull())
            {
                return(null);
            }

            return(new ListElementDeclaration(name, newValue, index));
        }
コード例 #29
0
        public static ICommand Build(List <Token> tokens)
        {
            string    name = tokens[0].GetContent();
            TokenType type = tokens[1].GetTokenType();

            tokens.RemoveAt(0);
            tokens.RemoveAt(0);

            if (InterVariables.GetInstance().ContainsChangable(name, InterVarType.Number) &&
                !InterVariables.GetInstance().Contains(name, InterVarType.Bool))
            {
                INumerable value = NumerableBuilder.Build(tokens);
                if (value.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! Changing value of variable " + name + " cannot be performed, because expression value is not a number.");
                }

                switch (type)
                {
                case TokenType.PlusEquals:
                    return(new IncrementBy(name, value));

                case TokenType.MinusEquals:
                    return(new DecrementBy(name, value));

                case TokenType.MultiplyEquals:
                    return(new MultiplyBy(name, value));

                case TokenType.DivideEquals:
                    return(new DivideBy(name, value));

                case TokenType.PercentEquals:
                    return(new ModuloBy(name, value));
                }
            }
            throw new SyntaxErrorException("ERROR! Value of variable " + name + " cannot be changed.");
        }
コード例 #30
0
 public NumericComparison(INumerable leftSide, INumerable rightSide, ComparisonType type)
 {
     this.leftSide  = leftSide;
     this.rightSide = rightSide;
     this.type      = type;
 }