Inspecting the language
In the previous step we defined our greeting
expression, a type consisting of two functions. We can now create a new language from this expression, appropriately called greet
.
const greet = new Language("greet", greeting);
Krikata can automatically generate a grammar for greet
in an approximate BNF notation.
const grammar = greet.grammar();
console.log(grammar.format());
l.greet:
| <t.greeting> EOI
t.greeting:
| "hi"
| "hello" <p.string>
We see our two expressions. First the language greet, which expects a greeting type followed by the special End-Of-Input, and second the greeting type itself, which matches either the string hi
or the string hello
followed by a primitive string.