Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Reader reader = new Reader((Message)null, @"c:\Zouev\SLang\SLang Tests\T011.slang");
            //  Reader reader = new Reader((Message)null,@"c:\Zouev\SLang\SLang Config Min\Version.slang");
            //  Reader reader = new Reader((Message)null,@"c:\Zouev\SLang\SLang Tests\Core ver 0.72.slang");
            //  Reader reader = new Reader((Message)null,@"c:\Zouev\SLang\SLang Tests\Core ver 0.6.2.slang");
            //  Reader reader = new Reader((Message)null,@"c:\Zouev\SLang\SLang Tests\Core ver 0.7 Updated.slang");
            //  Reader reader = new Reader((Message)null,@"c:\Zouev\SLang\SLang Tests\Comparable.slang");
            //  Reader reader = new Reader((Message)null,@"c:\Zouev\SLang\SLang Tests\Any.slang");
            //  Reader reader = new Reader(@"unit Integer is end");
            Options   options     = new Options();
            Message   messagePool = new Message(options);
            Tokenizer tokenizer   = new Tokenizer(reader, options, messagePool);

            ENTITY.init(tokenizer, 0, messagePool, options);
            COMPILATION compilation = COMPILATION.parse();

            compilation.report(4);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                // Output the quick guide
                Options.QuickGuide();
                goto NoActions;
            }

            // Parsing command line arguments
            Dictionary <string, string> opts = CommandLineArgs.parse(args);
            // The first queue element should be the source file name/path
            string fileName = opts["file-name"];

            // Setting compilation options
            Options options = new Options(opts);
            // Opening message pool
            Message messagePool = new Message(options);

            // Output compiler title & version
            if (options.optPrintVersion)
            {
                messagePool.info("compiler-title", "0.0.0.1 prototype");
            }

            // Opening the source file
            if (fileName == "")
            {
                messagePool.error(null, "empty-path");
                goto Finish;
            }

            if (!System.IO.File.Exists(fileName))
            {
                messagePool.error(null, "no-file", fileName);
                goto Finish;
            }

            // Initializing parsing process
            Reader    reader    = new Reader((Message)null, fileName);
            Tokenizer tokenizer = new Tokenizer(reader, options, messagePool);

            ENTITY.init(tokenizer, 0, messagePool, options);
            if (messagePool.numErrors > 0)
            {
                goto Finish;
            }

            // Phase 1: parsing
            // ================

            COMPILATION compilation = null;

            try
            {
                try
                {
                    compilation = COMPILATION.parse();
                    if (options.optDumpAST)
                    {
                        compilation.report(4);
                    }
                }
                catch (Exception)
                {
                    throw new TerminateSLangCompiler(ENTITY.current);
                }
            }
            catch (TerminateSLangCompiler exc)
            {
                Position pos = (exc == null) ? null : exc.position;
                messagePool.error(pos, "system-bug");
                goto Finish;
            }

            // TODO: semantic analysis call?

            // Phase 2: code generation
            // ===============================

            if (options.optDumpJSON)
            {
                JsonIr json = compilation.ToJSON();
                System.IO.File.WriteAllText(fileName + ".json", json.Serialize(false));
            }

            if (!options.optGenerate)
            {
                goto Finish;
            }

Finish:
            messagePool.info("end-compilation");
NoActions:
            ;
        }