MiniJava is a subset of Java. The meaning of a MiniJava program is
given by its meaning as a Java program. Overloading is not allowed in
MiniJava. The MiniJava statement System.out.println(...);
can only print integers. The MiniJava expression e.length
only applies to expressions of type int[]
.
&& < + - *
In this appendix the symbol op stands for a binary operator.
/*
, ends with */
,
and may be nested; another begins with //
and goes to the
end of the line.
Program -> MainClass ClassDecl* MainClass -> class id { public static void main ( String [] id ) { Statement } } ClassDecl -> class id { VarDecl* MethodDecl* } -> class id extends id { VarDecl* MethodDecl* } VarDecl -> Type id ; MethodDecl -> public Type id ( FormalList ) { VarDecl* Statement* return Exp ; } FormalList -> Type id FormalRest* -> FormalRest -> , Type id Type -> int [] -> boolean -> int -> id Statement -> { Statement* } -> if ( Exp ) Statement else Statement -> while ( Exp ) Statement -> System.out.println ( Exp ) ; -> id = Exp ; -> id [ Exp ] = Exp ; Exp -> Exp op Exp -> Exp [ Exp ] -> Exp . length -> Exp . id ( ExpList ) -> INTEGER_LITERAL -> true -> false -> id -> this -> new int [ Exp ] -> new id ( ) -> ! Exp -> ( Exp ) ExpList -> Exp ExpRest* -> ExpRest -> , Exp
class Factorial { public static void main(String[] a) { System.out.println(new Fac().ComputeFac(10)); } } class Fac { public int ComputeFac(int num) { int num_aux; if (num < 1) num_aux = 1; else num_aux = num * (this.ComputeFac(num - 1)); return num_aux; } }