previous                   ToC                next

 

2.      Source language

 

The source language for the compiler is mjava, a subset of Java which mainly differs from the standard language in the following points:

· all classes in a program are declared in a single file (linking is not needed)

· multiple inheritance is not supported (interface declarations are not allowed)

· abstract classes are not admitted

· static fields and static methods are not allowed

· overloading is not supported

· basic only flow-of-control statements ( if, if-else and while ) are implemented

· basic input/output operations on the I/O standard devices are performed by invoking the C-like functions printf and scanf.

 

This is an example of mjava source program:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

previous                   ToC                next

/********************************************************************

                        Sample mjava source program

*********************************************************************/

 

public class String{

} //end of class String

 

public class Int{

  int n;

  public Int(int i){

    n = i;

  }

  public int f(){

    return fact(n);

  }

  int fact(int n){

    return n > 2 ? n * fact(n -1) : n;

  }

} //end of class Int

 

public class Test{

  public void main(){

    int n, f;

    Int t;

    n = 0;

    while(n < 1 || n > 16) {

       printf ("Enter an integer greater than 0 and less than 17: ");

       scanf ("%d", &n);

    }

    t = new Int(n);

    f = t.f(); 

    printf("factorial(%d)= %d\n", n, f);

  }

} //end of class Test