Esempio n. 1
0
        private static void AssignVar(TVar left, TVar right)
        {
            FreeItems(left);
            TItem last    = null;
            TItem itemaux = right.items;

            while (itemaux != null)
            {
                TItem newItem = new TItem();
                newItem.UL     = itemaux.UL;
                newItem.ValNB  = itemaux.ValNB;
                newItem.ValStr = itemaux.ValStr;
                if (left.items == null)
                {
                    left.items = newItem;
                }
                else
                {
                    last.Next = newItem;
                }

                last = newItem;

                itemaux = itemaux.Next;
            }
        }
Esempio n. 2
0
        private static void Assign(TVar v, int index, TExpression exp)
        {
            if (index != 0)
            {
                int   i        = 0;
                TItem itemAux  = v.items;
                TItem lastItem = null;
                while (i < index)
                {
                    if (itemAux == null)
                    {
                        TItem newItem = new TItem {
                            UL = TypeSymbol.U_UnKown
                        };

                        if (lastItem == null)
                        {
                            v.items = newItem;
                        }
                        else
                        {
                            lastItem.Next = newItem;
                        }

                        lastItem = newItem;
                    }
                    else
                    {
                        lastItem = itemAux;
                        itemAux  = itemAux.Next;
                    }

                    i++;
                }

                lastItem.UL     = exp.UL;
                lastItem.ValNB  = exp.ValNB;
                lastItem.ValStr = exp.ValStr;

                // check if we free it outside the method
                Free(ref exp);
            }
            else
            {
                FreeItems(v);
                v.items = new TItem {
                    UL = exp.UL, ValNB = exp.ValNB, ValStr = exp.ValStr
                };
                //v.items.UL = exp.UL;
                //v.items.ValNB = exp.ValNB;
                //v.items.ValStr = exp.ValStr;
                Free(ref exp);
            }
        }
Esempio n. 3
0
        private static void FreeItems(TVar v)
        {
            if (v.items != null)
            {
                TItem itemAux  = v.items;
                TItem itemNext = null;

                while (itemAux != null)
                {
                    itemNext = itemAux.Next;
                    itemAux  = null;     // itemAux.Free();
                    itemAux  = itemNext;
                }

                v.items = null;
            }
        }
Esempio n. 4
0
        private TExpression ReadFact(ref TExpression last)
        {
            if (UL == TypeSymbol.U_Cst_Int || UL == TypeSymbol.U_Cst_Real || UL == TypeSymbol.U_Cst_Str ||
                UL == TypeSymbol.U_True || UL == TypeSymbol.U_False)
            {
                TExpression expNew = new TExpression();
                expNew.UL = UL;
                if (UL == TypeSymbol.U_Cst_Str)
                {
                    expNew.ValStr = G_curr_Str;
                }
                else if (UL == TypeSymbol.U_Cst_Int || UL == TypeSymbol.U_Cst_Real) // the if statment i added after notce the true false.
                {
                    expNew.ValNB = G_curr_Num;
                }

                // by default
                expNew.Next = null;
                expNew.Prev = null;

                last = expNew;
                UL   = LexicalUnit();
                return(expNew);
            }
            else if (UL == TypeSymbol.U_OpenParanthese)
            {
                UL = LexicalUnit();
                TExpression expNew = ReadCondition(ref last);
                if (UL != TypeSymbol.U_ClosedParanthese)
                {
                    GetSyntaxError(WordMessagesError.NotFound, ")");
                }
                UL = LexicalUnit();
                return(expNew);
            }
            else if (UL == TypeSymbol.U_Var || UL == TypeSymbol.U_VarDefine ||
                     UL == TypeSymbol.U_VarProcedure || UL == TypeSymbol.U_UnKown)
            {
                TExpression expNew = new TExpression();

                // By Default
                expNew.Next = null;
                expNew.Prev = null;

                TVar varAux = null;
                ProcedureInstruction procAux = null;
                TypeSymbol           ulAux;

                if (UL == TypeSymbol.U_VarDefine)   // if the variable define
                {
                    DefineInstruction defAux = (DefineInstruction)G_curr_ID;
                    expNew.UL     = defAux.UL;
                    expNew.ValNB  = defAux.ValNB;
                    expNew.ValStr = defAux.ValStr;
                    ulAux         = defAux.UL;
                    UL            = LexicalUnit();
                }
                else if (UL == TypeSymbol.U_UnKown) // if the variblae unknown procedure , unknown variable
                {
                    string buffer = G_curr_Str;
                    UL = LexicalUnit();

                    if (UL == TypeSymbol.U_OpenParanthese)  // if the variblae unknown procedure
                    {
                        IdentifierInstruction.AddIdentifier(buffer, ref Locals.gproc);
                        procAux      = gProc;
                        gProc.IsFunc = true;
                        //gProc.IsDefined = false;
                        //gProc.PIN = null;
                        //gProc.POut = null;
                        //gproc.LVar = null;
                        //gProc.Linst = null;
                        ulAux = TypeSymbol.U_VarProcedure;
                    }
                    else                    // if the variblae unknown procedure , unknownvariable
                    {
                        IdentifierInstruction.AddIdentifier(buffer, ref Locals.gvar);
                        varAux = gVar;
                        ulAux  = TypeSymbol.U_Var;
                    }
                }
                else    // if the variable known
                {
                    // this statment i am not sure about it
                    ulAux = UL;
                    if (ulAux == TypeSymbol.U_Var)      // if the vairable known var
                    {
                        varAux = (TVar)G_curr_ID;
                    }
                    else                                // if the variable known procedure
                    {
                        procAux = (ProcedureInstruction)G_curr_ID;
                    }

                    UL = LexicalUnit();
                }

                expNew.UL = ulAux;
                last      = expNew;
                if (ulAux == TypeSymbol.U_VarProcedure)
                {
                    expNew.ValCall = ReadCall(procAux);
                }
                else if (ulAux == TypeSymbol.U_Var)
                {
                    expNew.ValVar = varAux;
                    if (UL == TypeSymbol.U_OpenBracket)
                    {
                        UL           = LexicalUnit();
                        expNew.Index = ReadExpression();
                        if (UL != TypeSymbol.U_ClosedBracket)
                        {
                            GetSyntaxError(WordMessagesError.NotFound, "]");
                        }

                        UL = LexicalUnit();
                    }
                    else
                    {
                        expNew.Index = null;
                    }
                }

                return(expNew);
            }
            else if (new TypeSymbol[] { TypeSymbol.U_Sin, TypeSymbol.U_Cos, TypeSymbol.U_Tg,
                                        TypeSymbol.U_Ln, TypeSymbol.U_Log, TypeSymbol.U_Exp, TypeSymbol.U_Sqr, TypeSymbol.U_Sqrt,
                                        TypeSymbol.U_Length, TypeSymbol.U_IntToStr, TypeSymbol.U_StrToInt, TypeSymbol.U_IntToHex, }.Contains(UL))
            {
                TExpression expNew = new TExpression();
                expNew.UL = UL;
                UL        = LexicalUnit();
                if (UL != TypeSymbol.U_OpenParanthese)
                {
                    GetSyntaxError(WordMessagesError.NotFound, "(");
                }

                UL = LexicalUnit();
                TExpression exp0 = ReadExpression(ref last);
                last.Next   = expNew;
                expNew.Prev = last;
                last        = expNew;

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

                UL = LexicalUnit();
                return(exp0);
            }
            else if (UL == TypeSymbol.U_Pluse || UL == TypeSymbol.U_Minus || UL == TypeSymbol.U_Not || UL == TypeSymbol.U_Complement)
            {
                TExpression expNew = new TExpression();

                if (UL == TypeSymbol.U_Pluse)
                {
                    expNew.UL = TypeSymbol.U_UnaryPluse;
                }
                else if (UL == TypeSymbol.U_Minus)
                {
                    expNew.UL = TypeSymbol.U_UnaryMinuse;
                }
                else if (UL == TypeSymbol.U_Not)
                {
                    expNew.UL = TypeSymbol.U_Not;
                }
                else
                {
                    expNew.UL = TypeSymbol.U_Complement;
                }

                UL = LexicalUnit();
                TExpression exp0 = ReadFact(ref last);
                last.Next   = expNew;
                expNew.Prev = last;
                last        = expNew; // this statment i added to solve the problem that unary pluse and unary minus.

                return(exp0);
            }
            else
            {
                GetSyntaxError(SyntaxMessagesError.InvalidToken, UL.ToString());
            }

            // this statment will never execute
            // just for elminate compile time error.
            return(null);
        }