% vim: ft=mercury ts=4 sw=4 et
%
%  Compiling this module as follows with rotd-2011-02-14 and before:
%
%     mmc --infer-all bug186a.m
%
% results in:
%
% Uncaught Mercury exception:
% Software Error: modes.m: Unexpected: modecheck_queued_proc: found detism error

:- module bug186b.
:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.

:- import_module list.
:- import_module string.
:- import_module char.
:- import_module solutions.
:- import_module require.
:- import_module int.
:- import_module bool.

:- type bf_cmd
    --->    plus
    ;       print
    ;       step(int).

chars_to_ast(Chars) = Ast :-
    (  
        one_solution(
            (pred(Ast_::out) is nondet :- ast(Ast_, Chars, []:list(char))),
            Ast0)
    ->
        Ast = Ast0
    ;
        error("Program invalid (parse error)!")
    ).

one_solution(Pred, Solution) :-
    solutions(Pred, [Solution| _]).

% Works with this line uncommented.
%:- mode ast(out, in, out) is multi.

ast([plus|Cmds]) --> ['+'], ast(Cmds).
ast([print|Cmds]) --> ['.'], ast(Cmds).
ast([]) --> [].

main(!IO).
