private void FillTables() { KeywordsList.AddRange(Tokens.Where(t => t.HasType(TokenType.Keyword)).Select(t => t.Value).Distinct()); OperatorsList.AddRange(Tokens.Where(t => t.HasType(TokenType.Operator)).Select(t => t.Value).Distinct()); FunctionsList.AddRange(Tokens.Where(t => t.HasType(TokenType.Function)).Select(t => t.Value).Distinct()); IdentifiersList.AddRange(Tokens.Where(t => t.HasType(TokenType.Identifier)).Select(t => t.Value).Distinct()); ConstantsList.AddRange(Tokens.Where(t => t.HasOneOfTypes(TokenType.CharConstant, TokenType.IntegerConstant, TokenType.FloatConstant, TokenType.StringConstant)).Select(t => t.Value.Escape()).Distinct()); }
public void Init() { OperatorsList <double> operators = new OperatorsList <double>(); operators.Add('+', new DoubleAdditionOperator(OperatorsPriority.Low)); operators.Add('-', new DoubleSubstractOperator(OperatorsPriority.Low)); operators.Add('*', new DoubleMultiplicationOperator(OperatorsPriority.Medium)); operators.Add('/', new DoubleDivisionOperator(OperatorsPriority.Medium)); calc = new ExpressionCalculator(operators); }
static void Main(string[] args) { string mathExpression = Console.ReadLine(); OperatorsList <double> operators = new OperatorsList <double>(); operators.Add('+', new DoubleAdditionOperator(OperatorsPriority.Low)); operators.Add('-', new DoubleSubstractOperator(OperatorsPriority.Low)); operators.Add('*', new DoubleMultiplicationOperator(OperatorsPriority.Medium)); operators.Add('/', new DoubleDivisionOperator(OperatorsPriority.Medium)); ExpressionCalculator calculator = new ExpressionCalculator(operators); Console.WriteLine(calculator.Solve(mathExpression)); Console.ReadKey(); }
public void SplitCurrenciesWithValues(string leftPart) { int z = 0; var elements = leftPart.Split(' '); foreach (var x in elements) { z++; if (z % 2 != 0) { CurrenciesWithValues.Add(x); } else { OperatorsList.Add(x); } } if (z % 2 == 0) { throw new ArgumentException($"{Constants.WrongInputMessage}:Некорректно введен оператор"); } }
public void DisplayExpression(int problemNumber, int operandx, int operandy, OperatorsList operatorParam) { switch (operatorParam) { case OperatorsList.Addition: ConsoleUiOperator = "+"; break; case OperatorsList.Subtraction: ConsoleUiOperator = "-"; break; case OperatorsList.Multiplication: ConsoleUiOperator = "*"; break; case OperatorsList.Division: ConsoleUiOperator = "/"; break; } Console.WriteLine($"Problem {problemNumber}: {operandx} {ConsoleUiOperator} {operandy}"); Console.WriteLine(" "); Console.WriteLine(" "); }