new Language(rules)
Define a language syntax with BNF like description.
Define a language syntax with BNF like description.
Parameters:
Name | Type | Description |
---|---|---|
rules |
Array.<SyntaxRule> | array of syntax definition |
- Source:
Members
root :string
Type:
- string
- Source:
rules :Record.<string, SyntaxRule>
Type:
- Record.<string, SyntaxRule>
- Source:
Methods
(static) syntax(name, rules, evaluator) → {SyntaxRule}
Create a syntax rule as an element for parameter of the constructor.
Create a syntax rule as an element for parameter of the constructor.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | syntax name |
rules |
Array.<Rule> | syntax rules |
evaluator |
Evaluator | evaluator function |
- Source:
Returns:
syntax object
- Type
- SyntaxRule
evaluate(term) → {any}
Evaluate an analyzed code.
Evaluate an analyzed code.
Parameters:
Name | Type | Description |
---|---|---|
term |
Term | A term returned from `Language#parse' |
- Source:
Returns:
A value returned from the evaluator for the term.
- Type
- any
parse(source) → {Term}
Analyze the codes by recursive descent parsing based on the BNF rule.
Analyze the codes by recursive descent parsing based on the BNF rule.
Parameters:
Name | Type | Description |
---|---|---|
source |
string | Array.<Token> | source code or token list |
- Source:
Returns:
result
- Type
- Term
tokenize(source) → {Array.<Token>}
Tokenize the source code by lexical analysis.
Tokenize the source code by lexical analysis.
Parameters:
Name | Type | Description |
---|---|---|
source |
string | source code |
- Source:
Returns:
an array of lexical tokens. It contains tokens type of whitespaces, string literal, number literal, or punctuators. Types of token:
Language.whitespace
Language.strlit
Language.numlit
Language.punct
- Type
- Array.<Token>