new BNFP()
Creates a new grammar representation.
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
levels |
Array.<page.BNFP.Precedence> | list of lists of terminals with equal precedence and associativity in order of increasing precedence. This list needs to be complete before the first call to page.BNFP#rule with an explicit precedence. |
Extends
Classes
Members
-
<static> builder
-
An object with action functions corresponding to page.BNFP.grammar for page.SLR1#reflect which require a new page.BNFP as environment to represent a grammar in BNF notation with precedences and
errorusing this environment.- Source:
-
<static> grammar
-
The left-recursive BNF SLR(1) grammar for BNFP.
- Source:
Methods
-
<static> from(_grammar)
-
Factory method: Represent a grammar described in BNFP.
This is bootstrapped using page.BNF.from and page.BNFP.grammar to create an SLR(1) compiler for BNFP which uses page.BNFP.builder.
Parameters:
Name Type Description _grammarstring description in BNFP; comments extend from
#to the end of a line.- Source:
Returns:
a new grammar representation; check
.errors.- Type
- page.BNFP
-
dump()
-
Displays a grammar and all non-terminals with name and contents of all sets.
- Inherited From:
- Source:
Returns:
- Type
- string
-
dump()
-
Displays a grammar and all non-terminals with name and contents of all sets.
- Source:
Returns:
- Type
- string
-
getByOrd(_ord)
-
Returns symbol by
ord.Parameters:
Name Type Description _ordnumber page.BNF.NT or page.BNF.T's
ord.- Inherited From:
- Source:
Returns:
- Type
- Node
-
init( [_start] [, _rules])
-
Must be called once to complete BNF grammar initialization.
Completes rule 0 with a new start symbol
$acceptto accept the grammar's original start symbol and then$eof.Sets page.BNF.Rule
.indexas index into the rules array. Setsemptyfor each rule and its non-terminal which has an empty right-hand side.Checks that all non-terminals are defined, can be reached, and cannot expand infinitely without generating terminals.
Computes
firstandfollowfor all rules and non-terminals.Parameters:
Name Type Argument Description _startpage.BNF.NT <optional>
start symbol of grammar, default is the non-terminal of rule 1.
_rulesArray.<page.BNF.Rule> <optional>
(additional) grammar rules.
- Inherited From:
- Source:
- See:
-
<private> initTree( [_rules])
-
Must be called once; common code to complete grammar initialization.
Adds rules passed as a parameter to page.BNF
.rules.Sorts literals in reverse order, i.e., longer ones before shorter prefixes. Defines page.BNF.T
.ordand page.BNF.NT.ordas globally unique index (literals before tokens before non-terminals). Sets page.BNF.T.firstfor each terminal to contain itself.Parameters:
Name Type Argument Description _rulesArray.<page.BNF.Rule> <optional>
(additional) grammar rules.
- Inherited From:
- Source:
-
lit( [_literal])
-
Parameters:
Name Type Argument Description _literalstring <optional>
literal's representation; if omitted represents the
$eofliteral terminal.- Inherited From:
- Source:
Returns:
a unique literal.
- Type
- page.BNF.Lit
-
nt( [_name])
-
Factory method to create a unique non-terminal representation, maintains page.BNF
.ntsand page.BNF.ntsByName, checks against page.BNF.tokensByName.Parameters:
Name Type Argument Description _namestring <optional>
non-terminal's name; cannot start with
$. If$creates a unique name which cannot be searched for. If omitted represents the$acceptnon-terminal.- Inherited From:
- Source:
Returns:
a unique non-terminal representation.
- Type
- page.BNF.NT
-
precedence(_assoc, _terminals)
-
Factory method to represent a list of terminals with equal precedence level and equal associativity.
Creates a new page.BNFP.Precedence object, adds it to page.BNFP
.levels, adds.prec.leveland.prec.assocto all terminals in the list, and checks for duplicates.Parameters:
Name Type Description _assocstring associativity:
'left','right', or'nonassoc'._terminalsArray.<page.BNF.T> list of terminals.
- Source:
Throws:
-
an error message if there is duplication.
- Type
- string
Returns:
representing the set.
- Type
- page.BNFP.Precedence
-
rule(_nt [, _symbols])
-
Factory method to create a rule representation for BNF. Adds to rule's non-terminal's page.BNF.NT
.rules.Parameters:
Name Type Argument Description _ntpage.BNF.NT left-hand side, non-terminal.
_symbolsArray.<Node> <optional>
right-hand side, may be empty array; if omitted, creates empty rule 0 for
$accept.- Inherited From:
- Source:
- See:
-
- page.BNF.init
Returns:
a new rule representation.
- Type
- page.BNF.Rule
-
rule(_nt [, _symbols] [, _prec])
-
Factory method to create a rule representation for BNFP. Adds to rule's non-terminal's page.BNF.NT
.rules.Parameters:
Name Type Argument Description _ntpage.BNF.NT left-hand side, non-terminal.
_symbolsArray.<Node> <optional>
right-hand side, may be empty array; if omitted, creates empty rule 0 for
$accept._precpage.BNF.T <optional>
terminal defining precedence explicitly; by default last terminal in right-hand side, if any. page.BNFP
.levelsneeds to be complete before this parameter is specified.- Source:
Throws:
-
an error message if an explicit precedence cannot be resolved.
- Type
- string
Returns:
a new rule representation.
- Type
- page.BNFP.Rule
-
token( [_name] [, _pattern])
-
Factory method to create a unique token, maintains page.BNF
.tokensand page.BNF.tokensByName, checks against page.BNF.ntsByName.Parameters:
Name Type Argument Description _namestring <optional>
token's name; cannot start with
$. If omitted represents the$errortoken._patternstring <optional>
pattern to match values representing the token in input; must be specified if and only if the token is created.
- Inherited From:
- Source:
Returns:
a unique terminal category representation.
- Type
- page.BNF.Token
-
tokenizer( [_skip])
-
Creates a function which tokenizes a string.
For literals with common prefixes the longer literal will be matched first. Token patterns are matched after literals and in the order the tokens were defined.
Parameters:
Name Type Argument Description _skipstring | RegExp <optional>
a pattern to define ignorable character sequences; this pattern must not accept empty input and it must use
(:? )rather than( )for grouping; the default is to skip white space.- Inherited From:
- Source:
Returns:
a function which takes a string and returns a list of page.Tuple elements. The list contains one tuple with the
errortoken for each character which is neither ignorable nor a literal or part of a token. The function is based on a regular expression which can be displayed as a member.pattern.- Type
- Tokenizer
-
toString()
-
Displays description of grammar and number of errors if any.
- Inherited From:
- Source:
Returns:
- Type
- string
-
toString()
-
Displays description of grammar and number of errors if any.
- Source:
Returns:
- Type
- string
page