예제 #1
0
        static public ModuleDefn ParseModule(ProgramDefn p, string s, string fileName)
        {
            ParseNode node = ParserState.Parse(HeronGrammar.Module, s);

            if (node == null)
            {
                return(null);
            }
            ModuleDefn r = CodeModelBuilder.CreateModule(p, node, fileName);

            return(r);
        }
예제 #2
0
        static public ModuleDefn ParseFile(ProgramDefn p, string sFileName)
        {
            ParseNode node;
            string    sFileContents = File.ReadAllText(sFileName);

            try
            {
                node = ParserState.Parse(HeronGrammar.File, sFileContents);
            }
            catch (ParsingException e)
            {
                Console.WriteLine("Parsing exception occured in file " + sFileName);
                Console.WriteLine("at character " + e.context.col + " of line " + e.context.row);
                Console.WriteLine(e.context.msg);
                Console.WriteLine(e.context.line);
                Console.WriteLine(e.context.ptr);
                throw;
            }

            if (node == null)
            {
                Console.WriteLine("Ill-formed Heron file " + sFileName);
                throw new Exception();
            }

            try
            {
                ModuleDefn r = CodeModelBuilder.CreateModule(p, node, sFileName);
                return(r);
            }
            catch (ParsingException e)
            {
                Console.WriteLine("Parsing exception occured in file " + sFileName);
                Console.WriteLine("at character " + e.context.col + " of line " + e.context.row);
                Console.WriteLine(e.context.msg);
                Console.WriteLine(e.context.line);
                Console.WriteLine(e.context.ptr);
                throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occured during construction of code model in file " + sFileName);
                Console.WriteLine(e.Message);
                throw;
            }
        }