Maximizing Parser Speed
ANTLR v4’s adaptive parsing strategy is more powerful than v3’s, but it comes at the cost of a little bit of speed. If you need the most speed and the smallest memory footprint possible, you can do a two-step parsing strategy. The first step uses a slightly weaker parsing strategy, SLL(*), that almost always works. (It’s very similar to v3’s strategy, except it doesn’t need to backtrack.) If the first parsing step fails, you have to try the full LL(*) parse. After failing the first step, we don’t know whether it’s a true syntax error or whether it’s because the SLL(*) strategy wasn’t strong enough. Input that passes the SLL(*) step is guaranteed to pass the full LL(*), so there’s no point in trying out that more expensive ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access