COP5555 HW6 CodeGenVisitor Help:

1. Make sure your HW submission has "cop5555.jar" file in it.
   It should includes: cop5555/Scanner.java, cop5555/Parser.java, cop5555/SyntaxException.java, cop5555/ContextVisitor.java, cop5555/ContextException.java, cop5555/CodeGenVisitor.java

2. Please submit cop5555_ast package (and runtime.jar if you have changed) as well,
Make sure you changed ForEachStatement.(foreach ident in expr do block endfor)

3. Don't change cop5555_tokens package.

4. Don't submit your .class files

5. Make sure Parser.parse(), ContextVisitor.visitProgram(), and CodeGenVisitor.visitProgram() methods are both public.

6. This is a code for simple test. Following table shows expected output.

import java.io.*;
import cop5555.*;
import cop5555_ast.*;

public class CodeGenTest
{
  public static void main(String[] args) throws IOException
  {
   BufferedReader r;
   PrintStream out;
   if (args.length == 0)
   {
    System.out.println("error: missing input file");
    System.exit(1);
   }
   r = new BufferedReader(new FileReader(args[0]));
   Parser parser = new Parser(r);
   Program tree = null;
   try
   {
    tree = (Program) parser.parse();
    ASTVisitor v = new ContextVisitor();
    v.visitProgram(tree, null);
    ASTVisitor gen = new CodeGenVisitor();
    gen.visitProgram(tree,null);
   }
   catch (Exception e)
   { e.printStackTrace(); }
  }
}
Example Input Generated class file Output
program game {
  if (true)
  then{ write "Go Gator!";}
  else {write "Hello World.";}
  endif;
}
game.class >/depot/c1/JAVA-2007-01/JDK-6/java-6/bin/java game
Go Gator!
program test {
   list[int] x,y,z,w;
   x := {1,2,3};
   y := {1,2,3};
   z := {1,3};
   w := x;

   write x=y;
   write x==y;
   write x!=y;

   write x=w;
   write x==w;
   write x!=w;

   write y=w;
   write y==w;
   write y!=w;

   write y=z;
   write y==z;
   write y!=z;
}
test.class >/depot/c1/JAVA-2007-01/JDK-6/java-6/bin/java test
>false
>true
>true
>true
>true
>false
>false
>true
>true
>false
>false
>true


Note: Make sure to test your program at eclipse.cise.ufl.edu machine. We will use this machine to test.

Good luck!