<!-- A project is one or more targets that executes tasks. This project
     has three targets: build, clean, and test. The build target is
     set as the default target and used if no target is supplied. -->
<project name="Compiler" default="build" basedir=".">

  <!-- The name used for the jjt/jj files  -->
  <property name="parser.name" value="CalcParser"/>

  <!-- The directory where generated files will be stored -->
  <property name="package" value="AST"/>
	
  <!-- The directory where tools like javacc, junit, and jastadd are stored. -->
  <property name="tools" value="tools"/>

  <!-- The JastAdd ANT task -->
  <taskdef classname="jastadd.JastAddTask" name="jastadd" classpath="${tools}/jastadd2.jar" />

  <!-- gen:
    - Creates a directory for generated files.
    - Generates the AST classes using jastadd.
    - Generates the parser using jjtree and javacc. -->
  <target name="gen">
    <mkdir dir="${package}"/>
    <jastadd package="${package}" jjtree="true" grammar="${parser.name}">
      <fileset dir=".">
        <include name="**/*.ast"/>
        <include name="**/*.jrag"/>
        <include name="**/*.jadd"/>
      </fileset>
    </jastadd>
    <jjtree
      target="${parser.name}.jjt"
      outputdirectory="${package}"
      javacchome="${tools}"
      buildnodefiles="true"
      static="false"
      multi="true"
      visitor="true"
      nodedefaultvoid="true"
      nodeprefix='""'
      nodepackage="${package}"
    />
    <javacc
      target="${package}/${parser.name}.jj"
      outputdirectory="${package}"
      javacchome="${tools}"
      buildparser="true"
      buildtokenmanager="true"
      static="false"
    />
  </target>
	
  <!-- build: (automatically runs "gen" if needed)
    - compiles all java files
    - intended to be used from the command line
      (in Eclipse you don't need this target since Eclipse compiles
      java files automatically)
    - you can change "javac1.4" to "jikes" for faster compilation -->
  <target name="build" depends="gen">
    <javac 
      compiler="javac1.4"
      srcdir="."
      debug="true"
      classpath="${tools}/junit.jar"
    />
  </target>
  
  <!-- clean:
    - deletes the directory holding generated files
    - deletes all .class files (recursively) -->
  <target name="clean">
    <delete dir="${package}"/>
    <delete>
      <fileset dir="." includes="**/*.class"/>
    </delete>
  </target>

  <!-- test: (automatically runs "build" if needed)
    - runs a set of tests by starting the Java program TestAll
    - intended to be used from the command line
      (In Eclipse you don't need this target since you can run testcases
      directly in Eclipse from a menu command.) -->
  <target name="test" depends="build">
    <java 
      classname="TestAll"
      classpath=".:${tools}/junit.jar" 
      fork="true" 
      dir="."
    />
  </target>
</project>

