Exemplo n.º 1
0
        public static void CompileDec(ParsedCommandOptions opts)
        {
            var Dec = new DecFile(@"C:\Users\yveem\source\repos\Redmond\TestDec.dec");

            CompileSettings.InitSettings(Dec.SettingsLines);
            var gram = new DecGrammar(Dec);

            Console.WriteLine("Generating parsing table...");

            ParseFile parseFile = new ParseFile(@"C:\Users\yveem\source\repos\Redmond\TestParse.parse");

            parseFile.SetLexLines(Dec.LexLines);
            parseFile.SetParseTableLines(gram.SerializeParsingTable());
            parseFile.SetTokenIdLines(ProductionEntry.Register.Serialize());
            parseFile.Save();

            Console.WriteLine("Done!");
            Console.Beep();

            var parser = gram.GetParser();

            var input = new MultiFileInputStream(new List <string>(new string[] { @"C:\Users\yveem\source\repos\Redmond\TestInput.txt" }));
            //var input = GetAllCSFiles(@"C:\Users\yveem\source\repos\CompileTestProject");


            TokenStream Input = new TokenStream(input, Dec.LexLines, new string(Enumerable.Range('\x1', 127).Select(i => (char)i).ToArray()));

            parser.Parse(Input);
            var tree = SyntaxTreeNode.CurrentNode;

            Console.WriteLine(tree.ToTreeString());
            Console.WriteLine("============\n");
            new IntermediateGenerator(new ConsoleStream()).Start(tree);
            Console.WriteLine("============\n");
        }
Exemplo n.º 2
0
        private static OutputStream GetSelectedOutput(ParsedCommandOptions options)
        {
            var o = options.FindOption("output", "out", "o")?.Argument;

            if (o == null || o.ToLower() == "console")
            {
                return(new ConsoleStream());
            }
            else
            {
                return(new FileOutputStream(o));
            }
        }
Exemplo n.º 3
0
        public static bool TryInvokeSubcommand(string[] args)
        {
            bool succes = true;
            var  parsed = new ParsedCommandOptions(args);

            switch (args[0])
            {
            case "compile": CompileCommands.Compile(parsed); break;

            case "compiledec": CompileCommands.CompileDec(parsed); break;

            default:
                succes = false;
                break;
            }

            return(succes);
        }
Exemplo n.º 4
0
        public static void Compile(ParsedCommandOptions opts)
        {
            Console.WriteLine("Reading parse file..");

            var output = GetSelectedOutput(opts);
            var input  = new MultiFileInputStream(new List <string>(new string[] { @"C:\Users\yveem\source\repos\Redmond\TestInput.txt" }));
            //var input = GetAllCSFiles(@"C:\Users\yveem\source\repos\CompileTestProject");
            //var input = GetAllCSFiles(@"C:\Users\yveem\source\repos\Redmond");

            ParseFile parseFile = new ParseFile(@"C:\Users\yveem\source\repos\Redmond\TestParse.parse").Read();

            string inputFile = opts.FindOption("input", "i")?.Argument ??
                               @"C:\Users\yveem\source\repos\Redmond\TestInput.txt";

            var context = new CompilationContext(parseFile, input, output);

            context.Compile();
        }