note
moritz
<blockquote>Small problem: 3 + 4 6 5 7 is considered valid by your parser. You need to check to make sure all tokens were absorbed or return an EOF token and check if that's the next token. The latter method would remove the need for "no warnings 'uninitialized';".</blockquote>
<p>Very good catch, thank you. I'll update the tutorial accordingly.
<blockquote>I think you could improve performance by generating a single regexp from <c>@token_def</c> <c>(/\G(?>$ws)(?>$tok1(?{...}|$tok2(?{...}|...)/g).</c>
</blockquote>
<p>Since <c>(?{...})</c> is marked as experimental even in perl 5.10.0 and I (re)discovered some bugs in it, I won't use it, at least not in a tutorial at this level. Thanks for the suggestion anyway, it made me think about 5.10's named captures that could be used instead.
<blockquote>
Also, it would be better if the lexer was an iterator instead of doing all the lexing up front. That would decrease the memory footprint.
</blockquote>
<p>Indeed. I decided against it because it slightly increases complexity (or at least makes it harder to understand), but I should at least mention it.
<p>I guess I'll find some time tomorrow to incorporate your suggestions.
690624
690816