1generate(3)                         ANTLR3C                        generate(3)
2
3
4

NAME

6       generate - Generating C
7
8

Generating C

10       Before discussing how we compile or call the generated C code, we need
11       to know how to invoke the C code generator. This is achieved within the
12       grammar file itself, using the language option:
13
14       options {   language = C;}
15
16       The code generator consists of a single .java file within the standard ANTLR tool jar, and a code generation template,
17       used by the StringTemplate engine, which drives code generation for all language targets. In fact you can make copies of the C.stg
18       and AST.stg templates and make changes to them (though you are encouraged not to, as it is better to provide bug fixes or
19       enhancements which we are happy to receive requests for and will do out best to incorporate.
20
21       If you are working in the Windows environment, with Visual Studio 2005 or later, you may wish to utilize the custom rulefile
22       provided in the C source code distribution under the <code>./vs2005</code> directory for this purpose. If you are using a pre-built
23       library then you can also download this rule file directly from the FishEye source code browser for ANTLR3.
24
25       In order to use the rulefile, you must adopt the following suffixes for your grammar files, though they are otherwise optional:
26
27       <table>
28
29       <tr>
30       <th> Suffix </th>
31       <th> Grammar should contain... </th>
32       </tr>
33       <tr>
34       <td> .g3l </td>
35       <td> A lexer grammar specification only. </td>
36       </tr>
37       <tr>
38       <td> .g3p </td>
39       <td> A parser grammar specification only. </td>
40       </tr>
41       <tr>
42       <td> .g3pl </td>
43       <td> A combined lexer and parser specification. </td>
44       </tr>
45       <tr>
46       <td> .g3t </td>
47       <td> A tree grammar specification. </td>
48       </tr>
49
50       </table>
51
52       You may also wish to use these suffixes if you are building your projects using Makefiles, as this makes the output deterministic.
53       However in this case a much better solution is probably to utilize the -depend option of the Antlr tool, which should tell your
54       Makefile what the grammar files generates, irrespective of its suffix. ANTLR does not care about the actual suffix you use for
55       your grammar file, so building for multiple platforms is relatively easy.
56
57       <b>NOTE:</b> Your grammar source, regardless of suffix must be named the same as the grammar statement within it. Grammar xyz
58       must be contained within a file called xyz.<i>anything</i>
59
60
61Version 3.3.1                   Tue Jan 28 2020                    generate(3)
Impressum