Mímico

Overview

•  Input: a grammar specification with semantic rules — that is, some productions of the form:

A = r  {| e |}

where:
•  A is a nonterminal — production's left-hand side (lhs)
•  r  is a sequence of terminals and/or nonterminals — production's right-hand side (rhs)
•  e  is a Haskell expression — production's semantic rule

•  Output: a recursive descent monadic parser, that parses strings and returns the value specified by the (semantic rule of the) first production. Each production specifies a (sub)string to be parsed and the value obtained after a successful parsing.

•  Mímico parses alternatives in their textual order — the Pastor rule (parse as specified by the textual order).

The generated parser tries to parse a subsequent alternative only if the previous ones have failed to produce a successful parse of the input.

In other words, grammar productions form a list, not a set: ambiguities never occur.

•  Behaviour: For a list of productions of the form:

Ai = ri  {| ei |}

for i=1…n, Mímico generates a "compiler" which follows the Pastor rule for each of the productions, and a compiler for the initial symbol — the nonterminal at the lhs of the first production — that implements the following additional production, automatically introduced by Mímico:
S = A1 eoi   {| A1 |}

In this production, eoi  represents a parser that succeeds if and only if the end of the input is reached (and A1  is the initial symbol).

•  Semantic rules may also be monadic, in which case productions have the form:

A = r  [| e |]

Monadic semantic rules are typically used to control parsing. They may specify parsing failure or success according to "semantic" conditions. For example, in:

comment = c  anyCharTillEOLn   [| chkColPos c |}

chkColPos may be used to specify a successful parsing if and only if the letter c appears as the first letter in a line of the string to be parsed (see chkColPos in the toy examples).
Carlos Camarão de Figueiredo
Last modified: Fri Oct 7 16:52:48 BRT 2005