[mercury-users] segmentation violation with wrong syntax sources

Ian MacLarty maclarty at csse.unimelb.edu.au
Tue Jun 29 10:58:10 AEST 2010


Hi,

On Tue, Jun 29, 2010 at 12:47 AM, Jean-Marc Vanel
<jeanmarc.vanel at gmail.com> wrote:
> Hi
> I tried to run the pasted and corrected version of the cryptarithm example
> from the tutorial (cf my preceding post) .
> Alas, I couln't, as I met a segmentation violation.
> So I tried to write a small example showing the same problem. Here it is :
> :- module crypt_crash3.
> :- interface.
> :- pred main is det.
> :- implementation.
>
> main :-
>   CAT = 100 * C % segmentation violation <<<<<<<<<<<<
>   % CAT = C  % OK ! warning: unresolved polymorphism.  The variables with
> unbound types were: C: V_1 CAT: V_1
> .
>
> Here is the result of compiling this :
> /usr/local/mercury-10.04-beta-2010-06-24/bin/mmc --make crypt_crash3
> *** Mercury runtime: caught segmentation violation ***
> cause: address not mapped to object
> address involved: 0x9994f80
> This may have been caused by a stack overflow, due to unbounded recursion.
> exiting from signal handler
> zsh: segmentation fault  /usr/local/mercury-10.04-beta-2010-06-24/bin/mmc
> --make crypt_crash3
> It is hard to learn Mercury if the compiler does not flag syntax errors
> correctly !
> I put my version of crypt.m that looks good but however makes a segmentation
> violation here :
> http://jmvanel.free.fr/tmp/crypt.m

When I try to compile this module using rotd-2010-01-30 I don't get a
segfault.  Instead I get the following error:

crypt.m:027: Syntax error: Illegal character 0xE2 (226) in input.

This is because the asterix characters are not the usual ascii asterix
characters.  Changing them to '*' yielded a couple more syntax errors:

crypt.m:011: Syntax error at token ` (': operator or `.' expected.

and then:

crypt.m:013: Syntax error at variable `Ds0': expecting `)' or operator.

After fixing these it compiled and ran.

Here is the fixed version:

:- module crypt.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.

:- implementation.
:- import_module int, list, string.

main(!IO) :-
io.format( "DOG + ANT = CAT\n", [], !IO),
( if
true,
        Ds0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ,
        C0 = 0 ,
        pick( Ds0 , G, Ds1 ),
        pick( Ds1 , T, Ds2 ),
        T = (G + T + C0 ) mod 10,
        C1 = (G + T + C0 ) / 10,
        pick( Ds2 , O, Ds3 ),
        pick( Ds3 , N, Ds4 ),
        A = (O + N + C1 ) mod 10, A \= 0, C2 = (O + N + C1 ) / 10,
        pick( Ds4 , D, Ds5 ),
        pick( Ds5 , A, Ds6 ),
        C = (D + A + C2 ) mod 10, D \= 0, 0 = (D + A + C2 ) / 10,
        pick( Ds6 , C, _)
then
        DOG = 100 * D + 10 * O + G,
        ANT = 100 * A + 10 * N + T,
        CAT = 100 * C + 10 * A + T,
        io.format("%d + %d = %d\n", [i(DOG), i(ANT), i(CAT)], !IO)
else
        io.format("has no solutions\n", [], !IO)
)
.

:- pred pick(list(int)::in, int::out, list(int)::out) is nondet.

pick([X | Xs], X, Xs).
pick([X | Xs], Y, [X | Zs]) :- pick(Xs, Y, Zs).


Here is the system I ran on:

Linux vostro 2.6.32-22-server #36-Ubuntu SMP Thu Jun 3 20:38:33 UTC
2010 x86_64 GNU/Linux

Ian.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list