You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

jjtree.html 15 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>JJTree Task</title>
  20. </head>
  21. <body>
  22. <h2 id="jjtree">JJTree</h2>
  23. <h3>Description</h3>
  24. <p>Invokes the <a href="https://javacc.org/">JJTree</a> preprocessor for the JavaCC compiler
  25. compiler. It inserts parse tree building actions at various places in the JavaCC source that it
  26. generates. The output of JJTree is run through JavaCC to create the parser.</p>
  27. <p>To use the <code>jjtree</code> task, set the <var>target</var> attribute to the name of the
  28. JJTree grammar file to process. You also need to specify the directory containing the JavaCC
  29. installation using the <var>javacchome</var> attribute, so that Ant can find the JavaCC
  30. classes. Optionally, you can also set the <var>outputdirectory</var> to write the generated JavaCC
  31. grammar and node files to a specific directory. Otherwise <code>jjtree</code> writes the generated
  32. JavaCC grammar and node files to the directory containing the JJTree grammar file. As an extra
  33. option, you can also set the <var>outputfile</var> to write the generated JavaCC grammar file to a
  34. specific (directory and) file. Otherwise <code>jjtree</code> writes the generated JavaCC grammar
  35. file as the JJTree grammar file with a suffix <samp>.jj</samp>.</p>
  36. <p>This task only invokes JJTree if the grammar file is newer than the generated JavaCC file.</p>
  37. <h3>Parameters</h3>
  38. <table class="attr">
  39. <tr>
  40. <th>Attribute</th>
  41. <th>Description</th>
  42. <th>Required</th>
  43. </tr>
  44. <tr>
  45. <td>target</td>
  46. <td>The JJTree grammar file to process.</td>
  47. <td>Yes</td>
  48. </tr>
  49. <tr>
  50. <td>javacchome</td>
  51. <td>The directory containing the JavaCC distribution.</td>
  52. <td>Yes</td>
  53. </tr>
  54. <tr>
  55. <td>outputdirectory</td>
  56. <td>The directory to write the generated JavaCC grammar and node files to. If not set, the files
  57. are written to the directory containing the grammar file.</td>
  58. <td>No</td>
  59. </tr>
  60. <tr>
  61. <td>outputfile</td>
  62. <td>The file to write the generated JavaCC grammar file to. If not set, the file is written with
  63. the same name as the JJTree grammar file but with a the suffix <code>.jj</code>. This is a
  64. filename relative to <var>outputdirectory</var> if specified, the project's basedir.</td>
  65. <td>No</td>
  66. </tr>
  67. <tr>
  68. <td>buildnodefiles</td>
  69. <td>Sets the BUILD_NODE_FILES grammar option. This is a boolean option.</td>
  70. <td>No</td>
  71. </tr>
  72. <tr>
  73. <td>multi</td>
  74. <td>Sets the MULTI grammar option. This is a boolean option.</td>
  75. <td>No</td>
  76. </tr>
  77. <tr>
  78. <td>nodedefaultvoid</td>
  79. <td>Sets the NODE_DEFAULT_VOID grammar option. This is a boolean option.</td>
  80. <td>No</td>
  81. </tr>
  82. <tr>
  83. <td>nodefactory</td>
  84. <td>Sets the NODE_FACTORY grammar option. This is boolean option.</td>
  85. <td>No</td>
  86. </tr>
  87. <tr>
  88. <td>nodescopehook</td>
  89. <td>Sets the NODE_SCOPE_HOOK grammar option. This is a boolean option.</td>
  90. <td>No</td>
  91. </tr>
  92. <tr>
  93. <td>nodeusesparser</td>
  94. <td>Sets the NODE_USES_PARSER grammar option. This is a boolean option.</td>
  95. <td>No</td>
  96. </tr>
  97. <tr>
  98. <td>static</td>
  99. <td>Sets the STATIC grammar option. This is a boolean option.</td>
  100. <td>No</td>
  101. </tr>
  102. <tr>
  103. <td>visitor</td>
  104. <td>Sets the VISITOR grammar option. This is a boolean option.</td>
  105. <td>No</td>
  106. </tr>
  107. <tr>
  108. <td>nodepackage</td>
  109. <td>Sets the NODE_PACKAGE grammar option. This is a string option.</td>
  110. <td>No</td>
  111. </tr>
  112. <tr>
  113. <td>visitorexception</td>
  114. <td>Sets the VISITOR_EXCEPTION grammar option. This is a string option.</td>
  115. <td>No</td>
  116. </tr>
  117. <tr>
  118. <td>nodeprefix</td>
  119. <td>Sets the NODE_PREFIX grammar option. This is a string option.</td>
  120. <td>No</td>
  121. </tr>
  122. <tr>
  123. <td>maxmemory</td>
  124. <td>Max amount of memory to allocate to the forked JVM. <em>since Ant 1.8.3</em></td>
  125. <td>No</td>
  126. </tr>
  127. </table>
  128. <h3>Example</h3>
  129. <pre>
  130. &lt;jjtree target="src/Parser.jjt"
  131. outputdirectory="build/src"
  132. javacchome="c:/program files/JavaCC"
  133. nodeusesparser="true"/&gt;</pre>
  134. <p>This invokes JJTree on grammar file <samp>src/Parser.jjt</samp>, writing the generated grammar
  135. file, <samp>Parser.jj</samp>, file to <samp>build/src</samp>. The grammar option NODE_USES_PARSER is
  136. set to <q>true</q> when invoking JJTree.</p>
  137. <h3>Comparison output locations between command line JJTree and different Ant <code>taskdef</code>
  138. versions</h3>
  139. <table>
  140. <thead class="no-bold">
  141. <tr>
  142. <th><strong>Command line JJTree options</strong> and <em>generated files</em> (working directory: <samp>/tmp</samp>)</th>
  143. <th><strong>Ant 1.5.3</strong> versus command line</th>
  144. <th><strong>Ant 1.6</strong> versus command line</th>
  145. </tr>
  146. </thead>
  147. <tbody>
  148. <tr>
  149. <td><pre><b>jjtree grammar.jjt</b>
  150. /tmp/grammar.jj
  151. /tmp/&lt;generated&gt;.java</pre>
  152. </td>
  153. <td>Same</td>
  154. <td>Same</td>
  155. </tr>
  156. <tr>
  157. <td><pre><b>jjtree relative/grammar.jjt</b>
  158. /tmp/grammar.jj
  159. /tmp/&lt;generated&gt;.java</pre>
  160. </td>
  161. <td><pre>
  162. /tmp/relative/grammar.jj
  163. /tmp/relative/&lt;generated&gt;.java</pre>
  164. </td>
  165. <td>Same</td>
  166. </tr>
  167. <tr>
  168. <td><pre><b>jjtree /tmp/absolute/grammar.jjt</b>
  169. /tmp/grammar.jj
  170. /tmp/&lt;generated&gt;.java</pre>
  171. </td>
  172. <td><pre>
  173. /tmp/absolute/grammar.jj
  174. /tmp/absolute/&lt;generated&gt;.java</pre>
  175. </td>
  176. <td>Same</td>
  177. </tr>
  178. <tr>
  179. <td><pre><b>jjtree -OUTPUT_DIRECTORY:relative grammar.jjt</b>
  180. /tmp/relative/grammar.jj
  181. /tmp/relative/&lt;generated&gt;.java</pre>
  182. </td>
  183. <td>Same</td>
  184. <td>Same</td>
  185. </tr>
  186. <tr>
  187. <td><pre><b>jjtree -OUTPUT_DIRECTORY:relative relative/grammar.jjt</b>
  188. /tmp/relative/grammar.jj
  189. /tmp/relative/&lt;generated&gt;.java</pre>
  190. </td>
  191. <td>Same</td>
  192. <td>Same</td>
  193. </tr>
  194. <tr>
  195. <td><pre><b>jjtree -OUTPUT_DIRECTORY:relative /tmp/absolute/grammar.jjt</b>
  196. /tmp/relative/grammar.jj
  197. /tmp/relative/&lt;generated&gt;.java</pre>
  198. </td>
  199. <td>Same</td>
  200. <td>Same</td>
  201. </tr>
  202. <tr>
  203. <td><pre><b>jjtree -OUTPUT_DIRECTORY:/tmp/absolute/ grammar.jjt</b>
  204. /tmp/absolute/grammar.jj
  205. /tmp/absolute/&lt;generated&gt;.java</pre>
  206. </td>
  207. <td>Same</td>
  208. <td>Same</td>
  209. </tr>
  210. <tr>
  211. <td><pre><b>jjtree -OUTPUT_DIRECTORY:/tmp/absolute/ relative/grammar.jjt</b>
  212. /tmp/absolute/grammar.jj
  213. /tmp/absolute/&lt;generated&gt;.java</pre>
  214. </td>
  215. <td>Same</td>
  216. <td>Same</td>
  217. </tr>
  218. <tr>
  219. <td><pre><b>jjtree -OUTPUT_DIRECTORY:/tmp/absolute/ /tmp/absolute/grammar.jjt</b>
  220. /tmp/absolute/grammar.jj
  221. /tmp/absolute/&lt;generated&gt;.java</pre>
  222. </td>
  223. <td>Same</td>
  224. <td>Same</td>
  225. </tr>
  226. <tr>
  227. <td><pre><b>jjtree -OUTPUT_FILE:output.jj grammar.jjt</b>
  228. /tmp/output.jj
  229. /tmp/&lt;generated&gt;.java</pre>
  230. </td>
  231. <td>Not Supported</td>
  232. <td>Same</td>
  233. </tr>
  234. <tr>
  235. <td><pre><b>jjtree -OUTPUT_FILE:output.jj relative/grammar.jjt</b>
  236. /tmp/output.jj
  237. /tmp/&lt;generated&gt;.java</pre>
  238. </td>
  239. <td>Not Supported</td>
  240. <td>Same</td>
  241. </tr>
  242. <tr>
  243. <td><pre><b>jjtree -OUTPUT_FILE:output.jj /tmp/absolute/grammar.jjt</b>
  244. /tmp/output.jj
  245. /tmp/&lt;generated&gt;.java</pre>
  246. </td>
  247. <td>Not Supported</td>
  248. <td>Same</td>
  249. </tr>
  250. <tr>
  251. <td><pre><b>jjtree -OUTPUT_FILE:output.jj -OUTPUT_DIRECTORY:relative grammar.jjt</b>
  252. /tmp/relative/output.jj
  253. /tmp/relative/&lt;generated&gt;.java</pre>
  254. </td>
  255. <td>Not Supported</td>
  256. <td>Same</td>
  257. </tr>
  258. <tr>
  259. <td><pre><b>jjtree -OUTPUT_FILE:output.jj -OUTPUT_DIRECTORY:relative relative/grammar.jjt</b>
  260. /tmp/relative/output.jj
  261. /tmp/relative/&lt;generated&gt;.java</pre>
  262. </td>
  263. <td>Not Supported</td>
  264. <td>Same</td>
  265. </tr>
  266. <tr>
  267. <td><pre><b>jjtree -OUTPUT_FILE:output.jj -OUTPUT_DIRECTORY:relative /tmp/absolute/grammar.jjt</b>
  268. /tmp/relative/output.jj
  269. /tmp/relative/&lt;generated&gt;.java</pre>
  270. </td>
  271. <td>Not Supported</td>
  272. <td>Same</td>
  273. </tr>
  274. <tr>
  275. <td><pre><b>jjtree -OUTPUT_FILE:output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ grammar.jjt</b>
  276. /tmp/absolute/output.jj
  277. /tmp/absolute/&lt;generated&gt;.java</pre>
  278. </td>
  279. <td>Not Supported</td>
  280. <td>Same</td>
  281. </tr>
  282. <tr>
  283. <td><pre><b>jjtree -OUTPUT_FILE:output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ relative/grammar.jjt</b>
  284. /tmp/absolute/output.jj
  285. /tmp/absolute/&lt;generated&gt;.java</pre>
  286. </td>
  287. <td>Not Supported</td>
  288. <td>Same</td>
  289. </tr>
  290. <tr>
  291. <td><pre><b>jjtree -OUTPUT_FILE:output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ /tmp/absolute/grammar.jjt</b>
  292. /tmp/absolute/output.jj
  293. /tmp/absolute/&lt;generated&gt;.java</pre>
  294. </td>
  295. <td>Not Supported</td>
  296. <td>Same</td>
  297. </tr>
  298. <tr>
  299. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj grammar.jjt</b>
  300. /tmp/subdir/output.jj
  301. /tmp/&lt;generated&gt;.java</pre>
  302. </td>
  303. <td>Not Supported</td>
  304. <td>Same</td>
  305. </tr>
  306. <tr>
  307. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj relative/grammar.jjt</b>
  308. /tmp/subdir/output.jj
  309. /tmp/&lt;generated&gt;.java</pre>
  310. </td>
  311. <td>Not Supported</td>
  312. <td>Same</td>
  313. </tr>
  314. <tr>
  315. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj /tmp/absolute/grammar.jjt</b>
  316. /tmp/subdir/output.jj
  317. /tmp/&lt;generated&gt;.java</pre>
  318. </td>
  319. <td>Not Supported</td>
  320. <td>Same</td>
  321. </tr>
  322. <tr>
  323. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj -OUTPUT_DIRECTORY:relative grammar.jjt</b>
  324. /tmp/relative/subdir/output.jj
  325. /tmp/relative/&lt;generated&gt;.java</pre>
  326. </td>
  327. <td>Not Supported</td>
  328. <td>Same</td>
  329. </tr>
  330. <tr>
  331. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj -OUTPUT_DIRECTORY:relative relative/grammar.jjt</b>
  332. /tmp/relative/subdir/output.jj
  333. /tmp/relative/&lt;generated&gt;.java</pre>
  334. </td>
  335. <td>Not Supported</td>
  336. <td>Same</td>
  337. </tr>
  338. <tr>
  339. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj -OUTPUT_DIRECTORY:relative /tmp/absolute/grammar.jjt</b>
  340. /tmp/relative/subdir/output.jj
  341. /tmp/relative/&lt;generated&gt;.java</pre>
  342. </td>
  343. <td>Not Supported</td>
  344. <td>Same</td>
  345. </tr>
  346. <tr>
  347. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ grammar.jjt</b>
  348. /tmp/absolute/subdir/output.jj
  349. /tmp/absolute/&lt;generated&gt;.java</pre>
  350. </td>
  351. <td>Not Supported</td>
  352. <td>Same</td>
  353. </tr>
  354. <tr>
  355. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ relative/grammar.jjt</b>
  356. /tmp/absolute/subdir/output.jj
  357. /tmp/absolute/&lt;generated&gt;.java</pre>
  358. </td>
  359. <td>Not Supported</td>
  360. <td>Same</td>
  361. </tr>
  362. <tr>
  363. <td><pre><b>jjtree -OUTPUT_FILE:subdir/output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ /tmp/absolute/grammar.jjt</b>
  364. /tmp/absolute/subdir/output.jj
  365. /tmp/absolute/&lt;generated&gt;.java</pre>
  366. </td>
  367. <td>Not Supported</td>
  368. <td>Same</td>
  369. </tr>
  370. <tr>
  371. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj grammar.jjt</b>
  372. /tmp/subdir/output.jj
  373. /tmp/&lt;generated&gt;.java</pre>
  374. </td>
  375. <td>Not Supported</td>
  376. <td>Same</td>
  377. </tr>
  378. <tr>
  379. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj relative/grammar.jjt</b>
  380. /tmp/subdir/output.jj
  381. /tmp/&lt;generated&gt;.java</pre>
  382. </td>
  383. <td>Not Supported</td>
  384. <td>Same</td>
  385. </tr>
  386. <tr>
  387. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj /tmp/absolute/grammar.jjt</b>
  388. /tmp/subdir/output.jj
  389. /tmp/&lt;generated&gt;.java</pre>
  390. </td>
  391. <td>Not Supported</td>
  392. <td>Same</td>
  393. </tr>
  394. <tr>
  395. <td><pre><b>jjtree -OUTPUT_FILE:<i>D:</i>/tmp/subdir/output.jj grammar.jjt</b>
  396. /tmp/subdir/output.jj
  397. /tmp/&lt;generated&gt;.java</pre>
  398. </td>
  399. <td>Not Supported</td>
  400. <td>Not Supported *)</td>
  401. </tr>
  402. <tr>
  403. <td><pre><b>jjtree -OUTPUT_FILE:<i>D:</i>/tmp/subdir/output.jj relative/grammar.jjt</b>
  404. /tmp/subdir/output.jj
  405. /tmp/&lt;generated&gt;.java</pre>
  406. </td>
  407. <td>Not Supported</td>
  408. <td>Not Supported *)</td>
  409. </tr>
  410. <tr>
  411. <td><pre><b>jjtree -OUTPUT_FILE:<i>D:</i>/tmp/subdir/output.jj /tmp/absolute/grammar.jjt</b>
  412. /tmp/subdir/output.jj
  413. /tmp/&lt;generated&gt;.java</pre>
  414. </td>
  415. <td>Not Supported</td>
  416. <td>Not Supported *)</td>
  417. </tr>
  418. <tr>
  419. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj -OUTPUT_DIRECTORY:relative grammar.jjt</b>
  420. /tmp/relative/tmp/subdir/output.jj
  421. /tmp/relative/&lt;generated&gt;.java</pre>
  422. </td>
  423. <td>Not Supported</td>
  424. <td>Same</td>
  425. </tr>
  426. <tr>
  427. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj -OUTPUT_DIRECTORY:relative relative/grammar.jjt</b>
  428. /tmp/relative/tmp/subdir/output.jj
  429. /tmp/relative/&lt;generated&gt;.java</pre>
  430. </td>
  431. <td>Not Supported</td>
  432. <td>Same</td>
  433. </tr>
  434. <tr>
  435. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj -OUTPUT_DIRECTORY:relative /tmp/absolute/grammar.jjt</b>
  436. /tmp/relative/tmp/subdir/output.jj
  437. /tmp/relative/&lt;generated&gt;.java</pre>
  438. </td>
  439. <td>Not Supported</td>
  440. <td>Same</td>
  441. </tr>
  442. <tr>
  443. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ grammar.jjt</b>
  444. /tmp/absolute/tmp/subdir/output.jj
  445. /tmp/absolute/&lt;generated&gt;.java</pre>
  446. </td>
  447. <td>Not Supported</td>
  448. <td>Same</td>
  449. </tr>
  450. <tr>
  451. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ relative/grammar.jjt</b>
  452. /tmp/absolute/tmp/subdir/output.jj
  453. /tmp/absolute/&lt;generated&gt;.java</pre>
  454. </td>
  455. <td>Not Supported</td>
  456. <td>Same</td>
  457. </tr>
  458. <tr>
  459. <td><pre><b>jjtree -OUTPUT_FILE:/tmp/subdir/output.jj -OUTPUT_DIRECTORY:/tmp/absolute/ /tmp/absolute/grammar.jjt</b>
  460. /tmp/absolute/tmp/subdir/output.jj
  461. /tmp/absolute/&lt;generated&gt;.java</pre>
  462. </td>
  463. <td>Not Supported</td>
  464. <td>Same</td>
  465. </tr>
  466. </tbody>
  467. </table>
  468. <p>*) <strong>Footnote</strong>: When running JJTree with the Ant <code>taskdef jjtree</code> the
  469. option <code>-OUTPUT_DIRECTORY</code> must always be set, because the project's <var>basedir</var>
  470. and the Ant working directory might differ. So even if you don't specify
  471. the <var>outputdirectory</var> for <code>taskdef jjtree</code>, JJTree will be called with
  472. the <code>-OUTPUT_DIRECTORY</code> set to the project's <var>basedir</var>. But when
  473. the <code>-OUTPUT_DIRECTORY</code> is set, the <code>-OUTPUT_FILE</code> setting is handled as if
  474. relative to this <code>-OUTPUT_DIRECTORY</code>. Thus when the <code>-OUTPUT_FILE</code> is absolute
  475. or contains a drive letter we have a problem. Therefore absolute <var>outputfile</var>s (when
  476. the <var>outputdirectory</var> isn't specified) are made relative to the default directory. And for
  477. this reason <var>outputfile</var>s that contain a drive letter can't be supported.</p>
  478. <p>By the way: specifying a drive letter in the <code>-OUTPUT_FILE</code> when
  479. the <code>-OUTPUT_DIRECTORY</code> is set, also results in strange behavior when running JJTree from
  480. the command line.</p>
  481. </body>
  482. </html>