private void AddStep(object sender, EventArgs e) { if (CheckStep() == true) { Instruction.Add(new Instruct(EditStep.Text, id)); id++; EditStep.Text = ""; } else { DisplayAlert(Resource.Error, Resource.ErrorStep, Resource.Ok); } }
private static Instruction GetInstructions(ParserState state, Token previous) { Instruction inst = new Instruction(); do { if (state.PeepToken().Name == ",") { state.PopToken(); } Token open = state.PopToken(); if (open == null || open.Name != "(") { previous.ThrowException("Expected program format: (A1,G1),(A2,G2),...,(An,Gn)"); } Token a = state.PopToken(); if (a == null) { open.ThrowException("Expected action"); } if (a.Name == ")") { return(inst); } if (state.Action.ContainsKey(a.Name) == false) { open.ThrowException("Expected action"); } Token comma = state.PopToken(); if (comma == null || comma.Name != ",") { a.ThrowException("Comma should separate an action and a set of agents"); } MultiAgentLanguageModels.Action a1 = new MultiAgentLanguageModels.Action(a.Name); AgentsList g = GetAgentList(state); Token close = state.PopToken(); if (close == null || close.Name != ")") { a.ThrowException("Expected )"); } inst.Add(new Tuple <MultiAgentLanguageModels.Action, AgentsList>(a1, g)); } while (state.PeepToken() != null && state.PeepToken().Name == ","); return(inst); }
private Instruction GetComboInstruction(CharReader cr) { var newInstruction = new Instruction(InstructionType.Combo); while (cr.HasCharacters()) { var c = cr.GetChar(); if (c == '[' || c == ']' || c == '.' || c == ',') { break; } if (c == '+') { newInstruction.Add(); } if (c == '-') { newInstruction.Subtract(); } if (c == '<') { newInstruction.ShiftLeft(); } if (c == '>') { newInstruction.ShiftRight(); } cr.Forward(); } cr.Back(); newInstruction.Complete(); return(newInstruction); }