xref: /aosp_15_r20/external/antlr/runtime/C/doxygen/interop.dox (revision 16467b971bd3e2009fad32dd79016f2c7e421deb)
1*16467b97STreehugger Robot/// \page interop Interacting with the Generated Code
2*16467b97STreehugger Robot///
3*16467b97STreehugger Robot/// \section intro Introduction
4*16467b97STreehugger Robot///
5*16467b97STreehugger Robot/// The main way to interact with the generated code is via action code placed within <code>{</code> and
6*16467b97STreehugger Robot/// <code>}</code> characters in your rules. In general, you are advised to keep the code you embed within
7*16467b97STreehugger Robot/// these actions, and the grammar itself to an absolute minimum. Rather than embed code directly in your
8*16467b97STreehugger Robot/// grammar, you should construct an API, that is called from the actions within your grammar. This way
9*16467b97STreehugger Robot/// you will keep the grammar clean and maintainable and separate the code generators or other code
10*16467b97STreehugger Robot/// from the definition of the grammar itself.
11*16467b97STreehugger Robot///
12*16467b97STreehugger Robot/// However, when you wish to call your API functions, or insert small pieces of code that do not
13*16467b97STreehugger Robot/// warrant external functions, you will need to access elements of tokens, return elements from
14*16467b97STreehugger Robot/// parser rules and perhaps the internals of the recognizer itself. The C runtime provides a number
15*16467b97STreehugger Robot/// of MACROs that you can use within your action code. It also provides a number of performant
16*16467b97STreehugger Robot/// structures that you may find useful for building symbol tables, lists, tries, stacks, arrays and so on (all
17*16467b97STreehugger Robot/// of which are managed so that your memory allocation problems are minimized.)
18*16467b97STreehugger Robot///
19*16467b97STreehugger Robot/// \section rules Parameters and Returns from Parser Rules
20*16467b97STreehugger Robot///
21*16467b97STreehugger Robot/// The C target does not differ from the Java target in any major ways here, and you should consult
22*16467b97STreehugger Robot/// the standard documentation for the use of parameters on rules and the returns clause. You should
23*16467b97STreehugger Robot/// be aware though, that the rules generate C function calls and therefore the input and returns
24*16467b97STreehugger Robot/// clauses are subject to the constraints of C scoping.
25*16467b97STreehugger Robot///
26*16467b97STreehugger Robot/// You should note that if your parser rule returns more than a single entity, then the return
27*16467b97STreehugger Robot/// type of the generated rule function is a struct, which is returned by value. This is also the case
28*16467b97STreehugger Robot/// if your rule is part of a tree building grammar (uses the <code>output=AST;</code> option.
29*16467b97STreehugger Robot///
30*16467b97STreehugger Robot/// Other than the notes above, you can use any pre-declared type as an input or output parameter
31*16467b97STreehugger Robot/// for your rule.
32*16467b97STreehugger Robot///
33*16467b97STreehugger Robot/// \section memory Memory Management
34*16467b97STreehugger Robot///
35*16467b97STreehugger Robot/// You are responsible for allocating and freeing any memory used by your own
36*16467b97STreehugger Robot/// constructs, ANTLR will track and release any memory allocated internally for tokens, trees, stacks, scopes
37*16467b97STreehugger Robot/// and so on. This memory is returned to the malloc pool when you call the free method of any
38*16467b97STreehugger Robot/// ANTLR3 produced structure.
39*16467b97STreehugger Robot///
40*16467b97STreehugger Robot/// For performance reasons, and to avoid thrashing the malloc allocation system, memory for amy elements
41*16467b97STreehugger Robot/// of your generated parser is allocated in chunks and parcelled out by factories. For instance memory
42*16467b97STreehugger Robot/// for tokens is created as an array of tokens, and a token factory hands out the next available slot
43*16467b97STreehugger Robot/// to the lexer. When you free the lexer, the allocated memory is returned to the pool. The same applies
44*16467b97STreehugger Robot/// to 'strings' that contain the token text and various other text elements accessed within the lexer.
45*16467b97STreehugger Robot///
46*16467b97STreehugger Robot/// The only side effect of this is that after your parse and analysis is complete, if you wish to retain
47*16467b97STreehugger Robot/// anything generated automatically, you must copy it before freeing the recognizer structures. In practice
48*16467b97STreehugger Robot/// it is usually practical to retain the recognizer context objects until your processing is complete or
49*16467b97STreehugger Robot/// to use your own allocation scheme for generating output etc.
50*16467b97STreehugger Robot///
51*16467b97STreehugger Robot/// The advantage of using object factories is of course that memory leaks and accessing de-allocated
52*16467b97STreehugger Robot/// memory are bugs that rarely occur within the ANTLR3 C runtime. Further, allocating memory for
53*16467b97STreehugger Robot/// tokens, trees and so on is very fast.
54*16467b97STreehugger Robot///
55*16467b97STreehugger Robot/// \section ctx The CTX Macro
56*16467b97STreehugger Robot///
57*16467b97STreehugger Robot/// The CTX macro is a fundamental parameter that is passed as the first parameter to any generated function
58*16467b97STreehugger Robot/// concerned with your lexer, parser, or tree parser. The is is the context pointer for your generated
59*16467b97STreehugger Robot/// recognizer and is how you invoke the generated functions, and access the data embedded within your generated
60*16467b97STreehugger Robot/// recognizer. While you can use it to directly access stacks, scopes and so on, this is not really recommended
61*16467b97STreehugger Robot/// as you should use the $xxx references that are available generically within ANTLR grammars.
62*16467b97STreehugger Robot///
63*16467b97STreehugger Robot/// The context pointer is used because this removes the need for any global/static variables at all, either
64*16467b97STreehugger Robot/// within the generated code, or the C runtime. This is of course fundamental to creating free threading
65*16467b97STreehugger Robot/// recognizers. Wherever a function call or rule call required the ctx parameter, you either reference it
66*16467b97STreehugger Robot/// via the CTX macro, or the ctx parameter is in fact the return type from calling the 'constructor'
67*16467b97STreehugger Robot/// function for your parser/lexer/tree parser (see code example in "How to build Generated Code" .)
68*16467b97STreehugger Robot///
69*16467b97STreehugger Robot/// \section macros Pre-Defined convenience MACROs
70*16467b97STreehugger Robot///
71*16467b97STreehugger Robot/// While the author is not fond of using C MACROs to hide code or structure access, in the case of generated
72*16467b97STreehugger Robot/// code, they serve two useful purposes. The first is to simplify the references to internal constructs,
73*16467b97STreehugger Robot/// the second is to facilitate the change of any internal interface without requiring you to port grammars
74*16467b97STreehugger Robot/// from earlier versions (just regenerate and recompile). As of release 3.1, these macros are stable and
75*16467b97STreehugger Robot/// will only change their usage interface in the event of bugs being discovered. You are encouraged to
76*16467b97STreehugger Robot/// use these macros in your code, rather than access the raw interface.
77*16467b97STreehugger Robot///
78*16467b97STreehugger Robot/// \bNB: Macros that act like statements must be terminated with a ';'. The macro body does not
79*16467b97STreehugger Robot/// supply this, nor should it. Macros that call functions are declared with () even if they
80*16467b97STreehugger Robot/// have no parameters, macros that reference fields do not have a () declaration.
81*16467b97STreehugger Robot///
82*16467b97STreehugger Robot/// \section lexermacros Lexer Macros
83*16467b97STreehugger Robot///
84*16467b97STreehugger Robot/// There are a number of macros that are useful exclusively within lexer rules. There are additional
85*16467b97STreehugger Robot/// macros, common to all recognizer, and these are documented in the section Common Macros.
86*16467b97STreehugger Robot///
87*16467b97STreehugger Robot/// \subsection lexer LEXER
88*16467b97STreehugger Robot///
89*16467b97STreehugger Robot/// The <code>LEXER</code> macro returns a pointer to the base lexer object, which is of type #pANTLR3_LEXER. This is
90*16467b97STreehugger Robot/// not the pointer to your generated lexer, which is supplied by the CTX macro,
91*16467b97STreehugger Robot/// but to the common implementation of a lexer interface,
92*16467b97STreehugger Robot/// which is supplied to all generated lexers.
93*16467b97STreehugger Robot///
94*16467b97STreehugger Robot/// \subsection lexstate LEXSTATE
95*16467b97STreehugger Robot///
96*16467b97STreehugger Robot/// Provides a pointer to the lexer shared state structure, which is where the tokens for a
97*16467b97STreehugger Robot/// rule are constructed and the status elements of the lexer are kept. This pointer is of type
98*16467b97STreehugger Robot/// #pANTLR3_RECOGNIZER_SHARED_STATE.In general you should only access elements of this structure
99*16467b97STreehugger Robot/// if there is not already another MACRO or standard $xxxx antlr reference that refers to it.
100*16467b97STreehugger Robot///
101*16467b97STreehugger Robot/// \subsection la LA(n)
102*16467b97STreehugger Robot///
103*16467b97STreehugger Robot/// The <code>LA</code> macro returns the character at index n from the current input stream index. The return
104*16467b97STreehugger Robot/// type is #ANTLR3_UINT32. Hence <code>LA(1)</code> returns the character at the current input position (the
105*16467b97STreehugger Robot/// character that will be consumed next), <code>LA(-1)</code> returns the character that has just been consumed
106*16467b97STreehugger Robot/// and so on. The <code>LA(n)</code> macro is useful for constructing semantic predicates in lexer rules. The
107*16467b97STreehugger Robot/// reference <code>LA(0)</code> is undefined and will cause an error in your lexer.
108*16467b97STreehugger Robot///
109*16467b97STreehugger Robot/// \subsection getcharindex GETCHARINDEX()
110*16467b97STreehugger Robot///
111*16467b97STreehugger Robot/// The <code>GETCHARINDEX</code> macro returns the index of the current character position as a 0 based
112*16467b97STreehugger Robot/// offset from the start of the input stream. It returns a value type of #ANTLR3_UINT32.
113*16467b97STreehugger Robot///
114*16467b97STreehugger Robot/// \subsection getline GETLINE()
115*16467b97STreehugger Robot///
116*16467b97STreehugger Robot/// The <code>GETLINE</code> macro returns the line number of current character (<code>LA(1)</code> in the input
117*16467b97STreehugger Robot/// stream. It returns a value type of #ANTLR3_UINT32. Note that the line number is incremented
118*16467b97STreehugger Robot/// automatically by an input stream when it sees the input character '\n'. The character that causes
119*16467b97STreehugger Robot/// the line number to increment can be changed by calling the SetNewLineChar() method on the input
120*16467b97STreehugger Robot/// stream before invoking the lexer and after creating the input stream.
121*16467b97STreehugger Robot///
122*16467b97STreehugger Robot/// \subsection gettext GETTEXT()
123*16467b97STreehugger Robot///
124*16467b97STreehugger Robot/// The <code>GETTEXT</code> macro returns the text currently matched by the lexer rule. In general you should use the
125*16467b97STreehugger Robot/// generic $text reference in ANTLR to retrieve this. The return type is a reference type of #pANTLR3_STRING
126*16467b97STreehugger Robot/// which allows you to manipulate the text you have retrieved (\b NB this does not change the input stream
127*16467b97STreehugger Robot/// only the text you copy from the input stream when you use this MACRO or $text).
128*16467b97STreehugger Robot///
129*16467b97STreehugger Robot/// The reference $text->chars or GETTEXT()->chars will reference a pointer to the '\\0' terminated character
130*16467b97STreehugger Robot/// string that the ANTLR3 #pANTLR3_STRING represents. String space is allocated automatically as well as
131*16467b97STreehugger Robot/// the structure that holds the string. The #pANTLR3_STRING_FACTORY associated with the lexer handles this
132*16467b97STreehugger Robot/// and when you close the lexer, it will automatically free any space allocated for strings and their structures.
133*16467b97STreehugger Robot///
134*16467b97STreehugger Robot/// \subsection getcharpositioninline GETCHARPOSITIONINLINE()
135*16467b97STreehugger Robot///
136*16467b97STreehugger Robot/// The <code>GETCHARPOSITIONINLINE</code> returns the zero based offset of character <code>LA(1)</code>
137*16467b97STreehugger Robot/// from the start of the current input line. See the macro <code>GETLINE</code> for details on what the
138*16467b97STreehugger Robot/// line number means.
139*16467b97STreehugger Robot///
140*16467b97STreehugger Robot/// \subsection emit EMIT()
141*16467b97STreehugger Robot///
142*16467b97STreehugger Robot/// The macro <code>EMIT</code> causes the text range currently matched to the lexer rule to be emitted
143*16467b97STreehugger Robot/// immediately as the token for the rule. Subsequent text is matched but ignored. The type used for the
144*16467b97STreehugger Robot/// the token is the name of the lexer rule or, if you have change this by using $type = XXX;, the type
145*16467b97STreehugger Robot/// XXX is used.
146*16467b97STreehugger Robot///
147*16467b97STreehugger Robot/// \subsection emitnew EMITNEW(t)
148*16467b97STreehugger Robot///
149*16467b97STreehugger Robot/// The macro <code>EMITNEW</code> causes the supplied token reference <code>t</code> to be used as the
150*16467b97STreehugger Robot/// token emitted by the rule. The parameter <code>t </code> must be of type #pANTLR3_COMMON_TOKEN.
151*16467b97STreehugger Robot///
152*16467b97STreehugger Robot/// \subsection index INDEX()
153*16467b97STreehugger Robot///
154*16467b97STreehugger Robot/// The <code>INDEX</code> macro returns the current input position according to the input stream. It is not
155*16467b97STreehugger Robot/// guaranteed to be the character offset in the input stream but is instead used as a value
156*16467b97STreehugger Robot/// for marking and rewinding to specific points in the input stream. Use the macro <code>GETCHARINDEX()</code>
157*16467b97STreehugger Robot/// to find out the position of the <code>LA(1)</code> in the input stream.
158*16467b97STreehugger Robot///
159*16467b97STreehugger Robot/// \subsection pushstream PUSHSTREAM(str)
160*16467b97STreehugger Robot///
161*16467b97STreehugger Robot/// The <code>PUSHSTREAM</code> macro, in conjunction with the <code>POPSTREAM</code> macro (called internally in the runtime usually)
162*16467b97STreehugger Robot/// can be used to stack many input streams to the lexer, and implement constructs such as the C pre-processor
163*16467b97STreehugger Robot/// \#include directive.
164*16467b97STreehugger Robot///
165*16467b97STreehugger Robot/// An input stream that is pushed on to the stack becomes the current input stream for the lexer and
166*16467b97STreehugger Robot/// the state of the previous stream is automatically saved. The input stream will be automatically
167*16467b97STreehugger Robot/// popped from the stack when it is exhausted by the lexer. You may use the macro <code>POPSTREAM</code>
168*16467b97STreehugger Robot/// to return to the previous input stream prior to exhausting the currently stacked input stream.
169*16467b97STreehugger Robot///
170*16467b97STreehugger Robot/// Here is an example of using the macro in a lexer to implement the C \#include pre-processor directive:
171*16467b97STreehugger Robot///
172*16467b97STreehugger Robot/// \code
173*16467b97STreehugger Robot/// fragment
174*16467b97STreehugger Robot/// STRING_GUTS :	(~('\\'|'"') )* ;
175*16467b97STreehugger Robot///
176*16467b97STreehugger Robot/// LINE_COMMAND
177*16467b97STreehugger Robot/// : '#' (' ' | '\t')*
178*16467b97STreehugger Robot/// 	(
179*16467b97STreehugger Robot/// 	    'include' (' ' | '\t')+ '"' file = STRING_GUTS '"' (' ' | '\t')* '\r'? '\n'
180*16467b97STreehugger Robot/// 		{
181*16467b97STreehugger Robot/// 		    pANTLR3_STRING	    fName;
182*16467b97STreehugger Robot/// 		    pANTLR3_INPUT_STREAM    in;
183*16467b97STreehugger Robot///
184*16467b97STreehugger Robot/// 		    // Create an initial string, then take a substring
185*16467b97STreehugger Robot/// 		    // We can do this by messing with the start and end
186*16467b97STreehugger Robot/// 		    // pointers of tokens and so on. This shows a reasonable way to
187*16467b97STreehugger Robot/// 		    // manipulate strings.
188*16467b97STreehugger Robot/// 		    //
189*16467b97STreehugger Robot/// 		    fName = $file.text;
190*16467b97STreehugger Robot/// 		    printf("Including file '\%s'\n", fName->chars);
191*16467b97STreehugger Robot///
192*16467b97STreehugger Robot/// 		    // Create a new input stream and take advantage of built in stream stacking
193*16467b97STreehugger Robot/// 		    // in C target runtime.
194*16467b97STreehugger Robot/// 		    //
195*16467b97STreehugger Robot/// 		    in = antlr38BitFileStreamNew(fName->chars);
196*16467b97STreehugger Robot/// 		    PUSHSTREAM(in);
197*16467b97STreehugger Robot///
198*16467b97STreehugger Robot/// 		    // Note that the input stream is not closed when it EOFs, I don't bother
199*16467b97STreehugger Robot/// 		    // to do it here, but it is up to you to track streams created like this
200*16467b97STreehugger Robot/// 		    // and destroy them when the whole parse session is complete. Remember that you
201*16467b97STreehugger Robot/// 		    // don't want to do this until all tokens have been manipulated all the way through
202*16467b97STreehugger Robot/// 		    // your tree parsers etc as the token does not store the text it just refers
203*16467b97STreehugger Robot/// 		    // back to the input stream and trying to get the text for it will abort if you
204*16467b97STreehugger Robot/// 		    // close the input stream too early.
205*16467b97STreehugger Robot/// 		    //
206*16467b97STreehugger Robot///
207*16467b97STreehugger Robot/// 		}
208*16467b97STreehugger Robot///             | (('0'..'9')=>('0'..'9'))+ ~('\n'|'\r')* '\r'? '\n'
209*16467b97STreehugger Robot/// 	    )
210*16467b97STreehugger Robot/// 	 {$channel=HIDDEN;}
211*16467b97STreehugger Robot///     ;
212*16467b97STreehugger Robot/// \endcode
213*16467b97STreehugger Robot///
214*16467b97STreehugger Robot/// \subsection popstream POPSTREAM()
215*16467b97STreehugger Robot///
216*16467b97STreehugger Robot/// Assuming that you have stacked an input stream using the PUSHSTREAM macro, you can
217*16467b97STreehugger Robot/// remove it from the stream stack and revert to the previous input stream. You should be careful
218*16467b97STreehugger Robot/// to pop the stream at an appropriate point in your lexer action, so you do not match characters
219*16467b97STreehugger Robot/// from one stream with those from another in the same rule (unless this is what you want to do)
220*16467b97STreehugger Robot///
221*16467b97STreehugger Robot/// \subsection settext SETTEXT(str)
222*16467b97STreehugger Robot///
223*16467b97STreehugger Robot/// A token manufactured by the lexer does not actually physically store the text from the
224*16467b97STreehugger Robot/// input stream to which it matches. The token string is instead created only if you ask for
225*16467b97STreehugger Robot/// the text. However if you wish to change the text that the token represents you can use
226*16467b97STreehugger Robot/// this macro to set it explicitly. Note that this does not change the input stream text
227*16467b97STreehugger Robot/// but associates the supplied #pANTLR3_STRING with the token. This string is then returned
228*16467b97STreehugger Robot/// when parser and tree parser reference the tokens via the $xxx.text reference.
229*16467b97STreehugger Robot///
230*16467b97STreehugger Robot/// \subsection user1 USER1 USER2 USER3 and CUSTOM
231*16467b97STreehugger Robot///
232*16467b97STreehugger Robot/// While you can create your own custom token class and have the lexer deal with this, this
233*16467b97STreehugger Robot/// is a lot of work compared to the trivial inheritance that can be achieved in the Java target.
234*16467b97STreehugger Robot/// In many cases though, all that is needed is the addition of a few data items such as an
235*16467b97STreehugger Robot/// integer or a pointer. Rather than require C programmers to create complicated structures
236*16467b97STreehugger Robot/// just to add a few data items, the C target provides a few custom fields in the standard
237*16467b97STreehugger Robot/// token, which will fulfil the needs of most lexers and parsers.
238*16467b97STreehugger Robot///
239*16467b97STreehugger Robot/// The token fields user1, user2, and user3 are all value types of #ANTLR_UINT32. In the
240*16467b97STreehugger Robot/// parser you can reference these fields directly from the token: <code>x=TOKNAME { $x->user1 ...</code>
241*16467b97STreehugger Robot/// but when you are building the token in the lexer, you must assign to the fields using the
242*16467b97STreehugger Robot/// macros <code>USER1</code>, <code>USER2</code>, or <code>USER3</code>. As in:
243*16467b97STreehugger Robot///
244*16467b97STreehugger Robot/// \code
245*16467b97STreehugger Robot/// LEXTOK: 'AAAAA' { USER1 = 99; } ;
246*16467b97STreehugger Robot/// \endcode
247*16467b97STreehugger Robot///
248*16467b97STreehugger Robot///
249*16467b97STreehugger Robot/// \section parsermacros Parser and Tree Parser Macros
250*16467b97STreehugger Robot///
251*16467b97STreehugger Robot/// \subsection parser PARSER
252*16467b97STreehugger Robot///
253*16467b97STreehugger Robot/// The <code>PARSER</code> macro returns a pointer to the base parser or tree parser object, which is of type #pANTLR3_PARSER
254*16467b97STreehugger Robot/// or #pANTLR3_TREE_PARSER . This is not the pointer to your generated parser, which is supplied by the <code>CTX</code> macro,
255*16467b97STreehugger Robot/// but to the common implementation of a parser or tree parser interface, which is supplied to all generated parsers.
256*16467b97STreehugger Robot///
257*16467b97STreehugger Robot/// \subsection index INDEX()
258*16467b97STreehugger Robot///
259*16467b97STreehugger Robot/// When used in the parser, the <code>INDEX</code> macro returns the position of the current
260*16467b97STreehugger Robot/// token ( LT(1) ) in the input token stream. It can be used for <code>MARK</code> and <code>REWIND</code>
261*16467b97STreehugger Robot/// operations.
262*16467b97STreehugger Robot///
263*16467b97STreehugger Robot/// \subsection lt LT(n) and LA(n)
264*16467b97STreehugger Robot///
265*16467b97STreehugger Robot/// In the parser, the macro <code>LT(n)</code> returns the #pANTLR3_COMMON_TOKEN at offset <code>n</code> from
266*16467b97STreehugger Robot/// the current token stream input position. The macro <code>LA(n)</code> returns the token type of the token
267*16467b97STreehugger Robot/// at position <code>n</code>. The value <code>n</code> cannot be zero, and such a reference will return
268*16467b97STreehugger Robot/// <code>NULL</code> and possibly cause an error. <code>LA(1)</code> is the token that is about to be
269*16467b97STreehugger Robot/// recognized and <code>LA(-1)</code> is the token that has just been recognized. Values of n that exceed the
270*16467b97STreehugger Robot/// limits of the token stream boundaries will return <code>NULL</code>.
271*16467b97STreehugger Robot///
272*16467b97STreehugger Robot/// \subsection psrstate PSRSTATE
273*16467b97STreehugger Robot///
274*16467b97STreehugger Robot/// Returns the shared state pointer of type #pANTLR3_RECOGNIZER_SHARED_STATE. This is not generally
275*16467b97STreehugger Robot/// useful to the grammar programmer as the useful elements have generic $xxx references built in to
276*16467b97STreehugger Robot/// ANTLR.
277*16467b97STreehugger Robot///
278*16467b97STreehugger Robot/// \subsection adaptor ADAPTOR
279*16467b97STreehugger Robot///
280*16467b97STreehugger Robot/// When building an AST via a parser, the work of constructing and manipulating trees is done
281*16467b97STreehugger Robot/// by a supplied adaptor class. The default class is usually fine for most tree operations but
282*16467b97STreehugger Robot/// if you wish to build your own specialized linked/tree structure, then you may need to reference
283*16467b97STreehugger Robot/// the adaptor you supply directly. The <code>ADAPTOR</code> macro returns the reference to the tree adaptor
284*16467b97STreehugger Robot/// which is always of type #pANTLR3_BASE_TREE_ADAPTOR, even if it is your custom adapter.
285*16467b97STreehugger Robot///
286*16467b97STreehugger Robot/// \section commonmacros Macros Common to All Recognizers
287*16467b97STreehugger Robot///
288*16467b97STreehugger Robot/// \subsection recognizer RECOGNIZER
289*16467b97STreehugger Robot///
290*16467b97STreehugger Robot/// Returns a reference type of #pANTRL3_BASE_RECOGNIZER, which is the base functionality supplied
291*16467b97STreehugger Robot/// to all recognizers, whether lexers, parsers or tree parsers. You can override methods in this
292*16467b97STreehugger Robot/// interface by installing your own function pointers (once you know what you are doing).
293*16467b97STreehugger Robot///
294*16467b97STreehugger Robot/// \subsection input INPUT
295*16467b97STreehugger Robot///
296*16467b97STreehugger Robot/// Returns a reference to the input stream of the appropriate type for the recognizer. In a lexer
297*16467b97STreehugger Robot/// this macro returns a reference type of #pANTLR3_INPUT_STREAM, in a parser this is type
298*16467b97STreehugger Robot/// #pANTLR3_TOKEN_STREAM and in a tree parser this is type #pANTLR3_COMMON_TREE_NODE_STREAM.
299*16467b97STreehugger Robot/// You can of course provide your own implementations of any of these interfaces.
300*16467b97STreehugger Robot///
301*16467b97STreehugger Robot/// \subsection mark MARK()
302*16467b97STreehugger Robot///
303*16467b97STreehugger Robot/// This macro will cause the input stream for the current recognizer to be marked with a
304*16467b97STreehugger Robot/// checkpoint. It will return a value type of #ANTLR3_MARKER which you can use as the
305*16467b97STreehugger Robot/// parameter to a <code>REWIND</code> macro to return to the marked point in the input.
306*16467b97STreehugger Robot///
307*16467b97STreehugger Robot/// If you know you will only ever rewind to the last <code>MARK</code>, then you can ignore the return
308*16467b97STreehugger Robot/// value of this macro and just use the <code>REWINDLAST</code> macro to return to the last <code>MARK</code> that
309*16467b97STreehugger Robot/// was set in the input stream.
310*16467b97STreehugger Robot///
311*16467b97STreehugger Robot/// \subsection rewind REWIND(m)
312*16467b97STreehugger Robot///
313*16467b97STreehugger Robot/// Rewinds the appropriate input stream back to the marked checkpoint returned from a prior
314*16467b97STreehugger Robot/// MARK macro call and supplied as the parameter <code>m</code> to the <code>REWIND(m)</code>
315*16467b97STreehugger Robot/// macro.
316*16467b97STreehugger Robot///
317*16467b97STreehugger Robot/// \subsection rewindlast REWINDLAST()
318*16467b97STreehugger Robot///
319*16467b97STreehugger Robot/// Rewinds the current input stream (character, tokens, tree nodes) back to the last checkpoint
320*16467b97STreehugger Robot/// marker created by a <code>MARK</code> macro call. Fails silently if there was no prior
321*16467b97STreehugger Robot/// <code>MARK</code> call.
322*16467b97STreehugger Robot///
323*16467b97STreehugger Robot/// \subsection seek SEEK(n)
324*16467b97STreehugger Robot///
325*16467b97STreehugger Robot/// Causes the input stream to position itself directly at offset <code>n</code> in the stream. Works for all
326*16467b97STreehugger Robot/// input stream types, both lexer, parser and tree parser.
327*16467b97STreehugger Robot///
328