COP5555 HW4 ContextVisitor 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

2. If you added fields and methods to the AST nodes, do please submit cop5555_ast package as well,
   but if you did not make any modifications to this package, please do not submit.

3. Don't change cop5555_tokens package

4. Don't submit your .class files

5. Make sure Scanner.next() and Parser.parse() methods are both public.

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

import java.io.*;

public class TestContext{

    public static void main(String args[]){

        cop5555.Parser p = null;
        Reader r = null;

        try { r = new BufferedReader ( new FileReader(args[0])); }
        catch( IOException e ) { System.exit(-1); }

        try{ p = new cop5555.Parser(r); }
        catch(IOException e){ System.exit(-1); }
        try{
          cop5555_ast.AST tree = p.parse();
           cop5555.ContextVisitor v = new cop5555.ContextVisitor();
          tree.visit(v,null);
        }
        catch(cop5555.SyntaxException e){ System.out.println(e); }
        catch(cop5555.ContexException e){ System.out.println(e); }
        catch(Exception e){ System.out.println(e); }
    }
}
Example Input Output
program errorTest extends error {} cop5555.SyntaxException: expected token LBRACE
IDENT extends:0,18
program sample1 { procedure p(bool x) returns int {}
              write(call p(3)); }
cop5555.ContextException:incompatible parameter types
CALL:1,20
program sample2 { procedure p(int x) returns int{}
              write(call p(3)); }
 


Note: The toString() method of ContextException will not be graded, but it is very helpful for you to locate the error.

This program is more difficult than the previous ones. Good luck!