Exemple #1
0
        public LinkedList<class_types.CodeResult> ReadParametersFromIdentifier(string parameters,LinkedList<string> var_list, class_types.m_file_data input_m_file)
        {
            class_types.CodeResult clear_argument=new class_types.CodeResult();
            LinkedList<class_types.CodeResult> result = new LinkedList<class_types.CodeResult>();
            string temp_var_name;

            for (int i=0; i<var_list.Count; i++)
            {
                int start_index=-1;
                int length=-1;
                try{start_index=parameters.IndexOf(var_list.ElementAt(i));}catch{};
                if(start_index>-1)
                {
                    start_index += var_list.ElementAt(i).Length;
                    temp_var_name="";
                    clear_argument.code = "";
                    clear_argument.comment = "";
                    int comma_index=-1;
                    int parenthesis_index=-1;
                    if (parameters.Length>start_index+1)
                    {
                        try{comma_index=parameters.Substring(start_index).IndexOf(",");}catch{};
                        try{parenthesis_index=parameters.Substring(start_index).IndexOf(")");}catch{};

                        if (comma_index!=-1||parenthesis_index!=-1)
                        {
                            if (comma_index==-1)
                                length = parenthesis_index;
                            if (parenthesis_index == -1)
                                length = comma_index;

                            if (length==-1&&comma_index <= parenthesis_index)
                                length = comma_index;
                            else
                                length = parenthesis_index;

                            temp_var_name = parameters.Substring(start_index,length);
                            //start and end index determined
                            //check for special variables
                            clear_argument = ForwardToFBVar(temp_var_name, input_m_file);
                            if (!clear_argument.success)
                            {
                                clear_argument.code=ReplaceIllegalChars(temp_var_name);
                                clear_argument.comment="";
                                clear_argument.success = true;
                            }

                        }
                        else
                            clear_argument.success=false;

                    }
                    result.AddLast(clear_argument);
                }
                else
                    clear_argument.success = false;

            }
            return result;
        }
Exemple #2
0
        public class_types.CodeResult ForwardToFBVar(string input_var, class_types.m_file_data input_m_file)
        {
            //repoint variables do status vector

            class_types.CodeResult result = new class_types.CodeResult();
            string var = "";
            string FB_ID = "";
            string name = "";

            if (input_var.Contains("."))
            {

                for (int i = 0; i < input_m_file.variables.Count; i++)//find variable
                {
                    if (input_var.Substring(0, input_var.IndexOf(".")) + "_FBID" == input_m_file.variables.ElementAt(i).name)
                    {
                        FB_ID = input_m_file.variables.ElementAt(i).value;//retrieve FB_ID
                        name = input_m_file.variables.ElementAt(i).name.Substring(0, input_m_file.variables.ElementAt(i).name.IndexOf("_FBID"));
                        var = ReplaceIllegalChars(input_var.Substring(input_var.IndexOf(".") + 1));
                        break;
                    }
                }
                if (name != "" && FB_ID != "")
                {
                    switch (FB_ID)
                    {
                        case "'TIMER_ON'":
                            switch (var)
                            {
                                case "IN":
                                    result.code = name + "(2)";
                                    result.comment += name + ".IN";
                                    result.success = true;
                                    break;
                                case "ET":
                                    result.code = name + "(3)";
                                    result.comment += name + ".T";
                                    result.success = true;
                                    break;
                                case "PT":
                                    result.code = name + "(4)";
                                    result.comment += name + ".Q";
                                    result.success = true;
                                    break;
                                case "Q":
                                    result.code = name + "(6)";
                                    result.comment += name + ".Q";
                                    result.success = true;
                                    break;
                            }
                            break;
                        case "'COUNTER_UP'":
                            switch (var)
                            {
                                case "CU":
                                    result.code = name + "(2)";
                                    result.comment += name + ".CU";
                                    result.success = true;
                                    break;
                                case "CV":
                                    result.code = name + "(3)";
                                    result.comment += name + ".CV";
                                    result.success = true;
                                    break;
                                case "PV":
                                    result.code = name + "(4)";
                                    result.comment += name + ".PV";
                                    result.success = true;
                                    break;
                                case "RESET":
                                    result.code = name + "(5)";
                                    result.comment += name + ".RESET";
                                    result.success = true;
                                    break;
                                case "Q":
                                    result.code = name + "(6)";
                                    result.comment += name + ".Q";
                                    result.success = true;
                                    break;
                            }
                            break;
                        case "'COUNTER_DOWN'":
                            switch (var)
                            {
                                case "CD":
                                    result.code = name + "(2)";
                                    result.comment += name + ".CD";
                                    result.success = true;
                                    break;
                                case "CV":
                                    result.code = name + "(3)";
                                    result.comment += name + ".CV";
                                    result.success = true;
                                    break;
                                case "PV":
                                    result.code = name + "(4)";
                                    result.comment += name + ".PV";
                                    result.success = true;
                                    break;
                                case "LOAD":
                                    result.code = name + "(5)";
                                    result.comment += name + ".LOAD";
                                    result.success = true;
                                    break;
                                case "Q":
                                    result.code = name + "(6)";
                                    result.comment += name + ".Q";
                                    result.success = true;
                                    break;

                            }
                            break;
                    }
                }
                else
                    result.success = false;
            }
            else
                result.success = false;

            return result;
        }
Exemple #3
0
        //remove comment function
        class_types.CodeResult RemoveComment(string line)
        {
            class_types.CodeResult result=new class_types.CodeResult();
            result.code = line;
            result.comment = "";

            //comments "(* comment *)" exception
            if (!(line == ""))
            {
                if (line.Contains("(*"))
                {
                    if (line.Substring(2).Contains("*)"))
                    {
                        //--------if there any comments, it will write them to the output and remove them from the reading line-------
                        if (line.Substring(line.IndexOf("(*", 0), line.Length - line.IndexOf("(*", 0)).Contains("*)"))
                        {
                            result.comment = line.Substring(line.IndexOf("(*", 0) + 2, line.IndexOf("*)", 0) - line.IndexOf("(*", 0)-2);
                            //result.comment = line.Substring(line.IndexOf("(*", 0) + 2, line.Length - line.IndexOf("(*", 0) - 4);
                            result.code = line.Remove(line.IndexOf("(*", 0), line.Length - line.IndexOf("(*", 0));

                            //clean last spaces
                            result.code = RemoveEndSpaces(result.code);

                            result.success = true;
                        }
                    }
                    else
                    {
                        result.code = RemoveEndSpaces(line.Remove(line.IndexOf("(*", 0), line.Length - line.IndexOf("(*", 0)));
                        result.success = false;
                    }
                }
                else
                {
                    result.success = true;
                }
            }
            else
            {
                result.success = false;
            }

            return result;
        }