LLK

Implementation Notes

Implementation notes

There are some implementation details that worth mentioning. Some of which may only be interesting to those who care about the internals of the code.
  • Input source buffer.
  • Default ILLKLexerInput implementation maintain the complete input source in a character buffer. Tokens may either obtain the source text from the input buffer or maintain its own representation of the source string (see LexerTokenUseText option).
  • An implementation of ILLKLexerInput that use streaming input (LLKLexerStreamInput) is also provided.
  • Tracking verified depth.
  • LLK track the lookahead depth that has been verified and avoid redundant compares.
  • Switch/case block for LL(k) where k>1.
  • LLK generate parallel switch/case block instead of serial if/else for alternatives that are deterministic at lookahead depth > 1 by applying the switch generation algorithm recursively.
  • Error location locator.
  • See the error locator document for details.
  • Formatted and readable code output.
  • LLK create a primitive code DOM and allow code to be emitted non-linearly. Example, code generator can add variables to a method anytime during the code gneration phase and have the variable declared at start of the method scope and check for duplicated declarations. It provide flexibility for the code generator to perform checking or optimization operations on the output before the code is emitted. It also allow formatting of the output code to be more readable.