Пример #1
0
        //================================================================================================//
        // process subterm
        //================================================================================================//
        private static int ProcessSubTerm(SignalHead head, List <SignalScripts.SCRScripts.SCRStatTerm> statementTerms, int sublevel, int[] localFloats)
        {
            int tempValue = 0;
            int termValue;

            foreach (SignalScripts.SCRScripts.SCRStatTerm term in statementTerms)
            {
                if (term.Function == SignalScripts.SCRExternalFunctions.RETURN)
                {
                    break;
                }

                SignalScripts.SCRTermOperator thisOperator = term.TermOperator;
                if (term.TermLevel == sublevel)
                {
                    termValue = ProcessAssignTerm(head, statementTerms, term, localFloats);
                    if (term.Negated)
                    {
                        termValue = termValue == 0 ? 1 : 0;
                    }

                    switch (thisOperator)
                    {
                    case (SignalScripts.SCRTermOperator.MULTIPLY):
                        tempValue *= termValue;
                        break;

                    case (SignalScripts.SCRTermOperator.PLUS):
                        tempValue += termValue;
                        break;

                    case (SignalScripts.SCRTermOperator.MINUS):
                        tempValue -= termValue;
                        break;

                    case (SignalScripts.SCRTermOperator.DIVIDE):
                        if (termValue == 0)
                        {
                            tempValue = 0;
                        }
                        else
                        {
                            tempValue /= termValue;
                        }
                        break;

                    case (SignalScripts.SCRTermOperator.MODULO):
                        tempValue %= termValue;
                        break;

                    default:
                        tempValue = termValue;
                        break;
                    }
                }
            }
            return(tempValue);
        }
Пример #2
0
        //================================================================================================//
        //
        // process subterm
        //
        //================================================================================================//

        public int SH_processSubTerm(SignalHead thisHead, List <SignalScripts.SCRScripts.SCRStatTerm> StatementTerms,
                                     int sublevel, int[] localFloats, SIGSCRfile sigscr)
        {
            int tempvalue = 0;
            int termvalue = 0;

            foreach (SignalScripts.SCRScripts.SCRStatTerm thisTerm in StatementTerms)
            {
                if (thisTerm.Function == SignalScripts.SCRExternalFunctions.RETURN)
                {
                    break;
                }

                SignalScripts.SCRTermOperator thisOperator = thisTerm.TermOperator;
                if (thisTerm.issublevel == sublevel)
                {
                    termvalue =
                        SH_processAssignTerm(thisHead, StatementTerms, thisTerm, sublevel, localFloats, sigscr);
                    if (thisTerm.negate)
                    {
                        termvalue = termvalue == 0 ? 1 : 0;
                    }

                    switch (thisOperator)
                    {
                    case (SignalScripts.SCRTermOperator.MULTIPLY):
                        tempvalue *= termvalue;
                        break;

                    case (SignalScripts.SCRTermOperator.PLUS):
                        tempvalue += termvalue;
                        break;

                    case (SignalScripts.SCRTermOperator.MINUS):
                        tempvalue -= termvalue;
                        break;

                    case (SignalScripts.SCRTermOperator.DIVIDE):
                        if (termvalue == 0)
                        {
                            tempvalue = 0;
                        }
                        else
                        {
                            tempvalue /= termvalue;
                        }
                        break;

                    case (SignalScripts.SCRTermOperator.MODULO):
                        tempvalue %= termvalue;
                        break;

                    default:
                        tempvalue = termvalue;
                        break;
                    }
                }
            }

            return(tempvalue);
        }
Пример #3
0
        //================================================================================================//
        //
        // process single condition
        //
        //================================================================================================//

        public bool SH_processSingleCondition(SignalHead thisHead, SignalScripts.SCRScripts.SCRConditions thisCond,
                                              int[] localFloats, SIGSCRfile sigscr)
        {
            int  term1value = 0;
            int  term2value = 0;
            bool condition  = true;

            // get value of first term


#if DEBUG_PRINT_ENABLED
            if (thisHead.mainSignal.enabledTrain != null)
            {
                File.AppendAllText(dpe_fileLoc + @"printproc.txt", "IF Condition statement (1) : \n");
            }
#endif
#if DEBUG_PRINT_PROCESS
            if (TDB_debug_ref.Contains(thisHead.TDBIndex))
            {
                File.AppendAllText(dpr_fileLoc + @"printproc.txt", "IF Condition statement (1) : \n");
            }
#endif

            if (thisCond.Term1.Function != SignalScripts.SCRExternalFunctions.NONE)
            {
                term1value = SH_function_value(thisHead, thisCond.Term1, localFloats, sigscr);
            }
            else if (thisCond.Term1.PartParameter != null)
            {
                SignalScripts.SCRScripts.SCRParameterType thisParameter = thisCond.Term1.PartParameter[0];

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                       thisParameter.PartParameter.ToString() + "\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                       thisParameter.PartParameter.ToString() + "\n");
                }
#endif

                SignalScripts.SCRTermOperator thisOperator = thisCond.Term1.TermOperator;
                term1value = SH_termvalue(thisHead, thisParameter,
                                          localFloats, sigscr);
                if (thisOperator == SignalScripts.SCRTermOperator.MINUS)
                {
                    term1value = -term1value;
                }
            }

            // get value of second term

            if (thisCond.Term2 == null)

            // if only one value : check for NOT
            {
                if (thisCond.negate1)
                {
                    condition = !(Convert.ToBoolean(term1value));
                }
                else
                {
                    condition = Convert.ToBoolean(term1value);
                }

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Result of single condition : " +
                                       " : " + condition.ToString() + " (NOT : " + thisCond.negate1.ToString() + ")\n\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Result of single condition : " +
                                       " : " + condition.ToString() + " (NOT : " + thisCond.negate1.ToString() + ")\n\n");
                }
#endif
            }

            // process second term

            else
            {
#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "IF Condition statement (2) : \n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "IF Condition statement (2) : \n");
                }
#endif

                if (thisCond.Term2.Function != SignalScripts.SCRExternalFunctions.NONE)
                {
                    term2value = SH_function_value(thisHead, thisCond.Term2, localFloats, sigscr);
                }
                else if (thisCond.Term2.PartParameter != null)
                {
                    SignalScripts.SCRScripts.SCRParameterType thisParameter = thisCond.Term2.PartParameter[0];

#if DEBUG_PRINT_ENABLED
                    if (thisHead.mainSignal.enabledTrain != null)
                    {
                        File.AppendAllText(dpe_fileLoc + @"printproc.txt",
                                           "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                           thisParameter.PartParameter.ToString() + "\n");
                    }
#endif
#if DEBUG_PRINT_PROCESS
                    if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                    {
                        File.AppendAllText(dpr_fileLoc + @"printproc.txt",
                                           "Parameter : " + thisParameter.PartType.ToString() + " : " +
                                           thisParameter.PartParameter.ToString() + "\n");
                    }
#endif

                    SignalScripts.SCRTermOperator thisOperator = thisCond.Term2.TermOperator;
                    term2value = SH_termvalue(thisHead, thisParameter,
                                              localFloats, sigscr);
                    if (thisOperator == SignalScripts.SCRTermOperator.MINUS)
                    {
                        term2value = -term2value;
                    }
                }

                // check on required condition

                switch (thisCond.Condition)
                {
                // GT

                case (SignalScripts.SCRTermCondition.GT):
                    condition = (term1value > term2value);
                    break;

                // GE

                case (SignalScripts.SCRTermCondition.GE):
                    condition = (term1value >= term2value);
                    break;

                // LT

                case (SignalScripts.SCRTermCondition.LT):
                    condition = (term1value < term2value);
                    break;

                // LE

                case (SignalScripts.SCRTermCondition.LE):
                    condition = (term1value <= term2value);
                    break;

                // EQ

                case (SignalScripts.SCRTermCondition.EQ):
                    condition = (term1value == term2value);
                    break;

                // NE

                case (SignalScripts.SCRTermCondition.NE):
                    condition = (term1value != term2value);
                    break;
                }

#if DEBUG_PRINT_ENABLED
                if (thisHead.mainSignal.enabledTrain != null)
                {
                    File.AppendAllText(dpe_fileLoc + @"printproc.txt", "Result of operation : " +
                                       thisCond.Condition.ToString() + " : " + condition.ToString() + "\n\n");
                }
#endif
#if DEBUG_PRINT_PROCESS
                if (TDB_debug_ref.Contains(thisHead.TDBIndex))
                {
                    File.AppendAllText(dpr_fileLoc + @"printproc.txt", "Result of operation : " +
                                       thisCond.Condition.ToString() + " : " + condition.ToString() + "\n\n");
                }
#endif
            }


            return(condition);
        }