5 Parser Optimizations

5.1 Switch Optimization

The switch optimization is enabled by running the spg command with the --optimize option.

In a switch-optimized parser a group of choice parsing expressions is implemented as a switch statement whose condition is current input token and cases are token ids included in the FIRST sets of the choice parsers. The precondition of applying this optimization is that the FIRST sets are distinct.