[m-users.] DCG-s in Mercury

Sean Charles (emacstheviking) objitsu at gmail.com
Sun Apr 25 22:05:11 AEST 2021


Hi Tomas,

Thanks for the heads up! I have been reading the calculator.m sample code from the ROTD build I have. Yes, things are different in Mercury land than Prolog land here and there. I spent a lot of blood, sweat and tears getting the lever and the AST builder to where they are. I was furloughed for 8 months and every day for about six hours I moved it all long.

The master plan is here : http://felt-lang.com <http://felt-lang.com/>.  ////certainly not a new idea but never done by me before. That site is written in my language, and all done with PHP which I hated but PHP was and still is ubiquitous. I then tried to write a v2.0 in Haskell, C, OCaml but always in my mind I knew it had to be Prolog, but recently I hit some issues with modules and multifile/1 etc and so, having first played with Mercury(!) in 2019 I decided that this is it, death or glory, the code gets ported or bust,

I —WILL- finish the job. Wether its CPS style or DCG or a hand-rolled DFA/FSM with CPS thrown in, whatever it takes.

Thanks.
Sean.


> On 24 Apr 2021, at 10:56, Tomas By <tomas at basun.net> wrote:
> 
> On Sat, 24 Apr 2021 11:33:31 +0200, Sean Charles (emacstheviking) wrote:
>> [...] now I have two sets of DCG rules to port from SWI Prolog and I
>> just don’t know where to start. [...]
> 
> 
> There are a couple of problems: partical data structures and
> nondeterminism. If the DCG is for a formal language (ie programming
> code) then it is better to rewrite the parser, for example using
> `continuation passing' (I think it's called).
> 
> To implement a DCG in Mercury you need to have solutions/2 at the top,
> and then make all the `grammar rules' nondet. Constructing the output
> holistically, as is/was common in DCGs, does not work (unless it has
> been added in the twenty years or so since I tried it).
> 
> But to begin with you can just remove all the output parameters from
> the DCG, and then look at that problem after the parsing works.
> 
> There are some minor advantages compared to Prolog, e.g. you can write
> Kleene operators (star, plus, question mark) to make things
> prettier. This has been discussed here before I believe.
> 
> /Tomas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20210425/5c558b2f/attachment.html>


More information about the users mailing list