Desrired Language Features

amn@ubik.demon.co.uk (Anthony Naggs)
Sat, 2 Oct 1993 16:34:48 GMT

          From comp.compilers

Related articles
Desrired Language Features amn@ubik.demon.co.uk (1993-10-02)
Re: Desired Language Features dekker@dutiag.twi.tudelft.nl (1993-10-04)
Re: Desired Language Features henry@zoo.toronto.edu (1993-10-06)
Re: Desired Language Features doug@netcom.com (1993-10-19)
Re: Desired Language Features throop@aurw44.aur.alcatel.com (1993-10-20)
| List of all articles for this month |
Newsgroups: comp.compilers
From: amn@ubik.demon.co.uk (Anthony Naggs)
Keywords: design, question
Organization: Compilers Central
Date: Sat, 2 Oct 1993 16:34:48 GMT

I often find difficulty in solving programming problems because of the
poor features of the languages I use. So I am considering designing and
implementing a small language of my own. (I know, a familiar story).




Some features at the top of my list, with examples based on 'C':


<1> Errors and procedures can indicate a failure, (with the common assembly
        language technique of setting/clearing the Carry flag appropriately), eg:
                double acosh (double cosh)
                {
                        if (cosh < 1.0)
                                fail ;


                        ...
                }


<2> Procedures can return an error code iff an error occurs, eg:
                error positive (double fval)
                {
                        /* fail if fval is negative */
                        if (fval < 0.0)
                                fail (EDOM);


                        return;
                }


<2> Local exception handling using an 'error' block, for minor problems
        that are easily resolved, eg:
                int foo (double fp1)
                {
                        double fp2;


                        /* catch local exceptions */
                        /* error is set to -1 if no implicit assignment is made */
                        error
                        {
                                case EDOM:
                                        fp1 = 1.1;
                                        goto g1;


                                default:
                                        fprintf (stderr, "foo(): error %i\n", error);
                                        return (0);
                        }


                        /* if positive() fails execution goes to error block */
                        /* & error references the error code returned */
                        positive (fp1);


                g1:
                        /* if acosh() fails execution goes to error block */
                        fp2 = acosh (fp1);
                }


<3> Global error handling, for serious problems. Possibly by extending the
        error block to inorporate Ada's solid model, ('raise' & 'exception').
        I think the 'try' block proposed for C++ is syntactly ugly, (Koenig &
        Stroustrup, chapter 14, "The Annotated C++ Reference Manual", Ellis &
        Stroustrup, 1990). BASIC is quite powerful, ('on error goto', 'resume'
        'resume next', 'resume <linenumber>'), but not very pracical.


<4> Three way comparisons, eg:
                compare (value, reference)
                {
                        case < : /* value < reference */
                                        ...
                        case = : /* value = reference */
                                        ...
                        case > : /* value > reference */
                                        ...
                }


        eg #2:
                range (minimum, value, maximum)
                {
                        case < : /* value < minimum, (could also be '<=') */
                                        ...
                        case > : /* value > maximum, (could also be '>=') */
                                        ...
                        default: /* minimum <[=] value <[=] maximum */
                                        ...
                }


<5> Language support for testing input parameters, to replace the normal
        kludges of nested if's or 'do .. while (0)', etc... This is essential
        for any formal verification of program operation, (eg to compare a
        program with a first order predicate logic design in VDM or as a Z
        schema). For example, using a 'test' block with 'require' & 'accept';
                int foo (int value1, int value2, int value3)
                {
                        test
                        {
                                /* function 'fail's if assertion is false */
                                require (value2 > value3);


                                /* drop out of test block if true */
                                accept (value1 == value3);


                                if (value2 > 0)
                                        accept (value3 == 0);
                                else
                                        require (value1 != value2);
                        }


                        /* accepted input; everything is in range so DO IT! */
                        ...


                        return (...);
                }




I'd like to know if there are other models used for exception handling,
and whether any of my other ideas have been tried before. Apart from
the global exception handling, in my naivety they seem fairly easy support
in a compiler.




Regards,
Anthony Naggs
    Software/Electronics Engineer & Computer Virus Researcher
    Email: amn@ubik.demon.co.uk Phone: +44 273 589701
    Paper mail: PO Box 1080, Peacehaven, East Sussex BN10 8PZ Great Britain
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.