<div dir="ltr"><br><br><div class="gmail_quote">On Thu, Aug 28, 2008 at 4:38 PM, Jim Idle <span dir="ltr"><<a href="mailto:jimi@temporal-wave.com">jimi@temporal-wave.com</a>></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 x.y(z), you use x->y(x, z).<br>
<br>
<tt>rule</tt><br>
<tt>: f=FUNCTION x y z</tt><br>
<tt> {</tt><br>
<tt> int sIndex;</tt><br>
<tt> pANTLR3_COMMON_TOKEN tok;</tt><br>
<br>
<tt> sIndex = $f->getTokenIndex($f) - 1; // Index for first token</tt><br>
<tt> </tt><br>
<tt> // Now look back up looking for tokens</tt><br>
<tt> tok = INPUT->get(INPUT, sIndex);</tt><br>
</blockquote>
<br></div>
Actually, this should be:<br>
<br>
<pre>tok = <tt>(pANTLR3_COMMON_TOKEN)(</tt>INPUT->get(INPUT, sIndex)<tt>->super)</tt>;
Jim
</pre>
</div>
</blockquote></div><br><div>Are you sure? "super" is not a member of ANTLR3_COMMON_TOKEN_struct. Which object are you "super"ing here, the Token or the TokenStream?</div><div><br></div><div>The code for "get()" 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 "tokens" 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> Google, Inc.</div></div>