Пример #1
0
        //-----------------------------------------------------------
        void Run(string[] args)
        {
            PrintAppHeader();
            Console.WriteLine();
            PrintReleaseIncludes();
            Console.WriteLine();

            // if (args.Length != 1) {
            //  Console.Error.WriteLine(
            //      "Please specify the name of the input file.");
            //  Environment.Exit(1);
            // }

            try {
                var      inputPath = args[0];
                var      input     = File.ReadAllText(inputPath);
                var      parser    = new Parser(new Scanner(input).Start().GetEnumerator());
                NProgram program   = (NProgram)parser.CProgram();
                Console.WriteLine("Syntax OK");

                var semantic = new SemanticAnalyzer(program);
                semantic.Analyze();
                Console.WriteLine("Semantics OK.");
                Console.WriteLine();
                Console.WriteLine(program.ToStringTree());
                Console.WriteLine();
                Console.WriteLine("Symbol Table");
                Console.WriteLine("============");
                Console.WriteLine("Functions");
                foreach (FunctionSym entry in semantic.functions)
                {
                    entry.Print();
                }
                Console.WriteLine("Global Variables");
                foreach (VariableSym entry in semantic.globalVars)
                {
                    entry.Print();
                }
                var outputPath = args[1];

                var codeGenerator = new CILGenerator(semantic);
                File.WriteAllText(
                    outputPath,
                    codeGenerator.Visit((dynamic)program));
                Console.WriteLine(
                    "Generated CIL code to '" + outputPath + "'.");
                Console.WriteLine();
            } catch (Exception e) {
                if (e is FileNotFoundException ||
                    e is SyntaxError ||
                    e is SemanticError)
                {
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }
                throw;
            }
        }
Пример #2
0
        //-----------------------------------------------------------
        void Run(string[] args)
        {
            PrintAppHeader();
            Console.WriteLine();
            PrintReleaseIncludes();
            Console.WriteLine();

            if (args.Length != 1)
            {
                Console.Error.WriteLine(
                    "Please specify the name of the input file.");
                Environment.Exit(1);
            }

            try {
                var inputPath = args[0];
                var input     = File.ReadAllText(inputPath);
                var parser    = new Parser(new Scanner(input).Start().GetEnumerator());
                var program   = parser.Program();
                Console.WriteLine("Syntax OK.");
                Console.Write(program.ToStringTree());

                Console.WriteLine($"-------------{program.GetType()}------------------");

                var semantic = new SemanticAnalyzer();
                semantic.Visit((dynamic)program);
                SemanticAnalyzer.pasones++;

                Console.WriteLine("\n\n**************SEGUNDA VUELTA**************\n\n");
                semantic.Visit((dynamic)program);


                Console.WriteLine("\n\n**************TERCERA VUELTA**************\n\n");
                SemanticAnalyzer.pasones++;
                semantic.Visit((dynamic)program);

                Console.WriteLine("Semantics OK.");
                Console.WriteLine();

                Console.WriteLine("Global Variable Table");
                Console.WriteLine("============");
                foreach (var entry in semantic.globVars)
                {
                    Console.WriteLine(entry);
                }

                // Console.WriteLine("\n\nSymbol Table");
                // Console.WriteLine("============");
                // foreach (var entry in semantic.Table) {
                //     Console.WriteLine(entry);
                // }
                Console.WriteLine(semantic.Table.ToString());
            } catch (Exception e) {
                if (e is FileNotFoundException ||
                    e is SyntaxError ||
                    e is SemanticError)
                {
                    Console.Error.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                throw;
            }
        }
 public SecondPassVisitor(SemanticAnalyzer semanticAnalyzer)
 {
     this.semanticAnalyzer = semanticAnalyzer;
 }
Пример #4
0
 public FirstPassVisitor(SemanticAnalyzer semanticAnalyzer)
 {
     this.semanticAnalyzer = semanticAnalyzer;
 }
Пример #5
0
 public CILGenerator(SemanticAnalyzer semanticAnalyzer)
 {
     this.semanticAnalyzer = semanticAnalyzer;
 }