Class Generator


The class generator program generates classes given a text like:
 

package AST;

on PrintWriter "import java.io.*;"
on Hashtable   "import java.util.*;"
on Vector      "import java.util.*;"

abstract class Statement
  abstract void genC( PrintWriter out, int indent );
end

class WhileStatement : Statement
  void genC(PrintWriter out, int indent);
  Type exprType : get;
  StatementList statementList;

end

class ForStatement : Statement
  void genC(PrintWriter out, int indent);
  Variable v : get;
  Type exprType : get;
  - boolean changeIndex : get set ;
  StatementList statementList;
end

  The program will generates classes Statement, WhileStatement and ForStatement. Class WhileStatement will have methods genC and  getExprType. genC will have an empty body. getExprType will be generated because there is a "get" after the definition of instance variable "exprType". A constructor for WhileStatement will be generated with parameters exprType and statementList, the class instance variables. Method genC has a parameter type "PrintWriter". Therefore, there will be an import for "java.io.*"  before WhileStatement declaration since one of  the  "on" clauses in the text above says "If PrintWriter is used,  import java.io.*". See class WhileStatement. Note WhileStatement inherits from Statement.
     Class ForStatement has a constructor with variables v, exprType, and statementList. Variable changeIndex is not put there because it is prefixed by a - signal.

     Get the classgen program and unzip it in a directory c:\tools\classgen. If you already have java_cup in c:\tools, you will need not to unzip java_cup. Set the classpath to c:\tools\classgen;c:\tools. We assume that, if you have java_cup, then it is in directory c:\tools. See file pre.bat.
    Now  if you have your AST definition, a file containing a text like shown above, in file asa.txt, type at a DOS window:
            java  Main asa.txt
you will create several files, one for each class.