Mirinth / Plexiglass

A lexer generator, in the spirit of GNU Flex.
Other
0 stars 0 forks source link

Check whether a given state is always escapable. #63

Closed Mirinth closed 2 years ago

Mirinth commented 3 years ago

Once states are supported, semantic analysis should check whether any of them are (or can be) dead states.

Mirinth commented 2 years ago

On second thought, this wouldn't work.

If there was only a single state, then there would be no other state to escape to, so any single-state lexer would always be rejected. You'd have to add a useless state just to satisfy the analyzer.

Another example is something that can appear exactly once. You might start out in the not-seen-yet state, then transition to the seen-now state after seeing it. If those were the only two states, you'd have to transition back to the not-seen-yet state to keep the analyzer happy, which would be wrong. You'd need a useless state again.

A third example is if you're lexing multiple versions of a language. You might expect the first thing to be version 1 or version 2, then switch to a sub-lexer depending on which one you see. This rule would force allowing cases where you can switch between language versions in the middle of a file, which could make later processing difficult. You'd want useless states again.

Unless I can find a compelling reason to do so, enforcing states being escapable won't be done.