import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.stringtemplate.*;
import org.antlr.runtime.Token.*;

import java.nio.charset.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.io.BufferedWriter;
import java.io.IOException;


public class Tiger {
    private static String readFile(String path, Charset encoding) throws Exception {
        byte[] encoded = Files.readAllBytes(Paths.get(path));
        return new String(encoded, encoding);
    }

    private static void writeDotFile(String fileName, String outputString, Charset encoding) throws Exception {
        Path file = Paths.get(fileName);

        try (BufferedWriter writer = Files.newBufferedWriter(file, encoding)) {
            writer.write(outputString, 0, outputString.length());
        } catch (IOException x) {
            System.err.format("IOException: %s%n", x);
        }
    }

    public static void main(String[] args) {
        try {
            String[] file_tokens = args[0].split("\\.(?=[^\\.]+$)");
            String src = readFile(args[0], StandardCharsets.UTF_8);
            TigerLexer lexer = new TigerLexer(new ANTLRStringStream(src));
            TigerParser parser = new TigerParser(new CommonTokenStream(lexer));
            
            /*To print lexer symbols of the program*/
            TigerLexer lexer1 = new TigerLexer(new ANTLRStringStream(src));
            CommonTokenStream cts = new CommonTokenStream(lexer1);
            
            int i = 1;
            Token to = cts.LT(i);
            while(to.getType() != -1){
                System.out.print(TigerParser.tokenNames[to.getType()] + " ");
                if(to.getType() == -1) break;
                to = cts.LT(++i);
            }
            System.out.println();

            CommonTree tree = (CommonTree)(parser.tiger_program().getTree());
            DOTTreeGenerator gen = new DOTTreeGenerator();
            StringTemplate st = gen.toDOT(tree);
            writeDotFile(args[1], st.toString(), StandardCharsets.UTF_8);
    
            if(parser.getErrors().isEmpty() && lexer.getErrors().isEmpty()){
                System.out.println("***Successful Parse***");
            }
            else{
                if(!parser.getErrors().isEmpty()){
                    System.out.println("*** Parser Errors ***"); 
                    for(String s : parser.getErrors()) System.out.println(s);
                }

                if(!lexer.getErrors().isEmpty()){
                    System.out.println("*** Lexer Errors ***"); 
                    for(String s : lexer.getErrors()) System.out.println(s);
                }
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

@@ -298,29 +298,560 @@
 n;%0A%0A
-%0Apublic class Tiger %7B
+import java.util.Queue;%0Aimport java.util.LinkedList;%0A%0A%0Apublic class Tiger %7B%0A%0A    private static void bfs(CommonTree root)%7B%0A        Queue q = new LinkedList();%0A        q.add(root);%0A%0A        while(q.peek() != null)%7B%0A            CommonTree node = (CommonTree)q.remove();%0A            System.out.println(%22Node: %22+ node.getText());%0A            if (node.getChildren() != null) %7B%0A                for(Object t: node.getChildren())%7B%0A                    if(t != null)%0A                        q.add((CommonTree)t);%0A                %7D %0A            %7D%0A        %7D%0A    %7D%0A
 %0A   
@@ -2299,32 +2299,44 @@
   %7D%0A            
+%0A           
 System.out.print
@@ -2341,16 +2341,16 @@
 ntln();%0A
-
 %0A       
@@ -2416,24 +2416,60 @@
 getTree());%0A
+            bfs(tree);%0A            %0A
             
@@ -2511,24 +2511,24 @@
 enerator();%0A
-
             
@@ -2556,32 +2556,45 @@
 en.toDOT(tree);%0A
+            %0A
             writ

add bfs