Esempio n. 1
0
        private static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            DustContext         context  = new DustContext();
            DustRuntimeCompiler compiler = new DustRuntimeCompiler(context);

            string input;

            while ((input = Console.ReadLine()) != "exit")
            {
                AntlrInputStream  inputStream       = new AntlrInputStream(input);
                DustLexer         lexer             = new DustLexer(inputStream);
                CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
                DustParser        parser            = new DustParser(commonTokenStream);
                DustVisitor       visitor           = new DustVisitor(context);
                Module            module            = (Module)visitor.VisitModule(parser.module());

                object result = compiler.Compile(module).Value;

                bool hasErrored = false;

                foreach (Error error in context.ErrorHandler.Errors)
                {
                    hasErrored = true;

                    Console.WriteLine(error);
                }

                if (result != null && hasErrored == false)
                {
                    Console.WriteLine(result);
                }
            }
        }
Esempio n. 2
0
        public static CompileResult <object> CompileFile(string text)
        {
            AntlrInputStream    inputStream       = new AntlrInputStream(text);
            DustLexer           lexer             = new DustLexer(inputStream);
            CommonTokenStream   commonTokenStream = new CommonTokenStream(lexer);
            DustParser          parser            = new DustParser(commonTokenStream);
            DustContext         context           = new DustContext();
            DustVisitor         visitor           = new DustVisitor(context);
            DustRuntimeCompiler compiler          = new DustRuntimeCompiler(context);

            Module module = (Module)visitor.VisitModule(parser.module());

            return(compiler.Compile(module));
        }