Пример #1
0
        public void ExecuteMainMethodFromObjectFile(string path)
        {
            using (FileStream stream = new FileStream(path, FileMode.Open))
            {
                ProcedureInstruction methods;
                try
                {
                    methods = (ProcedureInstruction)formatter.Deserialize(stream);
                }
                catch (SerializationException)
                {
                    GetRuntimeError(RuntimeMessagesError.ObjFile);
                    return;     // this statment is unreachable. Just for the compile Error
                }

                ProcedureInstruction main = IdentifierInstruction.FindIdentifer("Main", methods);

                if (main != null)
                {
                    ExecuteListOfInstructions(main.Linst);
                }
                else
                {
                    GetRuntimeError(RuntimeMessagesError.NoMain);
                }

                EndOfExecute?.Invoke(this, new WriteEventArgs(true, "End of Executing... Press Enter to Exit", true));
            }
        }
Пример #2
0
        /// <summary>
        /// Compile the primary file that has main function and the related included file with it.
        /// </summary>
        /// <param name="fileName">Represent the filename</param>
        public void CompileMainProgram(string fileName)
        {
            Warning.Clear();

            locals.initializeForRecompile();
            gFile = new TFile { Name = fileName };
            currentFile = gFile;
            bool mainFile = true;

            while (currentFile != null)
            {
                locals.initializeForNewFile();
                try
                {
                    locals.CF = File.ReadAllLines(currentFile.Name);
                }
                catch (FileNotFoundException)   // if the file that included is not found.
                {
                    MakeSyntaxError(SyntaxMessagesError.FileNotFound);
                }
                catch (DirectoryNotFoundException)
                {
                    MakeSyntaxError(SyntaxMessagesError.FileNotFound);
                }

                analyst.CompileCurrentFile();
                if (mainFile)       // if there is NO main is not in main File.
                {
                    if (IdentifierInstruction.FindIdentifer("Main", gProc) == null)
                    {
                        MakeSyntaxError(string.Format(SyntaxMessagesError.NoMainMethod, currentFile.Name));
                    }
                }

                mainFile = false;
                currentFile = currentFile.Next;
            }

            // Check if we call function or procedure that not Defined
            ProcedureInstruction tempP = gProc;
            while (tempP != null)
            {
                if (!tempP.IsDefined)
                {
                    throw new SyntaxErrorException(string.Format(SyntaxMessagesError.MethodNotDefined, tempP.Name), 0, 0, "");
                    //MakeSyntaxError(string.Format(SyntaxMessagesError.MethodNotDefined, tempP.Name));
                }
                tempP = (ProcedureInstruction)tempP.Next;
            }

            string[] dirs = gFile.Name.Split('\\');
            dir = dirs.Take(dirs.Length - 1).Select(str => str + "\\").Aggregate((one, two) => one + two) + dirs.Last().Split('.')[0] + ".obj";
            using (FileStream writer = new FileStream(dir, FileMode.Create))
            {
                formatter.Serialize(writer, gProc);
            }
        }
Пример #3
0
        private TypeSymbol HandleIdentifier()
        {
            id = CC.ToString();
            CI++;

            while (CCInLine && (char.IsNumber(CC) || char.IsLetter(CC) || CC == '_'))
            {
                id += CC;
                CI++;
            }

            TSymbol symAux = TSymbol.FindSymbol(id, AubCompiler.Gsymbol);
            if (symAux != null)
            {
                return symAux.UL;
            }

            string idUpperCase = id.ToUpper();
            G_curr_ID = IdentifierInstruction.FindIdentifer(idUpperCase, gVar);
            if (G_curr_ID != null)
            {
                return TypeSymbol.U_Var;
            }

            G_curr_ID = IdentifierInstruction.FindIdentifer(idUpperCase, gDefine);
            if (G_curr_ID != null)
            {
                return TypeSymbol.U_VarDefine;
            }

            G_curr_ID = IdentifierInstruction.FindIdentifer(idUpperCase, gProc);
            if (G_curr_ID != null)
            {
                return TypeSymbol.U_VarProcedure;
            }

            G_curr_Str = id.ToUpper();
            return TypeSymbol.U_UnKown;
        }