-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.xml
executable file
·183 lines (147 loc) · 6.19 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!-- Build file for INF5110/INF9110 Obligatory exercise -->
<project name="INF5110/INF9110 Obligatory exercise" default="menu" basedir=".">
<target name="menu" >
<echo>Targets</echo>
<echo>clean - Cleans up the project</echo>
<echo>build - Build compiler</echo>
<echo>run - Run compiler</echo>
<echo>compile-example-eval - Compile Example Eval</echo>
<echo>run-example-eval - Run Example Eval</echo>
<echo>compile-example-par - Compile Example Par</echo>
<echo>run-example-par - Run Example Par</echo>
</target>
<!-- Path definitions -->
<path id="path-cup">
<pathelement location="./lib/java-cup-11a.jar"/>
<pathelement location="./lib/JFlex.jar"/>
</path>
<path id="path-run">
<path refid="path-cup"/>
<pathelement location="build/classes" />
</path>
<!-- Task definitions -->
<taskdef classname="JFlex.anttask.JFlexTask" name="jflex" classpathref="path-cup" />
<taskdef classname="java_cup.anttask.CUPTask" name="cup" classpathref="path-cup"/>
<!-- Target definitions -->
<target name="init">
<!-- Directories and files that exist. -->
<property name="dir.base" value="${basedir}"/>
<property name="dir.build" value="${dir.base}/build"/>
<property name="dir.src-gen" value="${dir.base}/src-gen"/>
<property name="dir.src-examples" value="${dir.base}/src-examples"/>
<property name="dir.src" value="${dir.base}/src"/>
<property name="dir.desc" value="${dir.base}/desc"/>
<!-- Directories and files to be created. -->
<property name="dir.classes" value="${dir.build}/classes"/>
</target>
<target name="clean" depends="init">
<delete includeemptydirs="true">
<fileset dir="${dir.build}" includes="**/*"/>
</delete>
<delete includeemptydirs="true">
<fileset dir="${dir.src-gen}" includes="**/*"/>
</delete>
</target>
<target name="mkdir" depends="init">
<mkdir dir="${dir.classes}"/>
</target>
<!-- Generic compile target -->
<target name="generic-compile" depends="">
<javac srcdir="${dir.src-gen}" destdir="${dir.classes}" debug="true" includes="${package-name}/*.java" classpathref="path-cup"/>
</target>
<!-- Generic compile AST-nodes target -->
<target name="generic-compile-ast" depends="">
<javac srcdir="${dir.src-examples}" destdir="${dir.classes}" debug="true" includes="**/*.java" classpathref="path-cup"/>
</target>
<!-- Generate scanner and parser using JFlex and CUP -->
<target name="generate" depends="mkdir">
<jflex file="./grammars/oblig1.lex" destdir="src-gen"/>
<cup srcfile="./grammars/oblig1.cup" destdir="src-gen" interface="true" />
</target>
<!-- Compile Java Files and store in /build/classes directory -->
<target name="compile" depends="generate">
<javac includeantruntime="false" srcdir="${dir.src}" destdir="${dir.classes}" debug="true" includes="**/*.java" classpathref="path-cup" sourcepath="${dir.src-gen}"/>
<javac includeantruntime="false" srcdir="${dir.src-gen}" destdir="${dir.classes}" debug="true" includes="**/*.java" classpathref="path-cup" sourcepath="${dir.src}" />
</target>
<!-- Main target -->
<target name="build" depends="compile"/>
<!-- Run the system -->
<target name="run" depends="init">
<java classname="compiler.Compiler" classpathref="path-run" fork="true">
<arg value="compila-code/Compila.cmp"/>
<arg value="compila-ast/Compila.ast"/>
<arg value="compila-bin/Compila.bin"/>
</java>
</target>
<!-- Generate scanner and parser for example eval -->
<target name="generate-example-eval" depends="init, mkdir">
<jflex file="./grammars/expression-eval.lex" destdir="src-gen"/>
<cup srcfile="./grammars/expression-eval.cup" destdir="src-gen" interface="true" />
</target>
<!-- Compile code for example eval -->
<target name="compile-example-eval" depends="generate-example-eval">
<antcall target="generic-compile">
<param name="package-name" value="expression_eval"/>
</antcall>
</target>
<!-- Run example eval. -->
<target name="run-example-eval" depends="init">
<java classname="expression_eval.parser" classpathref="path-run">
<arg value="2+3*3;
1 + 2 * 1 + 1;
1+2+3+4*2*3*2+1;
3/3+1;
1 + 5 / 2 + 9;"/>
</java>
</target>
<!-- Generate scanner and parser for example par -->
<target name="generate-example-par" depends="init, mkdir">
<jflex file="./grammars/expression-par.lex" destdir="src-gen"/>
<cup srcfile="./grammars/expression-par.cup" destdir="src-gen" interface="true" />
</target>
<!-- Compile code for example par -->
<target name="compile-example-par" depends="generate-example-par">
<antcall target="generic-compile-ast" />
<antcall target="generic-compile">
<param name="package-name" value="expression_par"/>
</antcall>
</target>
<!-- Run example par -->
<target name="run-example-par" depends="init">
<java classname="expression_par.parser" classpathref="path-run">
<arg value="./input-examples/test-eval.txt"/>
</java>
</target>
<!-- Compile test classes -->
<target name="compile-test" depends="mkdir">
<javac srcdir="${dir.src}" destdir="${dir.classes}" debug="true"
includes="test/*.java" classpathref="path-cup" />
</target>
<!-- Run tests -->
<target name="test" depends="compile-test">
<java classname="test.Tester" classpathref="path-run" >
<arg value="tests"/>
</java>
</target>
<!-- Run compiler on example RunMe -->
<target name="compile-runme" depends="init">
<java classname="compiler.Compiler" classpathref="path-run" fork="true">
<arg value="code-examples/RunMe.cmp"/>
<arg value="code-examples/RunMe.ast"/>
<arg value="code-examples/RunMe.bin"/>
</java>
</target>
<!-- List example RunMe -->
<target name="list-runme" depends="init">
<java classname="runtime.VirtualMachine" classpathref="path-run">
<arg value="-l"/>
<arg value="code-examples/RunMe.bin"/>
</java>
</target>
<!-- Run vm on example RunMe -->
<target name="run-runme" depends="init">
<java classname="runtime.VirtualMachine" classpathref="path-run" fork="true">
<arg value="code-examples/RunMe.bin"/>
</java>
</target>
</project>