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