xref: /aosp_15_r20/external/antlr/runtime/C/doxygen/mainpage.dox (revision 16467b971bd3e2009fad32dd79016f2c7e421deb)
1*16467b97STreehugger Robot// Main page documentation for ANTLR3C runtime. Contains
2*16467b97STreehugger Robot// doxygen things only.
3*16467b97STreehugger Robot//
4*16467b97STreehugger Robot
5*16467b97STreehugger Robot/// \mainpage ANTLR3 C Runtime API and Usage Guide.
6*16467b97STreehugger Robot///
7*16467b97STreehugger Robot/// \section version Version 3.3.1
8*16467b97STreehugger Robot///
9*16467b97STreehugger Robot/// This documentation is specifically for the C rutime version 3.1.x.x, which is
10*16467b97STreehugger Robot/// specifically for use with version 3.1.x.x of the ANTLR recognizer generation
11*16467b97STreehugger Robot/// tool. While some of the documentation may well apply to prior or future versions
12*16467b97STreehugger Robot/// you should consult the manuals for the correct version whenever possible.
13*16467b97STreehugger Robot///
14*16467b97STreehugger Robot/// \section chchchchangeesss Changes from 3.2 to 3.3.1
15*16467b97STreehugger Robot///
16*16467b97STreehugger Robot/// Some changes in 3.3.1 may require small changes in your invoking programs or
17*16467b97STreehugger Robot/// in the grammar itself. Please read about them here before emailing the user group,
18*16467b97STreehugger Robot/// where you will be told to come and read about them here, unless they were missed
19*16467b97STreehugger Robot/// from this list.
20*16467b97STreehugger Robot///
21*16467b97STreehugger Robot/// - \subpage changes331 Check here for API changes
22*16467b97STreehugger Robot///
23*16467b97STreehugger Robot/// \section intro Introduction
24*16467b97STreehugger Robot///
25*16467b97STreehugger Robot/// The ANTLR3 recognizer generation tool is written in Java, but allows the generation
26*16467b97STreehugger Robot/// of code targeted for a number of other languages. Each target language provides a code
27*16467b97STreehugger Robot/// generation template for the tool and a runtime library for use by generated recognizers.
28*16467b97STreehugger Robot/// The C runtime tracks the Java runtime releases and in general when a new version of the
29*16467b97STreehugger Robot/// tool is released, a new version of the C runtime will be released at the same time.
30*16467b97STreehugger Robot///
31*16467b97STreehugger Robot/// The documentation here is in three parts:
32*16467b97STreehugger Robot///
33*16467b97STreehugger Robot/// - \subpage build Building the runtime itself from source code;
34*16467b97STreehugger Robot/// - \subpage generate How to tell ANTLR to generate code for the C target;
35*16467b97STreehugger Robot/// - \subpage buildrec How to build the generated code
36*16467b97STreehugger Robot/// - \subpage using Using the runtime and the libraries and so on;
37*16467b97STreehugger Robot/// - \subpage runtime The documentation of the runtime code and functions;
38*16467b97STreehugger Robot///
39*16467b97STreehugger Robot/// \section background Background Information
40*16467b97STreehugger Robot///
41*16467b97STreehugger Robot/// The ANTLR 3 C runtime and code generation templates were written by <a href="http://www.linkedin.com/in/jimidle"> Jim Idle</a>
42*16467b97STreehugger Robot/// (jimi|at|temporal-wave|dott/com) of <a href="http://www.temporal-wave.com">Temporal Wave LLC</a>.
43*16467b97STreehugger Robot///
44*16467b97STreehugger Robot/// The C runtime and therefore the code generated to utilize the runtime reflects the object model of the
45*16467b97STreehugger Robot/// Java version of the runtime as closely as a language without class structures and inheritance can.
46*16467b97STreehugger Robot/// Compromises have only been made where performance would be adversely affected such as minimizing the
47*16467b97STreehugger Robot/// number of pointer to pointer to pointer to function type structures that could ensue through trying to
48*16467b97STreehugger Robot/// model inheritance too exactly. Other differences include the use of token and string factories to minimize
49*16467b97STreehugger Robot/// the number of calls to system functions such as calloc().This model was adopted so that overriding any
50*16467b97STreehugger Robot/// default implementation of a function is relatively simple for the grammar programmer.
51*16467b97STreehugger Robot///
52*16467b97STreehugger Robot/// The generated code is free threading (subject to the systems calls used on any particular platform
53*16467b97STreehugger Robot/// being likewise free threading.)
54*16467b97STreehugger Robot///
55*16467b97STreehugger Robot/// \subsection model Runtime Model
56*16467b97STreehugger Robot///
57*16467b97STreehugger Robot/// As there is no such thing as an object reference in C, the runtime defines a number of typedef structs that reflect
58*16467b97STreehugger Robot/// the calling interface chosen by Terence Parr for the Java version of the same. The initialization of a parser,
59*16467b97STreehugger Robot/// lexer, input stream or other internal structure therefore consists of allocating the memory required for
60*16467b97STreehugger Robot/// an instance of the typedef struct that represents the interface, initializing any counters, and buffers etc,
61*16467b97STreehugger Robot/// then populating a number of pointers to functions that implement the equivalent of the methods in the Java class.
62*16467b97STreehugger Robot///
63*16467b97STreehugger Robot/// The use and initialization of the C versions of a parser is therefore similar to the examples given for Java,
64*16467b97STreehugger Robot/// but with a bent towards C of course. You may need to be aware of memory allocation and freeing operations
65*16467b97STreehugger Robot/// in certain environments such as Windows, where you cannot allocate memory in one DLL and free it in another.
66*16467b97STreehugger Robot///
67*16467b97STreehugger Robot/// The runtime provides a number of structures and interfaces that the author has found useful when writing action and
68*16467b97STreehugger Robot/// processing code within java parsers, and furthermore were required by the C runtime code if it was not to
69*16467b97STreehugger Robot/// depart too far from the logical layout of the Java model. These include the C equivalents of String, List,
70*16467b97STreehugger Robot/// Hashtable, Vector and Trie, implemented by pointers to structures. These are freely available for your own programming needs.
71*16467b97STreehugger Robot///
72*16467b97STreehugger Robot/// A goal of the generated code was to minimize the tracking, allocation and freeing of memory for reasons of both
73*16467b97STreehugger Robot/// performance and reliability. In essence any memory used by a lexer, parser or tree parser is automatically tracked and
74*16467b97STreehugger Robot/// freed when the instance of it is released. There are therefore factory functions for tokens and so on such that they
75*16467b97STreehugger Robot/// can be allocated in blocks and parceled out as they are required. They are all then freed in one go, minimizing the
76*16467b97STreehugger Robot/// risk of memory leaks and alloc/free thrashing. This has only one side effect, being that if you wish to preserve some structure generated by
77*16467b97STreehugger Robot/// the lexer, parser or tree parser, then you must make a copy of it before freeing those structures, and track it yourself
78*16467b97STreehugger Robot/// after that. In practice, it is easy enough just not to release the antlr generated components until you are
79*16467b97STreehugger Robot/// finished with their results.
80*16467b97STreehugger Robot///
81*16467b97STreehugger Robot/// \section targets Target Platforms
82*16467b97STreehugger Robot///
83*16467b97STreehugger Robot/// The C project is constructed such that it will compile on any reasonable ANSI C compiler in either 64 or 32 bit mode,
84*16467b97STreehugger Robot/// with all warnings turned on. This is true of both the runtime code and the generated code and has been summarily tested
85*16467b97STreehugger Robot/// with Visual Studio .Net (2003, 2005 and 2008) and later versions of gcc on Redhat Linux, as well as on AIX 5.2/5.3, Solaris 9/10,
86*16467b97STreehugger Robot/// HPUX 11.xx, OSX (PowerPC and Intel) and Cygwin.
87*16467b97STreehugger Robot///
88*16467b97STreehugger Robot/// \b Notes
89*16467b97STreehugger Robot///   - The C runtime is constructed such that the library can be integrated as an archive library, or a shared library/DLL.
90*16467b97STreehugger Robot///   - The C language target code generation templates are distributed with the source code for the ANTLR tool itself.
91*16467b97STreehugger Robot///
92*16467b97STreehugger Robot/// \section performance Performance
93*16467b97STreehugger Robot///
94*16467b97STreehugger Robot/// It is C :-). Basic testing of performance against the Java runtime,
95*16467b97STreehugger Robot/// using the JDK1.6 java source code, and the Java parser provided in the examples (which is a tough test as it includes
96*16467b97STreehugger Robot/// backtracking and memoization) show that the C runtime uses about half the memory and is between 2 and 3 times the speed.
97*16467b97STreehugger Robot/// Tests of non-backtracking, non-memoizing parsers, indicate results significantly better than this.
98*16467b97STreehugger Robot///
99*16467b97STreehugger Robot/// \section examples Downloading Examples
100*16467b97STreehugger Robot///
101*16467b97STreehugger Robot/// The <a href="http://www.antlr.org/download.html">downloads page</a> of the ANTLR web site contains a downloadable
102*16467b97STreehugger Robot/// zip/tar of examples projects for use with the C runtime model. It contains .sln files and source code for a
103*16467b97STreehugger Robot/// number of example grammars and helps to see how to invoke and call the generated recognizers.
104*16467b97STreehugger Robot///