[m-users.] Determinism issue with parser
Sean Charles (emacstheviking)
objitsu at gmail.com
Sun Jul 4 23:17:42 AEST 2021
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.
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.
ast.m:040: In `on_lexer'(in, in, out):
ast.m:040: error: determinism declaration not satisfied.
ast.m:040: Declared `det', inferred `multi'.
ast.m:115: Call to `ast.parse_all'(in, out, in, out) can succeed more than
ast.m:254: In `parse_body_term'(out, in, out):
ast.m:254: warning: determinism declaration could be tighter.
ast.m:254: Declared `nondet', inferred `multi'.
ast.m:275: In `parse_fncall'(out, in, out):
ast.m:275: error: determinism declaration not satisfied.
ast.m:275: Declared `semidet', inferred `nondet'.
ast.m:283: Call to `ast.parse_body'(in, out, in, out) can succeed more than
ast.m:431: In `sexp_or_error'(out, in, in, out):
ast.m:431: error: determinism declaration not satisfied.
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.
I ditched DCG syntax in favour of state variables which helped readability.
How does the compiler know something is ‘multi’. I guess I don’t know how to interpret the manual properly.
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)
• have exactly one solution, then that mode is deterministic (det);
• either have no solutions or have one solution, then that mode is semideterministic
• have at least one solution but may have more, then that mode is multi-solution(multi);
• have zero or more solutions, then that mode is nondeterministic (nondet);
• fail without producing a solution, then that mode has a determinism of failure.
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`.
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).
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the users