A module which extends the Base module and supports creating scanners and recursive descent parsers from LL(1) grammars and actions written in JavaScript.
The fundamental object created by this module
is a Grammar prepared from grammar rules
using the syntax defined here.
The syntax includes alternative and optional and iterated sequences,
all of which must not recognize empty input.
This book chapter explains how to write grammar rules.
A Grammar, optionally with precedences,
can be imported by the BNF module for stack-based parsing,
but the BNF and EBNF modules
do not depend on each other.
The grammar rules are represented using a number of classes as discussed in this book chapter and summarized in the following table:
| tree structure | getters | checking | parsing |
|---|---|---|---|
Grammar |
config, rules, prefix |
check() |
parser().parse() |
Node |
grammar, expect, #follow |
shallow(), deep(), follow(), check() |
parse(): stringfor terminals |
Lit: Lit: T: Symbol + Node |
name, value, prec, used, expect |
: string |
|
Token: Token: T: Symbol + Node |
name, pat, prec, used, expect |
: string |
|
NT: NT: Symbol + Node |
name, rule: Rule, expect |
shallow(), deep(), follow() |
parse(): Array| action value |
Alt + Node |
seqs: Seq[], expect |
shallow(), deep(), follow(), check() |
parse(): Array |
Rule: Alt |
nt, recursed, reached |
shallow(), deep() |
parse(): Array| action value |
Opt: Alt |
check() |
: null|Array |
|
Some: Alt |
follow(), check() |
parse(): Array<Array> |
|
Seq + Node |
nodes: Array<Symbol|Opt|Some>, prec: Term , expect |
shallow(), deep(), follow(), check() |
parse(): Array |
- Version:
-
- 2024-02-12
- Source:
- See: