示例#1
0
        static void Main(string[] args)
        {
            string inputfilename = "return_int.c";

            if (args.Count() > 0)
            {
                inputfilename = args[0];
            }

            if (!File.Exists(inputfilename))
            {
                Console.WriteLine("File \"" + inputfilename + "\" is not available.");
                return;
            }

            string src = File.ReadAllText(inputfilename);

            Token[] tokens = Lexer.Tokenize(src);

            AbstractSyntaxTree ast = Parser.Parse(tokens);

            string outfilename = inputfilename.Replace(".c", ".s");

            Generator.Write(outfilename, tokens, ast);
        }
示例#2
0
        public static AbstractSyntaxTree Parse(Token[] stream)
        {
            Queue <Token> tokens = new Queue <Token>(stream);

            AST.Function main = ParseFunction(tokens);

            AST.Program        program = new AST.Program(main);
            AbstractSyntaxTree ast     = new AbstractSyntaxTree(program);

            return(ast);
        }
示例#3
0
        public static void Write(string filename, Token[] tokens, AbstractSyntaxTree ast)
        {
            StreamWriter writer = new StreamWriter(filename, false);

            //WriteProgram(writer);
            WriteFunction(writer, ast.Root.Main);
            writer.WriteLine();

            for (int i = 0; i < tokens.Length; i++)
            {
                writer.Write(tokens[i] + "\n");
            }

            writer.WriteLine();
            writer.WriteLine(ast.ToString());

            writer.Close();
        }