Example #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);
                }
            }
        }
        private static Statement ParseStatements(string input)
        {
            AntlrInputStream  inputStream       = new AntlrInputStream(input);
            DustLexer         lexer             = new DustLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            DustParser        parser            = new DustParser(commonTokenStream);
            DustVisitor       visitor           = new DustVisitor(new DustContext());

            return(((Module)visitor.VisitModule(parser.module())).Statements.First());
        }
Example #3
0
        private static object Compile(string input)
        {
            AntlrInputStream  inputStream       = new AntlrInputStream(input);
            DustLexer         lexer             = new DustLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            DustParser        parser            = new DustParser(commonTokenStream);
            DustVisitor       visitor           = new DustVisitor(new DustContext());

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

            return(compiler.CompileModule((Module)visitor.VisitModule(parser.module())));
        }
Example #4
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));
        }