Exemplo n.º 1
0
        internal void PreProcess()
        {
            if (!ReadNewLine())
            {
                GetWordError(WordMessagesError.FileEmpty, currFile.Name);
            }

            if (!SkipSpacesAndComment())
            {
                GetWordError(WordMessagesError.LackFileCode, currFile.Name);
            }

            while (CC == '#')
            {
                if ((NextCCInLine) && (char.ToLower(NextCC) == 'i' || char.ToLower(NextCC) == 'd'))
                {
                    CI++;
                    UL = LexicalUnit();
                    if (UL == TypeSymbol.U_Include)
                    {
                        SkipSpaces();
                        if (!(CCInLine && CC == '\''))
                        {
                            GetMacroError(WordMessagesError.NotFound, "string");
                        }
                        UL = LexicalUnit();
                        if (UL != TypeSymbol.U_Cst_Str)
                        {
                            GetMacroError(WordMessagesError.NotFound, "string");
                        }

                        TFile.AddFile(G_curr_Str, gFile);
                    }
                    else if (UL == TypeSymbol.U_Define)
                    {
                        SkipSpaces();

                        if (!((CCInLine) && (char.IsLetter(CC) || CC == '_')))
                        {
                            GetMacroError(WordMessagesError.NotFound, "Identifier");
                        }

                        UL = LexicalUnit();

                        if (UL != TypeSymbol.U_UnKown && UL != TypeSymbol.U_VarProcedure)
                        {
                            GetMacroError(WordMessagesError.IdKnown);
                        }

                        if (UL == TypeSymbol.U_UnKown)
                        {
                            IdentifierInstruction.AddIdentifier(G_curr_Str, ref Locals.gdefine);
                        }
                        if (UL == TypeSymbol.U_VarProcedure)
                        {
                            IdentifierInstruction.AddIdentifier(id.ToUpper(), ref Locals.gdefine);
                        }

                        DefineInstruction defAux = gDefine;
                        SkipSpaces();

                        if (!(CCInLine && (CC == '.' || char.IsNumber(CC) || CC == '\'')))
                        {
                            GetMacroError(WordMessagesError.NotFound, "number or string");
                        }

                        UL = LexicalUnit();
                        if (UL == TypeSymbol.U_Cst_Int || UL == TypeSymbol.U_Cst_Real)
                        {
                            defAux.ValNB = G_curr_Num;
                        }
                        else if (UL == TypeSymbol.U_Cst_Str)
                        {
                            defAux.ValStr = G_curr_Str;
                        }
                        else
                        {
                            GetMacroError(WordMessagesError.NotValidChar, "number or string");
                        }

                        defAux.UL = UL;
                    }
                    else
                    {
                        GetMacroError(WordMessagesError.NotFound, "Include or Define");
                    }
                }
                else
                {
                    GetMacroError(WordMessagesError.NoSpace);
                }
            }

            //return UL;
        }
Exemplo n.º 2
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);
        }