ll1-parser
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

LL(1) parser

test codecov

import { LL1Parser } from 'll1-parser';

const parser = new LL1Parser();

parser.AddRule('E', '(E+I)');
parser.AddRule('E', 'I');
parser.AddRule('I', '0');
parser.AddRule('I', '1');

parser.Compile();

console.table(parser.DumpTransitionTable());
/**
 *  ┌─────────┬──────┬──────┬─────────┐
 *  │ (index) │  0   │  1   │    (    │
 *  ├─────────┼──────┼──────┼─────────┤
 *  │    E    │ 'I'  │ 'I'  │ '(E+I)' │
 *  │    I    │ '0'  │ '1'  │         │
 *  │    S    │ 'E$' │ 'E$' │  'E$'   │
 *  └─────────┴──────┴──────┴─────────┘
 **/

const tree1 = parser.Parse('((0+1)+1)');
/**
 * E
 * ├── (
 * ├─┬ E
 * │ ├── (
 * │ ├─┬ E
 * │ │ └─┬ I
 * │ │   └── 0
 * │ ├── +
 * │ ├─┬ I
 * │ │ └── 1
 * │ └── )
 * ├── +
 * ├─┬ I
 * │ └── 1
 * └── )
 **/

const tree2 = parser.Parse('(0+2)');
// Error: Failed to find grammar for transition 'I => 2'

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.31latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.31
0.0.10

Package Sidebar

Install

npm i ll1-parser

Weekly Downloads

1

Version

0.0.3

License

ISC

Unpacked Size

13.9 kB

Total Files

11

Last publish

Collaborators

  • imperger