Basic Examples (4)
Here is an EBNF grammar:
Here we generate random sentences with the grammar above:
Make a parser for a family of (two) simple sentences:
Here we parse a sentence adhering to the grammar of the defined parser:
Here we parse the other sentence of that grammar:
These sentences are not be parsed:
Here is another parser over longer, more complete integration sentences:
Here we parse a sentence (adhering to the grammar of the defined parser):
Here is another parsing:
Rewrite the parser above with suitable interpretation:
Here we parse a numerical integration command:
Here we parse a symbolic integration command:
Scope (4)
It is much easier to follow the parser and interpreter specification using Extended Backus-Naur Form (EBNF):
Here we generate the parsers:
Here we parse -- and interpret -- integration commands:
Here is an EBNF description of a Domain Specific Language (DSL) for food cravings:
Generate parsers from the EBNF string:
Test the parser pLOVEFOOD -- for the highest level rule "<lovefood>" -- with a list of sentences:
Note the EBNF rule wrappers -- those are symbols specified at the ends of some of the rules.
Generate random sentences from the grammar above:
We can implement interpreters that tell calorie intake for proclaimed food affinities and cravings. We can use WolframAlpha to get the calories, but since using WolframAlpha can be slow it is overridden inside Block:
Here the parsing tests are re-done by changing the definitions of the wrapping symbols LoveFood and LoveObjects: