[m-dev.] A formal grammar for Mercury?
Julien Fischer
jfischer at opturion.com
Mon Jan 16 21:16:59 AEDT 2023
Hi,
On Fri, 13 Jan 2023, Modestas Valauskas wrote:
> I'm looking for a formal grammar for Mercury. I'm thinking of a
> declarative specification in the form of e.g. BNF/EBNF or perhaps
> ANTLR or a different parser generator tool, but if that is not
> available, anything else that would allow me to more easily write a
> formal grammar for Mercury would be appreciated.
There isn't one written down in a single spot, so far as I am aware.
Some of it scattered throughout the reference manual -- the version
from recent ROTDs is probably more useful in this respect than the
current release.
The way Mercury is parsed is a little unusual (mainly for historical
reasons). The main steps are:
1. Tokenization (done by library/mercury_term_lexer.m).
2. Parsing the token stream into terms (done by
libary/mercury_term_parser.m and related modules.)
3. Parsing of terms into items (declarations and clauses).
The compiler design document (in compiler/notes/compiler_design.html)
describes this in more detail and provides pointers to the relevant
bits of code.
Julien.
More information about the developers
mailing list