Wolfram Language Paclet Repository
Community-contributed installable additions to the Wolfram Language
Functional parsers
Contributed by: Anton Antonov
This paclet provides a complete set of functional parsers and automatic parser generation from grammar specifications in Extended Backus-Naur Form.
To install this paclet in your Wolfram Language environment,
evaluate this code:
PacletInstall["AntonAntonov/FunctionalParsers"]
To load the code after installation, evaluate this code:
Needs["AntonAntonov`FunctionalParsers`"]
Here is an EBNF grammar:
| In[1]:= | ![]() |
Here we generate random sentences with the grammar above:
| In[2]:= |
| Out[3]= | ![]() |
Make a parser for a family of (two) simple sentences:
| In[4]:= |
Here we parse a sentence adhering to the grammar of the defined parser:
| In[5]:= |
| Out[5]= |
Here we parse the other sentence of that grammar:
| In[6]:= |
| Out[6]= |
These sentences are not be parsed:
| In[7]:= |
| Out[7]= |
Here is another parser over longer, more complete integration sentences:
| In[8]:= | ![]() |
Here we parse a sentence (adhering to the grammar of the defined parser):
| In[9]:= |
| Out[9]= |
Here is another parsing:
| In[10]:= |
| Out[10]= |
Rewrite the parser above with suitable interpretation:
| In[11]:= | ![]() |
Here we parse a numerical integration command:
| In[12]:= |
| Out[12]= |
Here we parse a symbolic integration command:
| In[13]:= |
| Out[13]= |
It is much easier to follow the parser and interpreter specification using Extended Backus-Naur Form (EBNF):
| In[14]:= | ![]() |
Here we generate random sentences with the grammar string above:
| In[15]:= |
| Out[16]= | ![]() |
Here we generate the parsers:
| In[17]:= |
Here we parse -- and interpret -- integration commands:
| In[18]:= | ![]() |
| Out[19]= | ![]() |