<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I am having terrible push—pull whack-a-mole issues with my parser and it is literally driving me to despair, I have read 6, 6.1 6,2 over and over until the words have become one long unintelligible mantra of confusion.<div class=""><br class=""></div><div class="">I thought —I— decided the determinism then wrote the code and the compiler moans at me to tell me I got it wrong. I can accept that. But I just don’t ‘get it’ yet. Case in point, of the of many errors I now have… …and once again I failed to represent my problem so nobody can help me. Perhaps I can ask some more general questions and then apply the answers to my brain and then to my code? Except I am so confused I can’t frame a question.</div><div class=""><br class=""></div><div class=""><div class="">ast.m:040: In `on_lexer'(in, in, out):</div><div class="">ast.m:040:   error: determinism declaration not satisfied.</div><div class="">ast.m:040:   Declared `det', inferred `multi'.</div><div class="">ast.m:115:   Call to `ast.parse_all'(in, out, in, out) can succeed more than</div><div class="">ast.m:115:   once.</div><div class="">ast.m:254: In `parse_body_term'(out, in, out):</div><div class="">ast.m:254:   warning: determinism declaration could be tighter.</div><div class="">ast.m:254:   Declared `nondet', inferred `multi'.</div><div class="">ast.m:275: In `parse_fncall'(out, in, out):</div><div class="">ast.m:275:   error: determinism declaration not satisfied.</div><div class="">ast.m:275:   Declared `semidet', inferred `nondet'.</div><div class="">ast.m:283:   Call to `ast.parse_body'(in, out, in, out) can succeed more than</div><div class="">ast.m:283:   once.</div><div class="">ast.m:431: In `sexp_or_error'(out, in, in, out):</div><div class="">ast.m:431:   error: determinism declaration not satisfied.</div></div><div class=""><br class=""></div><div class="">So I change one and then recompile and it pops up somewhere else until eventually, the ‘det’ entry point into the module wants to be multi… sigh.</div><div class=""><br class=""></div><div class="">I ditched DCG syntax in favour of state variables which helped readability.</div><div class=""><br class=""></div><div class="">How does the compiler know something is ‘multi’. I guess I don’t know how to interpret the manual properly.</div><div class=""><br class=""></div><div class=""><i class="">If all possible calls to a particular mode of a predicate or function which return to the caller (calls which terminate, do not throw an exception and do not cause a fatal runtime error)<br class=""><br class=""></i><div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre">  </span>• have exactly one solution, then that mode is deterministic (det);<br class=""></i></div><div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• either have no solutions or have one solution, then that mode is semideterministic<br class="">(semidet);<br class=""></i></div><div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre">     </span>• have at least one solution but may have more, then that mode is multi-solution(multi);<br class=""></i></div><div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• have zero or more solutions, then that mode is nondeterministic (nondet);<br class=""></i></div><div class=""><i class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• fail without producing a solution, then that mode has a determinism of failure.</i></div></div><div class=""><br class=""></div><div class="">I parse a file into a stream of tokens, there can be only one correct way to parse those into a well formed program. One. So the ast builder either fails or it doesnt, that is trapped in the code and a maybe_error is handed back, hence I figure the predicate, as seen by the caller (the REPL atm) should be `det`.</div><div class=""><br class=""></div><div class="">What does it ‘mean’ to be able to have more than one solution? I am not really writing Prolog like code i.e. swathes of facts and rules being interrogated, I am happy with choice-points and backtracking (I thought so anyway).</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">If I had some good clean examples I think I’d be fine, I look forward to the Eureka moment regarding how to defend myself against the big scary Determinasaurus Rex once and for all because until then I think I’m losing what’s left of my tiny little mind. Mercury feels like the language I wish I’d found 20 years ago and I am determined to get over this obstacle.</div><div class=""><br class=""></div><div class="">Thanks.</div><div class="">Sean</div><div class=""><br class=""></div></body></html>