Ejemplo n.º 1
0
        public HeronValue EvalString(string s)
        {
            Expression x = CodeModelBuilder.CreateExpr(s);

            x.ResolveAllTypes(globalModule, globalModule);
            return(Eval(x));;
        }
Ejemplo n.º 2
0
        static public InterfaceDefn ParseInterface(ModuleDefn m, string s)
        {
            ParseNode node = ParserState.Parse(HeronGrammar.Interface, s);

            if (node == null)
            {
                return(null);
            }
            InterfaceDefn r = CodeModelBuilder.CreateInterface(m, node);

            return(r);
        }
Ejemplo n.º 3
0
        static public ClassDefn ParseClass(ModuleDefn m, string s)
        {
            ParseNode node = ParserState.Parse(HeronGrammar.Class, s);

            if (node == null)
            {
                return(null);
            }
            ClassDefn r = CodeModelBuilder.CreateClass(m, node);

            return(r);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public ModuleDefn LoadModule(string sFileName)
        {
            ModuleDefn m = CodeModelBuilder.ParseFile(program, sFileName);

            program.AddModule(m);
            string sFileNameAsModuleName = sFileName.Replace('/', '.').Replace('\\', '.');

            sFileNameAsModuleName = Path.GetFileNameWithoutExtension(sFileNameAsModuleName);
            int n = sFileNameAsModuleName.IndexOf(m.name);

            if (n + m.name.Length != sFileNameAsModuleName.Length)
            {
                throw new Exception("The module name '" + m.name + "' does not correspond to the file name '" + sFileName + "'");
            }
            return(m);
        }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
0
 static public void TestStatement(string s)
 {
     Console.WriteLine("testing statement: " + s);
     try
     {
         Statement x = CodeModelBuilder.CreateStatement(s);
         if (x != null)
         {
             Console.WriteLine("test passed");
         }
         else
         {
             Console.WriteLine("test failed without exception");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("test failed with exception " + e.Message);
     }
 }
Ejemplo n.º 8
0
 static public void TestCreateExprParse(string s)
 {
     Console.WriteLine("testing expression: " + s);
     try
     {
         Expression x = CodeModelBuilder.CreateExpr(s);
         if (x != null)
         {
             Console.WriteLine("test passed");
             Console.WriteLine("result string = " + x.ToString() + ", type " + x.GetType().ToString());
         }
         else
         {
             Console.WriteLine("test failed without exception");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("test failed with exception " + e.Message);
     }
 }