# cfg-first-follow

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

Latest version **0.1.0** (published 2022-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install cfg-first-follow
pnpm add cfg-first-follow
yarn add cfg-first-follow
bun add cfg-first-follow
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-05-01 |
| First published | 2022-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shubham Parihar |
| Maintainers | ishibi |
| Keywords | first-set, follow-set, context-free-grammar, compiler-design |

## Links

- npm: https://www.npmjs.com/package/cfg-first-follow
- Repository: https://github.com/iShibi/cfg-first-follow
- Homepage: https://github.com/iShibi/cfg-first-follow#readme
- Issues: https://github.com/iShibi/cfg-first-follow/issues
- npm.io page: https://npm.io/package/cfg-first-follow

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2022-05-01

## README

# 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 | Є
```

```ts
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

```ts
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

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

### Follow

TODO

---
_Source: https://npm.io/package/cfg-first-follow · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
