// This program demonstrates what it might mean to solve the Halting
// Problem, by showing how a halting detector could be called on the
// text of methods. This halting detector takes the text of a parameterless
// method as its parameter, and returns true if that method eventually
// returns, false if it doesn't.

class HaltingDemo {


    // The main program, demonstrates how the halting detector is used:
        
    public static void main( String args[] ) {

/*
		HaltingDetector detector = new HaltingDetector();

        final String sampleMethod = "public static void simple () { while ( true ); }";

        if ( detector.runsForever( sampleMethod ) ) {
            System.out.println( "Horrors! '" + sampleMethod + "' never returns!" );
        }
        else {
            System.out.println( "'" + sampleMethod + "' will always return." );
        }
        */
        
        paradox();
        System.out.println( "paradox finished" );
    }




    // A particularly interesting method to test the halting detector on:

    private static String paradoxText =
    	"public static void paradox () { HaltingDetector d = new HaltingDetector(); if ( d.runsForever(paradoxText) ) {	} else { while (true); }}";

    public static void paradox () {
        HaltingDetector d = new HaltingDetector();
        if ( d.runsForever(paradoxText) ) {
        }
        else {
            while ( true );
        }
    }
        
}