package dk.aau.sw402F15;

import dk.aau.sw402F15.CodeGenerator.ASTSimplify;
import dk.aau.sw402F15.CodeGenerator.CodeGenerator;
import dk.aau.sw402F15.Preprocessor.Preprocessor;
import dk.aau.sw402F15.ScopeChecker.ScopeChecker;
import dk.aau.sw402F15.TypeChecker.TypeChecker;
import dk.aau.sw402F15.parser.lexer.Lexer;
import dk.aau.sw402F15.parser.lexer.LexerException;
import dk.aau.sw402F15.parser.node.Start;
import dk.aau.sw402F15.parser.parser.Parser;
import dk.aau.sw402F15.parser.parser.ParserException;

import java.io.*;

public class Main {

    public static void main(String[] args) {
/*        String code = "struct car func() {" +
                "struct car bmw;" +
                "return bmw;" +
                "}" +
                "struct car{\n" +
                "int nrOfWheels;\n" +
                "bool isTruck;\n" +
                "}\n" +
                "int main(){\n" +
                "struct car bmw;\n" +
                "func().nrOfWheels = 4;" +
                "return 1;\n" +
                "}\n";*/
            String code = "int main() {" +
                    "int a = 1; " +
                    "a = 1 + 1;" +
                    "return a;" +
                    "}";

        //System.out.println(code);

        try {
            Reader reader;
            if(args.length != 0)
                reader = new FileReader(args[0]);
            else
                reader = new StringReader(code);
            Parser parser = new Parser(new Lexer(new PushbackReader(reader, 1024)));
            Start tree = parser.parse();

            // Print tree
            tree.apply(new PrettyPrinter());

            // Apply preprocessor
            Preprocessor preprocessor = new Preprocessor();
            tree.apply(preprocessor);

            // Apply scopechecker
            ScopeChecker checker = new ScopeChecker(preprocessor.getScope());
            tree.apply(checker);

            // Applying typechecker
            tree.apply(new TypeChecker(checker.getSymbolTable()));

            // Simplifying the AST for easier codegen
            tree.apply(new ASTSimplify());

            tree.apply(new CodeGenerator());

        } catch (ParserException e) {
            e.printStackTrace();
        } catch (LexerException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
@@ -1629,24 +1629,122 @@
 rinter());%0A%0A
+            // Simplifying the AST for easier codegen%0A            tree.apply(new ASTSimplify());%0A%0A
             
@@ -2118,106 +2118,8 @@
 );%0A%0A
-            // Simplifying the AST for easier codegen%0A            tree.apply(new ASTSimplify());%0A%0A
     

Change order of simplify AST