/// <summary>
        ///    While There are more functions to parse
        /// </summary>
        /// <returns></returns>
        public TModule ParseFunctions()
        {
            bool error_state = false;

            while (Current_Token == TOKEN.TOK_FUNCTION)
            {
                ProcedureBuilder b = ParseFunction();
                Procedure        s = b.GetProcedure();

                //  if (s == null)
                //  {
                //      Console.WriteLine("Error While Parsing Functions");
                //       return null;
                //    }
                if (s != null)
                {
                    if (prog.IsCompiledFunction(s.Name))
                    {
                        Console.WriteLine("Warning : Duplicate function ....! " + s.Name);
                        throw new CParserException(-1, "Duplicate Function..", SaveIndex());
                    }

                    prog.Add(s);
                    GetNext();
                }
                else
                {
                    error_state = true;
                    while (GetNext() != TOKEN.TOK_FUNCTION)
                    {
                        if (Current_Token == TOKEN.ILLEGAL_TOKEN)
                        {
                            throw new CParserException(-100, "Compilation Error  ", SaveIndex());
                        }
                    }
                }
            }

            if (Current_Token != TOKEN.TOK_NULL)
            {
                throw new CParserException(-100, "Failed to compile the whole program ", SaveIndex());
            }
            if (Current_Token == TOKEN.ILLEGAL_TOKEN)
            {
                throw new CParserException(-100, "Illegal token , terminating compilation ", SaveIndex());
            }
            if (error_state == true)
            {
                throw new CParserException(-100, "Compilation Error  ", SaveIndex());
            }

            //
            //  Convert the builder into a program
            //
            return(prog.GetProgram());
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public TModule DoParse()
        {
            ProcedureBuilder p     = new ProcedureBuilder("MAIN", new COMPILATION_CONTEXT());
            ArrayList        stmts = Parse(p);

            foreach (Stmt s in stmts)
            {
                p.AddStatement(s);
            }

            Procedure pc = p.GetProcedure();

            prog.Add(pc);
            return(prog.GetProgram());
        }
예제 #3
0
        /// <summary>
        ///    While There are more functions to parse
        /// </summary>
        /// <returns></returns>
        public TModule ParseFunctions()
        {
            while (Current_Token == TOKEN.TOK_FUNCTION)
            {
                ProcedureBuilder b = ParseFunction();
                Procedure        s = b.GetProcedure();

                if (s == null)
                {
                    Console.WriteLine("Error While Parsing Functions");
                    return(null);
                }

                prog.Add(s);
                GetNext();
            }

            //
            //  Convert the builder into a program
            //
            return(prog.GetProgram());
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public TModule DoParse()
        {
            try
            {
                ProcedureBuilder p     = new ProcedureBuilder("MAIN", new COMPILATION_CONTEXT());
                ArrayList        stmts = Parse(p);

                foreach (Stmt s in stmts)
                {
                    p.AddStatement(s);
                }

                Procedure pc = p.GetProcedure();

                prog.Add(pc);
                return(prog.GetProgram());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }