Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > f6ec3de51c94922f2240c0767594dcf5 > files > 3192

antlr3-C-docs-3.2-14.fc15.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>ANTLR3C: Interacting with the Generated Code</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.3 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">ANTLR3C&#160;<span id="projectnumber">3.1.2</span></div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('interop.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<h1>Interacting with the Generated Code </h1>  </div>
</div>
<div class="contents">
<div class="textblock"><h2><a class="anchor" id="intro"></a>
Introduction</h2>
<p>The main way to interact with the generated code is via action code placed within <code>{</code> and <code>}</code> characters in your rules. In general, you are advised to keep the code you embed within these actions, and the grammar itself to an absolute minimum. Rather than embed code directly in your grammar, you should construct an API, that is called from the actions within your grammar. This way you will keep the grammar clean and maintainable and separate the code generators or other code from the definition of the grammar itself.</p>
<p>However, when you wish to call your API functions, or insert small pieces of code that do not warrant external functions, you will need to access elements of tokens, return elements from parser rules and perhaps the internals of the recognizer itself. The C runtime provides a number of MACROs that you can use within your action code. It also provides a number of performant structures that you may find useful for building symbol tables, lists, tries, stacks, arrays and so on (all of which are managed so that your memory allocation problems are minimized.)</p>
<h2><a class="anchor" id="rules"></a>
Parameters and Returns from Parser Rules</h2>
<p>The C target does not differ from the Java target in any major ways here, and you should consult the standard documentation for the use of parameters on rules and the returns clause. You should be aware though, that the rules generate C function calls and therefore the input and returns clauses are subject to the constraints of C scoping.</p>
<p>You should note that if your parser rule returns more than a single entity, then the return type of the generated rule function is a struct, which is returned by value. This is also the case if your rule is part of a tree building grammar (uses the <code>output=AST;</code> option.</p>
<p>Other than the notes above, you can use any pre-declared type as an input or output parameter for your rule.</p>
<h2><a class="anchor" id="memory"></a>
Memory Management</h2>
<p>You are responsible for allocating and freeing any memory used by your own constructs, ANTLR will track and release any memory allocated internally for tokens, trees, stacks, scopes and so on. This memory is returned to the malloc pool when you call the free method of any ANTLR3 produced structure.</p>
<p>For performance reasons, and to avoid thrashing the malloc allocation system, memory for amy elements of your generated parser is allocated in chunks and parcelled out by factories. For instance memory for tokens is created as an array of tokens, and a token factory hands out the next available slot to the lexer. When you free the lexer, the allocated memory is returned to the pool. The same applies to 'strings' that contain the token text and various other text elements accessed within the lexer.</p>
<p>The only side effect of this is that after your parse and analysis is complete, if you wish to retain anything generated automatically, you must copy it before freeing the recognizer structures. In practice it is usually practical to retain the recognizer context objects until your processing is complete or to use your own allocation scheme for generating output etc.</p>
<p>The advantage of using object factories is of course that memory leaks and accessing de-allocated memory are bugs that rarely occur within the ANTLR3 C runtime. Further, allocating memory for tokens, trees and so on is very fast.</p>
<h2><a class="anchor" id="ctx"></a>
The CTX Macro</h2>
<p>The CTX macro is a fundamental parameter that is passed as the first parameter to any generated function concerned with your lexer, parser, or tree parser. The is is the context pointer for your generated recognizer and is how you invoke the generated functions, and access the data embedded within your generated recognizer. While you can use it to directly access stacks, scopes and so on, this is not really recommended as you should use the $xxx references that are available generically within ANTLR grammars.</p>
<p>The context pointer is used because this removes the need for any global/static variables at all, either within the generated code, or the C runtime. This is of course fundamental to creating free threading recognizers. Wherever a function call or rule call required the ctx parameter, you either reference it via the CTX macro, or the ctx parameter is in fact the return type from calling the 'constructor' function for your parser/lexer/tree parser (see code example in "How to build Generated Code" .)</p>
<h2><a class="anchor" id="macros"></a>
Macro Changes</h2>
<p>While the author is not fond of using C MACROs to hide code or structure access, in the case of generated code, they serve two useful purposes. The first is to simplify the references to internal constructs, the second is to facilitate the change of any internal interface without requiring you to port grammars from earlier versions (just regenerate and recompile). As of release 3.1, these macros are stable and will only change their usage interface in the event of bugs being discovered. You are encouraged to use these macros in your code, rather than access the raw interface.</p>
<p>: Macros that act like statements must be terminated with a ';'. The macro body does not supply this, nor should it. Macros that call functions are declared with () even if they have no parameters, macros that reference fields do not have a () declaration.</p>
<h2><a class="anchor" id="lexermacros"></a>
Lexer Macros</h2>
<p>There are a number of macros that are useful exclusively within lexer rules. There are additional macros, common to all recognizer, and these are documented in the section Common Macros.</p>
<h3><a class="anchor" id="lexer"></a>
LEXER</h3>
<p>The <code>LEXER</code> macro returns a pointer to the base lexer object, which is of type <a class="el" href="group___a_n_t_l_r3___l_e_x_e_r.html#gaa9c680e9ec87505c5f2f4af1d8cbb2e2" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_LEXER.">pANTLR3_LEXER</a>. This is not the pointer to your generated lexer, which is supplied by the CTX macro, but to the common implementation of a lexer interface, which is supplied to all generated lexers.</p>
<h3><a class="anchor" id="lexstate"></a>
LEXSTATE</h3>
<p>Provides a pointer to the lexer shared state structure, which is where the tokens for a rule are constructed and the status elements of the lexer are kept. This pointer is of type #pANTLR3_RECOGNIZER_SHARED_STATE.In general you should only access elements of this structure if there is not already another MACRO or standard $xxxx antlr reference that refers to it.</p>
<h3><a class="anchor" id="la"></a>
LA(n)</h3>
<p>The <code>LA</code> macro returns the character at index n from the current input stream index. The return type is <a class="el" href="antlr3defs_8h.html#ac41f744abd0fd25144b9eb9d11b1dfd1">ANTLR3_UINT32</a>. Hence <code>LA(1)</code> returns the character at the current input position (the character that will be consumed next), <code>LA(-1)</code> returns the character that has just been consumed and so on. The <code>LA(n)</code> macro is useful for constructing semantic predicates in lexer rules. The reference <code>LA(0)</code> is undefined and will cause an error in your lexer.</p>
<h3><a class="anchor" id="getcharindex"></a>
GETCHARINDEX()</h3>
<p>The <code>GETCHARINDEX</code> macro returns the index of the current character position as a 0 based offset from the start of the input stream. It returns a value type of <a class="el" href="antlr3defs_8h.html#ac41f744abd0fd25144b9eb9d11b1dfd1">ANTLR3_UINT32</a>.</p>
<h3><a class="anchor" id="getline"></a>
GETLINE()</h3>
<p>The <code>GETLINE</code> macro returns the line number of current character (<code>LA(1)</code> in the input stream. It returns a value type of <a class="el" href="antlr3defs_8h.html#ac41f744abd0fd25144b9eb9d11b1dfd1">ANTLR3_UINT32</a>. Note that the line number is incremented automatically by an input stream when it sees the input character '<br/>
'. The character that causes the line number to increment can be changed by calling the SetNewLineChar() method on the input stream before invoking the lexer and after creating the input stream.</p>
<h3><a class="anchor" id="gettext"></a>
GETTEXT()</h3>
<p>The <code>GETTEXT</code> macro returns the text currently matched by the lexer rule. In general you should use the generic $text reference in ANTLR to retrieve this. The return type is a reference type of <a class="el" href="group___a_n_t_l_r3___s_t_r_i_n_g.html#ga36bbe7362079348864db4b4dbdcce56b" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_STRING.">pANTLR3_STRING</a> which allows you to manipulate the text you have retrieved (<b>NB</b> this does not change the input stream only the text you copy from the input stream when you use this MACRO or $text).</p>
<p>The reference $text-&gt;chars or GETTEXT()-&gt;chars will reference a pointer to the '\0' terminated character string that the ANTLR3 <a class="el" href="group___a_n_t_l_r3___s_t_r_i_n_g.html#ga36bbe7362079348864db4b4dbdcce56b" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_STRING.">pANTLR3_STRING</a> represents. String space is allocated automatically as well as the structure that holds the string. The <a class="el" href="group___a_n_t_l_r3___s_t_r_i_n_g___f_a_c_t_o_r_y.html#ga499a87287d582de04cf736f342b20692" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_STRING_FACTORY.">pANTLR3_STRING_FACTORY</a> associated with the lexer handles this and when you close the lexer, it will automatically free any space allocated for strings and their structures.</p>
<h3><a class="anchor" id="getcharpositioninline"></a>
GETCHARPOSITIONINLINE()</h3>
<p>The <code>GETCHARPOSITIONINLINE</code> returns the zero based offset of character <code>LA(1)</code> from the start of the current input line. See the macro <code>GETLINE</code> for details on what the line number means.</p>
<h3><a class="anchor" id="emit"></a>
EMIT()</h3>
<p>The macro <code>EMIT</code> causes the text range currently matched to the lexer rule to be emitted immediately as the token for the rule. Subsequent text is matched but ignored. The type used for the the token is the name of the lexer rule or, if you have change this by using $type = XXX;, the type XXX is used.</p>
<h3><a class="anchor" id="emitnew"></a>
EMITNEW(t)</h3>
<p>The macro <code>EMITNEW</code> causes the supplied token reference <code>t</code> to be used as the token emitted by the rule. The parameter <code>t </code> must be of type <a class="el" href="group___a_n_t_l_r3___c_o_m_m_o_n___t_o_k_e_n.html#gadaa6df9cbf0cd7ab37fd545520ff299b" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_COMMON_TOKEN.">pANTLR3_COMMON_TOKEN</a>.</p>
<h3><a class="anchor" id="index"></a>
INDEX()</h3>
<p>The <code>INDEX</code> macro returns the current input position according to the input stream. It is not guaranteed to be the character offset in the input stream but is instead used as a value for marking and rewinding to specific points in the input stream. Use the macro <code>GETCHARINDEX()</code> to find out the position of the <code>LA(1)</code> in the input stream.</p>
<h3><a class="anchor" id="pushstream"></a>
PUSHSTREAM(str)</h3>
<p>The <code>PUSHSTREAM</code> macro, in conjunction with the <code>POPSTREAM</code> macro (called internally in the runtime usually) can be used to stack many input streams to the lexer, and implement constructs such as the C pre-processor #include directive.</p>
<p>An input stream that is pushed on to the stack becomes the current input stream for the lexer and the state of the previous stream is automatically saved. The input stream will be automatically popped from the stack when it is exhausted by the lexer. You may use the macro <code>POPSTREAM</code> to return to the previous input stream prior to exhausting the currently stacked input stream.</p>
<p>Here is an example of using the macro in a lexer to implement the C #include pre-processor directive:</p>
<div class="fragment"><pre class="fragment"> fragment
 STRING_GUTS :  (~(<span class="charliteral">&#39;\\&#39;</span>|<span class="charliteral">&#39;&quot;&#39;</span>) )* ;

 LINE_COMMAND 
 : <span class="charliteral">&#39;#&#39;</span> (<span class="charliteral">&#39; &#39;</span> | <span class="charliteral">&#39;\t&#39;</span>)*
    (
        <span class="stringliteral">&#39;include&#39;</span> (<span class="charliteral">&#39; &#39;</span> | <span class="charliteral">&#39;\t&#39;</span>)+ <span class="charliteral">&#39;&quot;&#39;</span> file = STRING_GUTS <span class="charliteral">&#39;&quot;&#39;</span> (<span class="charliteral">&#39; &#39;</span> | <span class="charliteral">&#39;\t&#39;</span>)* <span class="charliteral">&#39;\r&#39;</span>? <span class="charliteral">&#39;\n&#39;</span>
        {
            <a class="code" href="struct_a_n_t_l_r3___s_t_r_i_n_g__struct.html" title="Base string class tracks the allocations and provides simple string tracking functions.">pANTLR3_STRING</a>      fName;
            <a class="code" href="struct_a_n_t_l_r3___i_n_p_u_t___s_t_r_e_a_m__struct.html" title="Master context structure for an ANTLR3 C runtime based input stream.">pANTLR3_INPUT_STREAM</a>    in;
 
            <span class="comment">// Create an initial string, then take a substring</span>
            <span class="comment">// We can do this by messing with the start and end</span>
            <span class="comment">// pointers of tokens and so on. This shows a reasonable way to</span>
            <span class="comment">// manipulate strings.</span>
            <span class="comment">//</span>
            fName = $file.text;
            printf(<span class="stringliteral">&quot;Including file &#39;\%s&#39;\n&quot;</span>, fName-&gt;<a class="code" href="struct_a_n_t_l_r3___s_t_r_i_n_g__struct.html#a7be84d1554437ab99377ab3c623ebd24" title="Pointer to the current string value (starts at NULL unless the string allocator is told to create it ...">chars</a>);
 
            <span class="comment">// Create a new input stream and take advantage of built in stream stacking</span>
            <span class="comment">// in C target runtime.</span>
            <span class="comment">//</span>
            in = <a class="code" href="antlr3filestream_8c.html#a449abcf6642288f35bacc3aae39c0ff6" title="Use the contents of an operating system file as the input for an input stream.">antlr3AsciiFileStreamNew</a>(fName-&gt;<a class="code" href="struct_a_n_t_l_r3___s_t_r_i_n_g__struct.html#a7be84d1554437ab99377ab3c623ebd24" title="Pointer to the current string value (starts at NULL unless the string allocator is told to create it ...">chars</a>);
            PUSHSTREAM(in);
 
            <span class="comment">// Note that the input stream is not closed when it EOFs, I don&#39;t bother</span>
            <span class="comment">// to do it here, but it is up to you to track streams created like this</span>
            <span class="comment">// and destroy them when the whole parse session is complete. Remember that you</span>
            <span class="comment">// don&#39;t want to do this until all tokens have been manipulated all the way through </span>
            <span class="comment">// your tree parsers etc as the token does not store the text it just refers</span>
            <span class="comment">// back to the input stream and trying to get the text for it will abort if you</span>
            <span class="comment">// close the input stream too early.</span>
            <span class="comment">//</span>
 
        }
             | ((<span class="charliteral">&#39;0&#39;</span>..<span class="charliteral">&#39;9&#39;</span>)=&gt;(<span class="charliteral">&#39;0&#39;</span>..<span class="charliteral">&#39;9&#39;</span>))+ ~(<span class="charliteral">&#39;\n&#39;</span>|<span class="charliteral">&#39;\r&#39;</span>)* <span class="charliteral">&#39;\r&#39;</span>? <span class="charliteral">&#39;\n&#39;</span>
        )
     {$channel=<a class="code" href="antlr3commontoken_8h.html#ab42ef41116f8f2fe447484e2844cf0df" title="Reserved channel number for a HIDDEN token - a token that is hidden from the parser.">HIDDEN</a>;}
     ;
</pre></div><h3><a class="anchor" id="popstream"></a>
POPSTREAM()</h3>
<p>Assuming that you have stacked an input stream using the PUSHSTREAM macro, you can remove it from the stream stack and revert to the previous input stream. You should be careful to pop the stream at an appropriate point in your lexer action, so you do not match characters from one stream with those from another in the same rule (unless this is what you want to do)</p>
<h3><a class="anchor" id="settext"></a>
SETTEXT(str)</h3>
<p>A token manufactured by the lexer does not actually physically store the text from the input stream to which it matches. The token string is instead created only if you ask for the text. However if you wish to change the text that the token represents you can use this macro to set it explicitly. Note that this does not change the input stream text but associates the supplied <a class="el" href="group___a_n_t_l_r3___s_t_r_i_n_g.html#ga36bbe7362079348864db4b4dbdcce56b" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_STRING.">pANTLR3_STRING</a> with the token. This string is then returned when parser and tree parser reference the tokens via the $xxx.text reference.</p>
<h3><a class="anchor" id="user1"></a>
USER1 USER2 USER3 and CUSTOM</h3>
<p>While you can create your own custom token class and have the lexer deal with this, this is a lot of work compared to the trivial inheritance that can be achieved in the Java target. In many cases though, all that is needed is the addition of a few data items such as an integer or a pointer. Rather than require C programmers to create complicated structures just to add a few data items, the C target provides a few custom fields in the standard token, which will fulfil the needs of most lexers and parsers.</p>
<p>The token fields user1, user2, and user3 are all value types of #ANTLR_UINT32. In the parser you can reference these fields directly from the token: <code>x=TOKNAME { $x-&gt;user1 ...</code> but when you are building the token in the lexer, you must assign to the fields using the macros <code>USER1</code>, <code>USER2</code>, or <code>USER3</code>. As in:</p>
<div class="fragment"><pre class="fragment"> LEXTOK: <span class="stringliteral">&#39;AAAAA&#39;</span> { USER1 = 99; } ;
</pre></div><h2><a class="anchor" id="parsermacros"></a>
Parser and Tree Parser Macros</h2>
<h3><a class="anchor" id="parser"></a>
PARSER</h3>
<p>The <code>PARSER</code> macro returns a pointer to the base parser or tree parser object, which is of type <a class="el" href="group___a_n_t_l_r3___p_a_r_s_e_r.html#gaa68a53fd6b2d899a8136c64e08fc1dbd" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_PARSER.">pANTLR3_PARSER</a> or <a class="el" href="group___a_n_t_l_r3___t_r_e_e___p_a_r_s_e_r.html#ga9e1fb23071290f1b9c93db4809dbd8d5" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_TREE_PARSER.">pANTLR3_TREE_PARSER</a> . This is not the pointer to your generated parser, which is supplied by the <code>CTX</code> macro, but to the common implementation of a parser or tree parser interface, which is supplied to all generated parsers.</p>
<h3><a class="anchor" id="index"></a>
INDEX()</h3>
<p>When used in the parser, the <code>INDEX</code> macro returns the position of the current token ( LT(1) ) in the input token stream. It can be used for <code>MARK</code> and <code>REWIND</code> operations.</p>
<h3><a class="anchor" id="lt"></a>
LT(n) and LA(n)</h3>
<p>In the parser, the macro <code>LT(n)</code> returns the <a class="el" href="group___a_n_t_l_r3___c_o_m_m_o_n___t_o_k_e_n.html#gadaa6df9cbf0cd7ab37fd545520ff299b" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_COMMON_TOKEN.">pANTLR3_COMMON_TOKEN</a> at offset <code>n</code> from the current token stream input position. The macro <code>LA(n)</code> returns the token type of the token at position <code>n</code>. The value <code>n</code> cannot be zero, and such a reference will return <code>NULL</code> and possibly cause an error. <code>LA(1)</code> is the token that is about to be recognized and <code>LA(-1)</code> is the token that has just been recognized. Values of n that exceed the limits of the token stream boundaries will return <code>NULL</code>.</p>
<h3><a class="anchor" id="psrstate"></a>
PSRSTATE</h3>
<p>Returns the shared state pointer of type <a class="el" href="group___a_n_t_l_r3___r_e_c_o_g_n_i_z_e_r___s_h_a_r_e_d___s_t_a_t_e.html#ga180526531b2c6da5cafe825ae7596bf1" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_RECOGNIZER_SHARED_STATE.">pANTLR3_RECOGNIZER_SHARED_STATE</a>. This is not generally useful to the grammar programmer as the useful elements have generic $xxx references built in to ANTLR.</p>
<h3><a class="anchor" id="adaptor"></a>
ADAPTOR</h3>
<p>When building an AST via a parser, the work of constructing and manipulating trees is done by a supplied adaptor class. The default class is usually fine for most tree operations but if you wish to build your own specialized linked/tree structure, then you may need to reference the adaptor you supply directly. The <code>ADAPTOR</code> macro returns the reference to the tree adaptor which is always of type <a class="el" href="group___a_n_t_l_r3___b_a_s_e___t_r_e_e___a_d_a_p_t_o_r.html#gaa6367527a5a2567bdc31c7066fc7000a" title="Pointer to an instantiation of &#39;class&#39; #ANTLR3_BASE_TREE_ADAPTOR.">pANTLR3_BASE_TREE_ADAPTOR</a>, even if it is your custom adapter.</p>
<h2><a class="anchor" id="commonmacros"></a>
Macros Common to All Recognizers</h2>
<h3><a class="anchor" id="recognizer"></a>
RECOGNIZER</h3>
<p>Returns a reference type of #pANTRL3_BASE_RECOGNIZER, which is the base functionality supplied to all recognizers, whether lexers, parsers or tree parsers. You can override methods in this interface by installing your own function pointers (once you know what you are doing).</p>
<h3><a class="anchor" id="input"></a>
INPUT</h3>
<p>Returns a reference to the input stream of the appropriate type for the recognizer. In a lexer this macro returns a reference type of <a class="el" href="group___a_n_t_l_r3___i_n_p_u_t___s_t_r_e_a_m.html#ga30a8f71f3e04066360723d538fd67f16" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_INPUT_STREAM.">pANTLR3_INPUT_STREAM</a>, in a parser this is type <a class="el" href="group___a_n_t_l_r3___t_o_k_e_n___s_t_r_e_a_m.html#ga9daa2d452cf7fb0c1f4b5e153266070c" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_TOKEN_STREAM.">pANTLR3_TOKEN_STREAM</a> and in a tree parser this is type <a class="el" href="group___a_n_t_l_r3___c_o_m_m_o_n___t_r_e_e___n_o_d_e___s_t_r_e_a_m.html#gad34592f16adc9c3df7eda33f9e35cd87" title="Pointer to an instantiation of &#39;class&#39; ANTLR3_COMMON_TREE_NODE_STREAM.">pANTLR3_COMMON_TREE_NODE_STREAM</a>. You can of course provide your own implementations of any of these interfaces.</p>
<h3><a class="anchor" id="mark"></a>
MARK()</h3>
<p>This macro will cause the input stream for the current recognizer to be marked with a checkpoint. It will return a value type of <a class="el" href="antlr3defs_8h.html#a0361e6bf442e07afe923e4d05e9ebc4f">ANTLR3_MARKER</a> which you can use as the parameter to a <code>REWIND</code> macro to return to the marked point in the input.</p>
<p>If you know you will only ever rewind to the last <code>MARK</code>, then you can ignore the return value of this macro and just use the <code>REWINDLAST</code> macro to return to the last <code>MARK</code> that was set in the input stream.</p>
<h3><a class="anchor" id="rewind"></a>
REWIND(m)</h3>
<p>Rewinds the appropriate input stream back to the marked checkpoint returned from a prior MARK macro call and supplied as the parameter <code>m</code> to the <code>REWIND(m)</code> macro.</p>
<h3><a class="anchor" id="rewindlast"></a>
REWINDLAST()</h3>
<p>Rewinds the current input stream (character, tokens, tree nodes) back to the last checkpoint marker created by a <code>MARK</code> macro call. Fails silently if there was no prior <code>MARK</code> call.</p>
<h3><a class="anchor" id="seek"></a>
SEEK(n)</h3>
<p>Causes the input stream to position itself directly at offset <code>n</code> in the stream. Works for all input stream types, both lexer, parser and tree parser. </p>
</div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="main.html">ANTLR3 C Runtime API and Usage Guide.</a>      </li>
      <li class="navelem"><a class="el" href="using.html">Using the ANTLR3 C Target</a>      </li>
      <li class="footer">Generated on Tue Feb 8 2011 for ANTLR3C by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li>
    </ul>
  </div>

</body>
</html>