1*16467b97STreehugger Robot/// \page using Using the ANTLR3 C Target 2*16467b97STreehugger Robot/// 3*16467b97STreehugger Robot/// \section intro Introduction 4*16467b97STreehugger Robot/// 5*16467b97STreehugger Robot/// Using the ANTLR target involves gaining knowledge of a number of elements: 6*16467b97STreehugger Robot/// 7*16467b97STreehugger Robot/// -# Writing ANTLR grammars (not covered in this manual); 8*16467b97STreehugger Robot/// -# How ANTLR works (not covered in this manual); 9*16467b97STreehugger Robot/// -# How to use the \@sections with the C target 10*16467b97STreehugger Robot/// -# Interoperation with the runtime within rule actions; 11*16467b97STreehugger Robot/// -# Implementing custom versions of the standard library methods; 12*16467b97STreehugger Robot/// 13*16467b97STreehugger Robot/// If you are as yet unfamiliar with how ANTLR works in general, then 14*16467b97STreehugger Robot/// it is suggested that you read the various <a href="http://www.antlr.org/wiki">wiki pages</a> concerned with 15*16467b97STreehugger Robot/// getting started. However there are a few things that you should note: 16*16467b97STreehugger Robot/// 17*16467b97STreehugger Robot/// - The lexer is independent of the parser. You \b cannot control the lexer from within the parser; 18*16467b97STreehugger Robot/// - The tree parser is independent of the parser. You \b cannot control the parser from within the tree parser(s); 19*16467b97STreehugger Robot/// - Each tree parser is independent of other tree parsers. 20*16467b97STreehugger Robot/// 21*16467b97STreehugger Robot/// This means that your lexer runs first and consumes all the input stream until 22*16467b97STreehugger Robot/// you stop it programmatically, or it reaches the end of the input stream. It produces 23*16467b97STreehugger Robot/// a complete stream of tokens, which the parser then consumes. 24*16467b97STreehugger Robot/// 25*16467b97STreehugger Robot/// \section Using \@sections in a C Targeted Grammar 26*16467b97STreehugger Robot/// 27*16467b97STreehugger Robot/// Within a grammar file there are a number of special sections you can add that cause the 28*16467b97STreehugger Robot/// code within them to be placed at strategic points in the generated code such as 29*16467b97STreehugger Robot/// before or after the #include statements in the .c file, within the generated header file 30*16467b97STreehugger Robot/// or within the constructor for the recognizer. 31*16467b97STreehugger Robot/// 32*16467b97STreehugger Robot/// Many of the \@sections used within a Java targeted grammar have some equivalent function within a 33*16467b97STreehugger Robot/// C targeted grammar, but their use may well be subtly different. There are also additional sections 34*16467b97STreehugger Robot/// that have meaning only within a grammar targeted for the C runtime. 35*16467b97STreehugger Robot/// 36*16467b97STreehugger Robot/// Detailed documentation of these sections is given here: \subpage atsections 37*16467b97STreehugger Robot/// 38*16467b97STreehugger Robot/// \section interop Interoperation Within Rule Actions 39*16467b97STreehugger Robot/// 40*16467b97STreehugger Robot/// Rule actions have a limited number of elements they can access by name, independently of the 41*16467b97STreehugger Robot/// target language generated. These are elements such as $line, $pos, $text and so on. Where the 42*16467b97STreehugger Robot/// $xxx returns a basic type such as \c int, then you can use these in C as you would in the Java 43*16467b97STreehugger Robot/// target, but where a reference returns a string, you will get a pointer to the C runtime 44*16467b97STreehugger Robot/// string implementation #pANTLR3_STRING. This will give you access to things like token text 45*16467b97STreehugger Robot/// but also provides some convenience methods such as #pANTLR3_STRING->substring() and #pANTLR3_STRING->toUTF8(). 46*16467b97STreehugger Robot/// 47*16467b97STreehugger Robot/// The generated code provides a number of C MACROs, which make it easier to access runtime 48*16467b97STreehugger Robot/// components. Always use these macros when available, to protect your action code from changes 49*16467b97STreehugger Robot/// to the underlying implementation. 50*16467b97STreehugger Robot/// 51*16467b97STreehugger Robot/// Detailed documentation of macros and rule action interoperation is given here: \subpage interop 52*16467b97STreehugger Robot/// 53*16467b97STreehugger Robot/// \section Custom Implementing Customized Methods 54*16467b97STreehugger Robot/// 55*16467b97STreehugger Robot/// Unless you wish to create your own tree structures using the built in ANTLR AST rewriting 56*16467b97STreehugger Robot/// notation, you will rarely need to override the default implementation of runtime methods. The 57*16467b97STreehugger Robot/// exception to this will be the syntax err reporting method, which is essentially a stub function 58*16467b97STreehugger Robot/// that you will usually want to provide your own implementation for. You should consider the built in function 59*16467b97STreehugger Robot/// displayRecognitionError() as an example of where to start as there can be no really useful 60*16467b97STreehugger Robot/// generic error message display. 61*16467b97STreehugger Robot/// 62*16467b97STreehugger Robot///