public void TestCode() { var list = new List <Item> { new Item { Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20 }, new Item { Name = "Aged Brie", SellIn = 2, Quality = 0 }, new Item { Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7 }, new Item { Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80 }, new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 15, Quality = 20 }, new Item { Name = "Conjured Mana Cake", SellIn = 3, Quality = 6 } }; INewFunction app = new NewFunction(list); app.UpdateQuality(); Assert.True(true); }
private void functionToolStripMenuItem_Click(object sender, EventArgs e) { if (Usermanager.Connection.CurrentUser.Database != null) { var form = new NewFunction(tool, Usermanager); form.Show(); } else { MessageBox.Show("You must Login to a Database", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public bool addFunction(NewFunction windowToShow) { String[] parameters = new String[4]; Polynomial newFunction = new Polynomial(); if ((bool)windowToShow.ShowDialog()) { newFunction.name = windowToShow.nameFunction; newFunction.function = windowToShow.newFunction; newFunction.drawingColor = windowToShow.color; newFunction.xMin = windowToShow.xMin; newFunction.xMax = windowToShow.xMax; newFunction.yMin = windowToShow.yMin; newFunction.yMax = windowToShow.yMax; if (windowToShow.parameterA.IsEnabled) parameters[0] = windowToShow.parameterA.Text; else parameters[0] = "-"; if (windowToShow.parameterB.IsEnabled) parameters[1] = windowToShow.parameterB.Text; else parameters[1] = "-"; if (windowToShow.parameterC.IsEnabled) parameters[2] = windowToShow.parameterC.Text; else parameters[2] = "-"; if (windowToShow.parameterN.IsEnabled) parameters[3] = windowToShow.parameterN.Text; else parameters[3] = "-"; newFunction.plot.Points = calculatePointCollection(newFunction, parameters); if (newFunction.plot.Points.Count != 0) { functions.Add(newFunction); return true; } else { MessageBox.Show("Could not calculate the function", "New Function", MessageBoxButton.OK, MessageBoxImage.Exclamation); return false; } } return false; }
public override INamespaceSet GetMember(Parsing.Ast.Node node, Interpreter.AnalysisUnit unit, string name) { if (name == "__new__") { if (_new == null) { var func = this._type.GetMember(unit.ProjectEntry.MyScope.InterpreterContext, name); if (func != null) { _new = new NewFunction((BuiltinFunctionInfo)unit.ProjectState.GetNamespaceFromObjects(func), ProjectState); } } if (_new != null) { return _new.SelfSet; } } return base.GetMember(node, unit, name); }
private void OnLevelChanged(IEvent ievent) { var level = PlayerDataManager.Instance.GetRes((int)eResourcesType.LevelRes); NewFunction newFun = null; foreach (var item in NewFunctionList) { if (CurrentLevel < item.Level && level >= item.Level) { newFun = item; } } CurrentLevel = level; if (null != newFun) { Show(newFun.Go, newFun.Btn); } }
public bool addFunction(NewFunction windowToShow) { String[] parameters = new String[4]; Polynomial newFunction = new Polynomial(); if ((bool)windowToShow.ShowDialog()) { newFunction.name = windowToShow.nameFunction; newFunction.function = windowToShow.newFunction; newFunction.drawingColor = windowToShow.color; newFunction.xMin = windowToShow.xMin; newFunction.xMax = windowToShow.xMax; newFunction.yMin = windowToShow.yMin; newFunction.yMax = windowToShow.yMax; if (windowToShow.parameterA.IsEnabled) { parameters[0] = windowToShow.parameterA.Text; } else { parameters[0] = "-"; } if (windowToShow.parameterB.IsEnabled) { parameters[1] = windowToShow.parameterB.Text; } else { parameters[1] = "-"; } if (windowToShow.parameterC.IsEnabled) { parameters[2] = windowToShow.parameterC.Text; } else { parameters[2] = "-"; } if (windowToShow.parameterN.IsEnabled) { parameters[3] = windowToShow.parameterN.Text; } else { parameters[3] = "-"; } newFunction.plot.Points = calculatePointCollection(newFunction, parameters); if (newFunction.plot.Points.Count != 0) { functions.Add(newFunction); return(true); } else { MessageBox.Show("Could not calculate the function", "New Function", MessageBoxButton.OK, MessageBoxImage.Exclamation); return(false); } } return(false); }
public Packer(NewFunction @new, GetBinariesFunction getBinaries) { _new = @new; _getBinaries = getBinaries; }
/// <summary> /// Парсит тела конструкций, в том числе и новой функции. /// </summary> public static void Parse(TokenList tokens, out int counter, bool isRoot = false) { counter = 0; while (counter < tokens.Count) { BaseGenerator generator = CodeManager.GetGenerator(parseMode); TokenList nextTokens = tokens.GetRange(counter); Token currentToken = tokens[counter]; Token nextToken = tokens.Get(counter + 1); if (currentToken.TypeIs(TokenType.NextLine)) { lineIndex++; counter++; continue; } if (currentToken.TypeIs(TokenType.Id)) { // <variableName> = <expression>; if (nextToken.TypeIs(TokenType.AssignOperator)) { string variableName = currentToken.value; TokenList expression = nextTokens.GetRange(nextTokens.IndexOf("=") + 1, nextTokens.IndexOf(";")); generator.AddVariableAssignment(variableName, expression, isRoot); counter += nextTokens.IndexOf(";") + 1; } // <id>(<expression>); else if (nextToken.TypeIs(TokenType.BeginParenthesis)) { Token name = currentToken; TokenList attributes = GetExpressionInParenthesis(nextTokens, errors: false); if (attributes.Count == 0 && !nextTokens.Get(2).TypeIs(TokenType.EndParenthesis)) { throw new ParseException($"После '(' при вызове функции без параметров ожидалось ')', а не '{nextToken}'", lineIndex); } generator.AddFunctionCall(name, attributes); counter += nextTokens.IndexOf(";") + 1; } else { throw new ParseException($"После '{currentToken}' ожидалось '=' либо '(', а не '{nextToken}'", lineIndex); } } else if (currentToken.TypeIs(TokenType.Keyword)) { // функция <functionName>(<parameters>) { <functionBody> } if (currentToken.TypeIs(KeywordType.Function)) { NewFunction newFunction = CodeManager.NewFunction; string name = nextToken.value; TokenList parameters = GetExpressionInParenthesis(nextTokens, errors: false); TokenList body = GetBody(nextTokens, out counter, counter); if (!nextToken.TypeIs(TokenType.Id)) { throw new ParseException($"После ключевого слова 'функция' ожидалось название объявляемой функции, а не '{nextToken}'", lineIndex); } if (!nextTokens.Get(2).TypeIs(TokenType.BeginParenthesis)) { throw new ParseException($"После названия функции ожидалось '(', а не '{nextToken}'", lineIndex); } if (parameters.Count == 0 && !nextTokens.Get(3).TypeIs(TokenType.EndParenthesis)) { throw new ParseException($"После '(' при объявлении функции без параметров ожидалось ')', а не '{nextToken}'", lineIndex); } parameters.DeleteAll(","); newFunction.AddFunctionHeader(name, parameters); parseMode = ParseMode.FunctionCreation; Parse(body, out _); newFunction.Create(); parseMode = ParseMode.Default; } // если (<expresion>) { <body> } else if (currentToken.TypeIs(KeywordType.If)) { TokenList expression = GetExpressionInParenthesis(nextTokens); TokenList body = GetBody(nextTokens, out counter, counter); if (!nextToken.TypeIs(TokenType.BeginParenthesis)) { throw new ParseException($"После ')' ожидалось '{{', а не {nextToken}", lineIndex); } generator.AddIfConstruction(expression); Parse(body, out _); generator.AddConstructionEnd(); } // иначе { <body> } else if (currentToken.TypeIs(KeywordType.Else)) { TokenList body = GetBody(nextTokens, out counter, counter); generator.AddElseConstruction(); Parse(body, out _); generator.AddConstructionEnd(); } // делать { <body> } пока (<expression>) else if (currentToken.TypeIs(KeywordType.Do)) { TokenList body = GetBody(nextTokens, out counter, counter); generator.AddDoConstruction(); Parse(body, out _); generator.AddConstructionEnd(); nextTokens = tokens.GetRange(counter); currentToken = tokens[counter]; if (currentToken.TypeIs(KeywordType.While)) { TokenList expression = GetExpressionInParenthesis(nextTokens); if (expression.Count == 0) { throw new ParseException($"Конструкция 'пока' без выражения", lineIndex); } generator.AddEndingWhileConstruction(expression); counter += nextTokens.IndexOf(";") + 1; } else { throw new ParseException($"После окончания конструкции 'делать' ожидалось ключевое слово 'пока'", lineIndex); } } // пока (<expression>) { <body> } else if (currentToken.TypeIs(KeywordType.While)) { TokenList expression = GetExpressionInParenthesis(nextTokens); TokenList body = GetBody(nextTokens, out counter, counter); generator.AddWhileConstruction(expression); Parse(body, out _); generator.AddConstructionEnd(); } // пробовать { <tryBody> } отловить [(<errorValue>)] { <catchBody> } else if (currentToken.TypeIs(KeywordType.Try)) { TokenList tryBody = GetBody(nextTokens, out counter, counter); generator.AddTryConstruction(); Parse(tryBody, out _); generator.AddConstructionEnd(); nextTokens = tokens.GetRange(counter); currentToken = tokens[counter]; if (currentToken.TypeIs(KeywordType.Catch)) { TokenList expression = GetExpressionInParenthesis(nextTokens, errors: false); TokenList catchBody = GetBody(nextTokens, out counter, counter); if (expression.Count == 1 && expression[0].TypeIs(TokenType.Id)) { generator.AddCatchConstruction(expression[0]); } else { generator.AddCatchConstruction(); } Parse(catchBody, out _); generator.AddConstructionEnd(); } } // определить (<value>) { <body> } else if (currentToken.TypeIs(KeywordType.Switch)) { TokenList expression = GetExpressionInParenthesis(nextTokens); TokenList body = GetBody(nextTokens, out counter, counter); if (expression.Count == 1 && expression[0].TypeIs(TokenType.Id)) { generator.AddSwitchConstruction(expression[0]); ParseSwitch(body); generator.AddConstructionEnd(); } } // использовать ... else if (currentToken.TypeIs(KeywordType.Use)) { // ссылки "<path>" if (nextToken.TypeIs(KeywordType.Links) && nextTokens.Get(2).TypeIs(TokenType.String) && Path.GetExtension(nextTokens[2].value) == GlobalParams.linksExtention) { CodeManager.UpdateNamesMap(nextTokens[2].value); } // <id> else if (nextToken.TypeIs(TokenType.Id)) { Compilator.AddUsing(nextToken.ToString()); Compilator.AddClassRef(nextToken.ToString()); } counter += nextTokens.IndexOf(";") + 1; } // импорт ... else if (currentToken.TypeIs(KeywordType.Import)) { if (nextToken.TypeIs(TokenType.String)) { string path = nextToken.value; if (File.Exists(path)) { string extention = Path.GetExtension(path); if (extention == GlobalParams.codeExtention) { // ...... } else { Compilator.AddRef(path); } } } counter += nextTokens.IndexOf(";") + 1; } else { throw new ParseException($"На первой позиции не ожидалось ключевое слово {currentToken}", lineIndex); } } else { throw new ParseException($"Не удалось распознать слово '{currentToken}'", lineIndex); } } }
private async void HandleSys(string cmd) { switch (cmd) { case "clr": if (output.IsInputMode) { output.SendInput('*'); } else { EditFunction = null; output.OutResult = null; program.ClearItems(); } break; case "del": if (output.IsInputMode) { output.SendInput('<'); } else { program.RemoveItem(); } break; case "exe": if (output.IsInputMode) { var num = output.FinishInput(); program.AddItem($"#{num}", num.ToNumeric()); } else if (editFunc != null) { var isNew = (editFunc.Name == null); var dialog = new NewFunction(editFunc); await dialog.ShowAsync(); if (dialog.FunctionName != null) { var app = (Application.Current as App); if (isNew) { editFunc.Name = dialog.FunctionName; app.CalcManager.Functions.Add(editFunc); } editFunc.Descr = dialog.FunctionDescr; editFunc.ParamNum = dialog.ParameterCount; editFunc.Code = program.Items(); var fn = editFunc.Compile(app.Calculator); app.Calculator.SetUserFunc(editFunc.Name, fn); program.ClearItems(); EditFunction = null; } } else { try { var calc = (Application.Current as App).Calculator; var fn = calc.Compile(program.CompiledItems(), 0); output.OutResult = calc.Execute(fn); } catch (Exception e) { output.Message = e.Message; } } break; } }