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