<div dir="ltr"><br><br><div class="gmail_quote">On Thu, Aug 28, 2008 at 4:38 PM, Jim Idle <span dir="ltr">&lt;<a href="mailto:jimi@temporal-wave.com">jimi@temporal-wave.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">



  
  

<div><div class="Ih2E3d">
On Thu, 2008-08-28 at 16:33 -0700, Jim Idle wrote:<blockquote type="CITE">
    When you want to do this in one rule, just use get it directly starting from the current index. Say you want to look back from a particular token in a rule to see if there was a comment on channel 2 (please note that I have not compiled this, just typed it in from memory). Basically though you can do anything you can do in Java (more in fact), just by looking a ta Java example and realizing that the C methods are all the same names (just about) but instead of&nbsp; x.y(z), you use x-&gt;y(x, z).<br>

    <br>
    <tt>rule</tt><br>
    <tt>: f=FUNCTION x y z</tt><br>
    <tt>&nbsp;&nbsp;&nbsp; {</tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int sIndex;</tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pANTLR3_COMMON_TOKEN tok;</tt><br>
    <br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sIndex = $f-&gt;getTokenIndex($f) - 1;&nbsp;&nbsp; // Index for first token</tt><br>
    <tt>&nbsp; </tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Now look back up looking for tokens</tt><br>
    <tt>&nbsp;&nbsp;&nbsp;&nbsp; tok = INPUT-&gt;get(INPUT, sIndex);</tt><br>
</blockquote>
<br></div>
Actually, this should be:<br>
<br>
<pre>tok = <tt>(pANTLR3_COMMON_TOKEN)(</tt>INPUT-&gt;get(INPUT, sIndex)<tt>-&gt;super)</tt>;

Jim
</pre>
</div>

</blockquote></div><br><div>Are you sure? &quot;super&quot; is not a member of ANTLR3_COMMON_TOKEN_struct. Which object are you &quot;super&quot;ing here, the Token or the TokenStream?</div><div><br></div><div>The code for &quot;get()&quot; in antlr3tokenstream.c takes the result of the INPUT macro, follows the super pointer to reach a pANTLR3_COMMON_TOKEN_STREAM, then directly accesses the pANTLR3_VECTOR &quot;tokens&quot; to get the next symbol. What are you suggesting that is different from that?</div>
<div><br></div><div>Mixing these macros with structure fields is making my head spin.</div><div><br></div><div>- Robin Green</div><div>&nbsp;&nbsp;Google, Inc.</div></div>