This is a fully implemented interpreter for the MiniRE 'toy' language. You can think of MiniRE as a mini Awk or Perl.
MiniRE deals primarily with the combination and manipulation of string-lists.
begin pups = find 'puppy' in 'animals.txt'; num_of_pups = #pups; kitties = find 'kitten' in 'animals.txt'; num_of_kitties = #kitties; pups_and_kitts = find 'puppy in 'animals.txt' union find 'kitten' in 'animals.txt; print (pups, num_of_pups, kitties, num_of_kitties); end
The above code outputs all occurrences of the words "puppy" and 'kitten', as well as the total number of occurrences of each.
This interpreter contains a built-from-scratch:
Regex Engine(automata-based)LexerScannerParserEvaluator
The regex engine, lexer, and scanner were designed to be extensible, so they contain no MiniRE-specific functionality. They can be reused with any regular language grammar to produce consumable tokens for the production of an Abstract Syntax Tree. The parser and evaluator are, however, specific to MiniRE scripts.
This is what happens when a MiniRE script is run.
- The MiniRE lexical spec is read by the
Lexer(using theRegex Engineand a series ofNondeterministic Finite State AutomataorNFAsare built and combined together. - For efficiency in later parsing, these
NFAsare converted toDeterministic Finite State AutomataorDFAs. - The MiniRE input script is read character by character and the
DFAsare used to produceTokens(meaningful groups of character e.gfindandbegin). - The resultant token stream is parsed by the (Recursive Descent)
Parserand anAbstract Syntax TreeorASTis constructed. - The
Evaluatorbegins at the root of theASTand evaluates all the nodes in the tree, producing output as necessary. - Once there are no more nodes to evaluate, the interpeter quits.
Each step has built in error handling so errors are caught before they propogate down the pipeline.