I add the parent post by hand to the start, and then scan, explicitly skipping the parent post which would otherwise match because of the javascript code for quoting. This has the effect of putting forward references after the parent post. I am not sure if this is the better behaviour or not.
The generalization to support replies-to-replies is easy to see: Make in_range() accept an array of post numbers to match against the range, and feed back the @posts array to it. This wouldn't catch forward references to replies, but maybe we can live without those.
If you don't want to catch forward references at all, start the scan from $num+1 instead of 1.