Home Manual Reference Source

Function

Static Public Summary
public

alphabet(productions: *): *

public

anyIterator(object: *): *

public

* audit(grammar: Grammar): IterableIterator<any>

List all reasons why a given grammar is not ll(1).

public

compile(productions: Map): Map

Compiles the predictive parsing table for a grammar.

public

expandobject(object: *): *

public

async * flatten(root: *)

public

follow(FOLLOW: Map, rule: Array): Set

Generate FOLLOW set for any rule given the FOLLOW sets for the nonterminals.

public

from(object: *): *

public

from(grammar: *): *

public

is(grammar: Grammar): Boolean

Check if grammar is ll(1).

public

map(callable: Function, children: AsyncIterable): AsyncIterable

Applies a given callable to each of the child of a given children async iterable.

public

async materialize(root: *): *

public

parse(root: *, start: *, eof: *, productions: *, table: *, tape: *): Object

Parse

public

async * rmap(callable: Function, rule: Iterable): AsyncIterator

Applies a given callable to each part of a given grammar rule (given as an iterable).

public

setadd(set: Set<any>, element: any): boolean

Adds an element to a set and returns true if the set has changed.

public

setaddall(set: Set<any>, iterable: Iterable<any>): boolean

Adds all elements of an iterable to a set and returns true if the set has changed.

public

async transform(tree: *, match: *, ctx: *): *

Static Private Summary
private

async _children_exhaust(children: Iterator)

Exhausts the input children iterator.

private

async _children_next_lazy(eof: Object, productions: Map, table: Map, tape: Tape, expected: Object): Promise<object>

Get next child of table-driven predictive lazy parsing.

private

* _compile(productions: Map): Iterable

Generates the rows of the predictive parsing table for a grammar.

private

* _expandproduction(production: *)

private

_follow(FIRST: Map, productions: Map): Map

Computes the FOLLOW table for all nonterminals.

private

_parse_lazy(eof: Object, productions: Map, table: Map, rule: Array, tape: Tape, nonterminal: String, production: String): Object

Table-driven predictive lazy parsing.

Static Public

public alphabet(productions: *): * source

Params:

NameTypeAttributeDescription
productions *

Return:

*

public anyIterator(object: *): * source

Params:

NameTypeAttributeDescription
object *

Return:

*

public * audit(grammar: Grammar): IterableIterator<any> source

List all reasons why a given grammar is not ll(1).

Params:

NameTypeAttributeDescription
grammar Grammar

Return:

IterableIterator<any>

public compile(productions: Map): Map source

Compiles the predictive parsing table for a grammar. Corresponds to Algorithm 4.31 in Dragon Book (2006) on page 224.

Params:

NameTypeAttributeDescription
productions Map

Return:

Map

public expandobject(object: *): * source

Params:

NameTypeAttributeDescription
object *

Return:

*

public async * flatten(root: *) source

Params:

NameTypeAttributeDescription
root *

public follow(FOLLOW: Map, rule: Array): Set source

Generate FOLLOW set for any rule given the FOLLOW sets for the nonterminals.

Params:

NameTypeAttributeDescription
FOLLOW Map
rule Array

Return:

Set

public from(object: *): * source

Params:

NameTypeAttributeDescription
object *

Return:

*

public from(grammar: *): * source

Params:

NameTypeAttributeDescription
grammar *

Return:

*

public is(grammar: Grammar): Boolean source

Check if grammar is ll(1).

Params:

NameTypeAttributeDescription
grammar Grammar

Return:

Boolean

public map(callable: Function, children: AsyncIterable): AsyncIterable source

Applies a given callable to each of the child of a given children async iterable.

Params:

NameTypeAttributeDescription
callable Function

The callable to use.

children AsyncIterable

The input children.

Return:

AsyncIterable

public async materialize(root: *): * source

Params:

NameTypeAttributeDescription
root *

Return:

*

public parse(root: *, start: *, eof: *, productions: *, table: *, tape: *): Object source

Parse

Params:

NameTypeAttributeDescription
root *
start *
eof *
productions *
table *
tape *

Return:

Object

public async * rmap(callable: Function, rule: Iterable): AsyncIterator source

Applies a given callable to each part of a given grammar rule (given as an iterable).

Params:

NameTypeAttributeDescription
callable Function

The callable to use.

rule Iterable

The input grammar rule.

Return:

AsyncIterator

public setadd(set: Set<any>, element: any): boolean source

Adds an element to a set and returns true if the set has changed.

Params:

NameTypeAttributeDescription
set Set<any>

The set to add to.

element any

The element to add to the set.

Return:

boolean

Whether set has changed.

public setaddall(set: Set<any>, iterable: Iterable<any>): boolean source

Adds all elements of an iterable to a set and returns true if the set has changed.

Params:

NameTypeAttributeDescription
set Set<any>

The set to add to.

iterable Iterable<any>

The iterable of elements to add to the set.

Return:

boolean

Whether set has changed.

public async transform(tree: *, match: *, ctx: *): * source

Params:

NameTypeAttributeDescription
tree *
match *
ctx *

Return:

*

Static Private

private async _children_exhaust(children: Iterator) source

Exhausts the input children iterator.

Params:

NameTypeAttributeDescription
children Iterator

The input children iterator.

private async _children_next_lazy(eof: Object, productions: Map, table: Map, tape: Tape, expected: Object): Promise<object> source

Get next child of table-driven predictive lazy parsing.

Params:

NameTypeAttributeDescription
eof Object

The end-of-file symbol.

productions Map

The ll1 productions.

table Map

The symbol table.

tape Tape

The tape from which to read the symbols from.

expected Object

The expected node.

Return:

Promise<object>

A node.

private * _compile(productions: Map): Iterable source

Generates the rows of the predictive parsing table for a grammar. Corresponds to Algorithm 4.31 in Dragon Book (2006) on page 224.

Params:

NameTypeAttributeDescription
productions Map

Return:

Iterable

private * _expandproduction(production: *) source

Params:

NameTypeAttributeDescription
production *

private _follow(FIRST: Map, productions: Map): Map source

Computes the FOLLOW table for all nonterminals.

Params:

NameTypeAttributeDescription
FIRST Map

The FIRST table as computed by ll1#_first

productions Map

The productions map.

Return:

Map

The FOLLOW table.

private _parse_lazy(eof: Object, productions: Map, table: Map, rule: Array, tape: Tape, nonterminal: String, production: String): Object source

Table-driven predictive lazy parsing.

Params:

NameTypeAttributeDescription
eof Object

The end-of-file symbol.

productions Map

The ll1 productions.

table Map

The symbol table.

rule Array

The production rule in use.

tape Tape

The tape from which to read the symbols from.

nonterminal String

The nonterminal that produced rule.

production String

The production that corresponds to rule.

Return:

Object

The root node of the parsed tree.