<div dir="ltr">Thank you Julien and Raghu.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 16 Jan 2023 at 11:17, Julien Fischer <<a href="mailto:jfischer@opturion.com">jfischer@opturion.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
Hi,<br>
<br>
On Fri, 13 Jan 2023, Modestas Valauskas wrote:<br>
<br>
> I'm looking for a formal grammar for Mercury. I'm thinking of a<br>
> declarative specification in the form of e.g. BNF/EBNF or perhaps<br>
> ANTLR or a different parser generator tool, but if that is not<br>
> available, anything else that would allow me to more easily write a<br>
> formal grammar for Mercury would be appreciated.<br>
<br>
There isn't one written down in a single spot, so far as I am aware.<br>
Some of it scattered throughout the reference manual -- the version<br>
from recent ROTDs is probably more useful in this respect than the<br>
current release.<br>
<br>
The way Mercury is parsed is a little unusual (mainly for historical<br>
reasons). The main steps are:<br>
<br>
1. Tokenization (done by library/mercury_term_lexer.m).<br>
2. Parsing the token stream into terms (done by<br>
libary/mercury_term_parser.m and related modules.)<br>
3. Parsing of terms into items (declarations and clauses).<br>
<br>
The compiler design document (in compiler/notes/compiler_design.html)<br>
describes this in more detail and provides pointers to the relevant<br>
bits of code.<br>
<br>
Julien.<br>
</blockquote></div>