Beispiel #1
0
        private TypeSymbol ExecuteCall(CallInstruction callaux)
        {
            // 1 . handle the input variables
            TExpression exp0 = EvaluateExpression(callaux.Pin);
            TVar        varaux;

            if (exp0 != null)
            {
                while (exp0.Next != null)
                {
                    exp0 = exp0.Next;
                }

                varaux = callaux.P.PIN;
                TExpression expaux;
                while (varaux != null && exp0 != null)
                {
                    expaux = exp0.Prev;
                    if (expaux != null)     // this condition I added because of expcetion.
                    {
                        expaux.Next = null;
                    }

                    //expaux.Prev = null;
                    exp0.Prev = null;

                    Assign(varaux, 0, exp0);

                    Free(ref exp0);
                    exp0   = expaux;
                    varaux = (TVar)varaux.Next;
                }

                // error the variables in method is different from variables in call.
                if (varaux != null || exp0 != null)
                {
                    GetRuntimeError(RuntimeMessagesError.VarsDifferents, "inupt");
                }
            }

            // 2 . Handle the output variables.
            TListVar lv = callaux.Pout;

            varaux = callaux.P.POut;

            if (!(lv == null && varaux == null))
            {
                if (varaux == null)
                {
                    GetRuntimeError(RuntimeMessagesError.VarsDifferents, "output");
                }
                while (lv != null && varaux != callaux.P.PIN)
                {
                    AssignVar(varaux, lv.V);
                    varaux = (TVar)varaux.Next;
                    lv     = lv.Next;
                }

                // error the output variables in method is different from output variables in call
                if (lv != null || varaux != callaux.P.PIN)
                {
                    GetRuntimeError(RuntimeMessagesError.VarsDifferents, "output");
                }
            }

            // 3 . Execute the Instructions of method.
            UL = ExecuteListOfInstructions(callaux.P.Linst);

            // 4 . return the output vaiables from the call to the orgianl variables in the methods.
            lv     = callaux.Pout;
            varaux = callaux.P.POut;

            if (varaux == null)
            {
                varaux = callaux.P.PIN;
            }

            // 5 . return the input variables from the call to the orginal vaiables in the methods.
            while (lv != null) // here there is another condition
            {
                AssignVar(lv.V, varaux);
                varaux = (TVar)varaux.Next;
                lv     = lv.Next;
            }

            return(UL);
        }
Beispiel #2
0
        private CallInstruction ReadCall(ProcedureInstruction procAux)
        {
            CallInstruction callAux = new CallInstruction {
                P = procAux
            };

            // Code before Modify

            //callAux.P = (TProcedure)lexer.CurrID;
            //if (LexicalUnit() != TypeSymbol.U_OpenParanthese)
            //{
            //    GetSyntaxError(WordMessagesError.NotFound, "(");
            //}

            // Code after Modify
            // callAux.P = procAux;
            if (UL != TypeSymbol.U_OpenParanthese)
            {
                GetSyntaxError(WordMessagesError.NotFound, "(");
            }

            UL = LexicalUnit();
            // By Default
            callAux.Pin  = null;
            callAux.Pout = null;

            if (UL == TypeSymbol.U_Input)
            {
                UL = LexicalUnit();
                TExpression last = null;
                while (true)
                {
                    TExpression last1 = null;
                    TExpression exp1  = ReadExpression(ref last1);
                    if (callAux.Pin == null)
                    {
                        callAux.Pin = exp1;
                    }
                    else
                    {
                        last.Next = exp1;
                        exp1.Prev = last;
                    }

                    last = last1;

                    if (UL == TypeSymbol.U_ClosedParanthese || UL == TypeSymbol.U_Output)
                    {
                        break;
                    }
                    if (UL != TypeSymbol.U_Comma)
                    {
                        GetSyntaxError(WordMessagesError.NotFound, "\",\"");
                    }

                    UL = LexicalUnit();
                }   // end while
            }

            if (UL == TypeSymbol.U_Output) // this section must be Repated again ( it is not finished )
            {
                UL = LexicalUnit();

                while (true)
                {
                    if (UL == TypeSymbol.U_UnKown)
                    {
                        IdentifierInstruction.AddIdentifier(G_curr_Str, ref Locals.gvar);
                        G_curr_ID = gVar;
                    }
                    else if (UL != TypeSymbol.U_Var)
                    {
                        GetSyntaxError(WordMessagesError.NotFound, "Variable");
                    }

                    TListVar newlvar = new TListVar();
                    newlvar.V    = (TVar)G_curr_ID;
                    newlvar.Next = callAux.Pout;
                    callAux.Pout = newlvar;

                    UL = LexicalUnit();
                    if (UL == TypeSymbol.U_ClosedParanthese)
                    {
                        break;
                    }
                    if (UL != TypeSymbol.U_Comma)
                    {
                        GetSyntaxError(WordMessagesError.NotFound, "\",\"");
                    }
                    UL = LexicalUnit();
                }
            }

            if (UL != TypeSymbol.U_ClosedParanthese)
            {
                GetSyntaxError(WordMessagesError.NotFound, ")");
            }

            UL = LexicalUnit();
            return(callAux);
        }