cfg-first-follow
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

cfg-first-follow

Calculate FIRST and FOLLOW set of a Context Free Grammar symbol.

Context Free Grammar

S -> ACB | Cbb | Ba
A -> da | BC
B -> g | Є
C -> h | Є
const grammar: ContextFreeGrammar = {
	S: [
		['A', 'C', 'B'],
		['C', 'b', 'b'],
		['B', 'a'],
	],
	A: [
		['d', 'a'],
		['B', 'C'],
	],
	B: [['g'], null],
	C: [['h'], null],
};

Usage

Parser

import { Parser, type ContextFreeGrammar } from 'cfg-first-follow';

const grammar: ContextFreeGrammar = {
	S: [
		['A', 'C', 'B'],
		['C', 'b', 'b'],
		['B', 'a'],
	],
	A: [
		['d', 'a'],
		['B', 'C'],
	],
	B: [['g'], null],
	C: [['h'], null],
};

const parser = new Parser(grammar);

First

const firstSetOfS = parser.first('S');
console.log(firstSetOfS); // Set(6) { 'd', 'g', 'h', null, 'b', 'a' }

Follow

TODO

Package Sidebar

Install

npm i cfg-first-follow

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

29.7 kB

Total Files

16

Last publish

Collaborators

  • ishibi