Chevrotain
Home
Features
Tutorial
Guide
FAQ
Changes
APIs
Playground
Benchmark
Discussions
GitHub
Home
Features
Tutorial
Guide
FAQ
Changes
APIs
Playground
Benchmark
Discussions
GitHub
  • Features

    • Blazing Fast
    • LL(K) Grammars
    • Separation of Grammar and Semantics
    • Easy Debugging
    • Fault Tolerance
    • Multiple Start Rules
    • Customizable Error Messages
    • Parameterized Rules
    • Gates
    • Syntactic Content Assist
    • Grammar Inheritance
    • Backtracking
    • Syntax Diagrams
    • RegExp Based Lexers
    • Position Tracking
    • Token Alternative Matches
    • Token Skipping
    • Token Categories
    • Token Grouping
    • Custom Token Patterns
    • Lexer Modes

LL(K) Grammars

Chevrotain can be used to build parsers for LL(K) Grammars. This means that the number of lookahead tokens needed to disambiguate alternatives must be a fixed number and known in advance.

For example, given the grammar

statement:
   A B C |
   A B D |
   A B E

Chevrotain will look three tokens ahead to decide between the two alternatives.

But given the following grammar

statement:
   longRule B  |
   longRule C  |
   longRule D

longRule:
   A+

Chevrotain will throw an error during parser initialization in this case. This is because there is no fixed number of tokens we can use to choose between the alternatives, due to a potentially infinite number of "A" tokens that can appear before the "B"|"C"|"D" tokens.

Edit this page on GitHub
Last Updated: 2/27/26, 8:20 PM
Contributors: Shahar Soel, bd82
Prev
Blazing Fast
Next
Separation of Grammar and Semantics