// GET OBJECT public SLT.Object GetObject(Phrase var) { try { //заглушка SLT.Object result = new SLT.Scalar("", ""); // string var_name;// = ((Lexeme)var_name_ph).LValue; if (var.PhType == PhraseType.Name) { var_name = ((Lexeme)var).LValue; result = this.ParentModel.O_Cont.GetObjectByName(var_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); //if (result == null) //{ // throw new NameNotFound(var.Start, var.Length, var.Line, var_name); //} return(result); } Phrase var_name_ph = var.Value[0]; Phrase next_ph = var.Value[1]; var_name = ((Lexeme)var_name_ph).LValue; if (var_name_ph.PhType == PhraseType.Name) { result = this.ParentModel.O_Cont.GetObjectByName(var_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); //if (result == null) //{ // throw new NameNotFound(var.Start, var.Length, var.Line, var_name); //} } switch (next_ph.PhType) { case PhraseType.VectorNode: //result = this.ParentModel.O_Cont.GetVectorNode(var, this.SUBPROGRAM.Unit.Name); //result = this.ParentModel.O_Cont.GetVectorNode(var, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); result = this.ParentModel.O_Cont.GetObjectByName(var_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); if (next_ph.Value.Count == 0) { //var_name = ((Lexeme)var_name_ph).LValue; //result = this.ParentModel.O_Cont.GetObjectByName(var_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); } else { //string var_name = ((Lexeme)var_name_ph).LValue; //result = this.ParentModel.O_Cont.GetObjectByName(var_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); string inner_name = ((Lexeme)next_ph.Value[1]).LValue; Phrase inner_ph = next_ph.Value[2]; result = ((Vector)result).FindNode(inner_name, inner_ph); } break; case PhraseType.ValueFromLink: result = this.GetObjectFromLink(var_name_ph); next_ph = next_ph.Value[1].Value[1]; if (next_ph.Value.Count == 0) { //var_name = ((Lexeme)var_name_ph).LValue; //result = this.ParentModel.O_Cont.GetObjectByName(var_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); } else { //string var_name = ((Lexeme)var_name_ph).LValue; //result = this.ParentModel.O_Cont.GetObjectByName(var_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); string inner_name = ((Lexeme)next_ph.Value[1]).LValue; Phrase inner_ph = next_ph.Value[2]; result = ((Vector)result).FindNode(inner_name, inner_ph); } break; } if (result == null) { throw new ObjectNotFoundError(var.Start, var.Length, var.Line, var_name); } return(result); } catch (NameNotFound e) { throw new ObjectNotFoundError(var.Start, var.Length, var.Line, e); //throw new ObjectDoesNotExistError(e); } }
public void SetValueToScalar(string name, string unit, object value) { SLT.Scalar updated_scalar = (Scalar)this.GVT.Vars[unit].Find(o => o.Name == name); updated_scalar.SetValue(value); }
int ExecuteAction(Action action) { string unit_name = action.ParentOperator.ParentSubprogram.Unit.Name; string label; string unit; bool islast; switch (action.Name) { case ActionName.Assign: Phrase var_ph = (Phrase)action.Parameters[0]; SLT.Object var = this.GetObject(var_ph); Phrase value_ph = (Phrase)action.Parameters[1]; object value_obj; // = ConvertValueToObject(value_ph); if (value_ph.PhType == PhraseType.Initiator_Word) { //пассивизация инициатора value_obj = GetObjectFromLink(value_ph).ID; } else { value_obj = ConvertValueToObject(value_ph); } var.SetValue(value_obj); break; case ActionName.Create: string var_name = (string)action.Parameters[0]; Phrase vartype_ph = (Phrase)action.Parameters[1]; SLT.Object new_obj = new SLT.Scalar("", ""); //заглушка //для скаляра if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.ScalarVarType_Word)) { new_obj = new SLT.Scalar(var_name, unit_name); } //для вектора if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.VectorVarType_Word)) { Phrase description_line_ph = vartype_ph.Value.Find(ph => ph.PhType == PhraseType.DescriptionLine); new_obj = new SLT.Vector(var_name, unit_name, this.ParentModel.Analyzer.CreateObjectsFromDesciptionLine(description_line_ph, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name)); } //для ссылки if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.LinkVarType_Word)) { new_obj = new SLT.Link(var_name, unit_name); } //для макроса if (vartype_ph.Value.Exists(ph => ph.PhType == PhraseType.MacroVarType_Word)) { } //this.ParentModel.O_Cont.CreateObject(new_obj,this.INITIATOR.NextOperator.ParentSubprogram SUBPROGRAM.Unit.Name); this.ParentModel.O_Cont.CreateObject(new_obj, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); //list.Add(new_obj); break; case ActionName.Delete: string deleted_name = Convert.ToString(action.Parameters[0]); if (deleted_name == "True") { int deleted_id = this.INITIATOR.ID_of_MemoryCell; this.ParentModel.O_Cont.IT.Delete(deleted_id); } else { //Objects.Object del_obj= this.ParentModel.O_Cont.GetObjectByName(deleted_name,this.SUBPROGRAM.Unit.Name); SLT.Object del_obj = this.ParentModel.O_Cont.GetObjectByName(deleted_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); //if (del_obj.Unit == this.SUBPROGRAM.Unit.Name) if (del_obj.Unit == this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name) { this.ParentModel.O_Cont.DeleteObjectByID(del_obj.ID); } } break; case ActionName.Terminate: string terminated_name = Convert.ToString(action.Parameters[0]); int terminated_id = this.INITIATOR.ID_of_MemoryCell; this.ParentModel.O_Cont.DeleteInitiatorByID(terminated_id); break; case ActionName.Write_to_CT: Phrase condition; if (typeof(bool) == action.Parameters[0].GetType()) { if ((bool)action.Parameters[0]) { condition = new Phrase(PhraseType.True); } else { condition = new Phrase(PhraseType.False); } } else { condition = (Phrase)action.Parameters[0]; } string link_name = Convert.ToString(action.Parameters[1]); bool to_the_begining = (bool)action.Parameters[2]; label = (string)action.Parameters[3]; unit = (string)action.Parameters[4]; islast = (bool)action.Parameters[5]; Initiator init; Subprogram subp; try { subp = this.ParentModel.ST_Cont.FindSubprogramByLabelAndUnit(label, unit); } catch (RunTimeError e) { throw new RunTimeError(e); } if (link_name == "True") { init = this.INITIATOR; } else { //init = this.ParentModel.O_Cont.ActivateFromLink(link_name, this.SUBPROGRAM.Unit.Name); init = this.ParentModel.O_Cont.ActivateFromLink(link_name, this.INITIATOR.NextOperator.ParentSubprogram.Unit.Name); } //init.NextOperator = subp; init.NextOperator = subp.Operators[0]; if (to_the_begining) { this.TC_Cont.InsertConditionRecord(condition, init, subp, islast); } else { this.TC_Cont.AddConditionRecord(condition, init, subp, islast); } break; case ActionName.Write_to_FTT: Phrase time_exp = (Phrase)action.Parameters[0]; double time = Convert.ToDouble(this.ComputeArithmeticExpression(time_exp)); label = (string)action.Parameters[3]; unit = (string)action.Parameters[4]; islast = (bool)action.Parameters[5]; init = this.INITIATOR; subp = this.ParentModel.ST_Cont.FindSubprogramByLabelAndUnit(label, unit); this.TC_Cont.AddTimeRecord(time, init, subp, islast); break; } return(1); }