Cambridge
Account MaintenanceSearchView basketOrdering Help


next
up previous
Next: Sample Program Up: MiniJava Language Reference Manual Previous: Lexical Issues

Grammar

In the MiniJava grammar, we use the notation N $^{\textstyle *}$, where N is a nonterminal, to mean 0, 1, or more repetitions of N.

Program $\!\!\!\!\rightarrow\!\!\!\!$ MainClass ClassDecl $^{\textstyle *}$
MainClass $\!\!\!\!\rightarrow\!\!\!\!$ class id { public static void main ( String [] id )
         { Statement } }
ClassDecl $\!\!\!\!\rightarrow\!\!\!\!$ class id { VarDecl $^{\textstyle *}$ MethodDecl $^{\textstyle *}$ }
  $\!\!\!\!\rightarrow\!\!\!\!$ class id extends id { VarDecl $^{\textstyle *}$ MethodDecl $^{\textstyle *}$ }
VarDecl $\!\!\!\!\rightarrow\!\!\!\!$ Type id ;
MethodDecl $\!\!\!\!\rightarrow\!\!\!\!$ public Type id ( FormalList )
         { VarDecl $^{\textstyle *}$ Statement $^{\textstyle *}$ return Exp ; }
FormalList $\!\!\!\!\rightarrow\!\!\!\!$ Type id FormalRest $^{\textstyle *}$
  $\!\!\!\!\rightarrow\!\!\!\!$  
FormalRest $\!\!\!\!\rightarrow\!\!\!\!$ , Type id
Type $\!\!\!\!\rightarrow\!\!\!\!$ int []
  $\!\!\!\!\rightarrow\!\!\!\!$ boolean
  $\!\!\!\!\rightarrow\!\!\!\!$ int
  $\!\!\!\!\rightarrow\!\!\!\!$ id
Statement $\!\!\!\!\rightarrow\!\!\!\!$ { Statement $^{\textstyle *}$ }
  $\!\!\!\!\rightarrow\!\!\!\!$ if ( Exp ) Statement else Statement
  $\!\!\!\!\rightarrow\!\!\!\!$ while ( Exp ) Statement
  $\!\!\!\!\rightarrow\!\!\!\!$ System.out.println ( Exp ) ;
  $\!\!\!\!\rightarrow\!\!\!\!$ id = Exp ;
  $\!\!\!\!\rightarrow\!\!\!\!$ id [ Exp ] = Exp ;
Exp $\!\!\!\!\rightarrow\!\!\!\!$ Exp op Exp
  $\!\!\!\!\rightarrow\!\!\!\!$ Exp [ Exp ]
  $\!\!\!\!\rightarrow\!\!\!\!$ Exp . length
  $\!\!\!\!\rightarrow\!\!\!\!$ Exp . id ( ExpList )
  $\!\!\!\!\rightarrow\!\!\!\!$ INTEGER_LITERAL
  $\!\!\!\!\rightarrow\!\!\!\!$ true
  $\!\!\!\!\rightarrow\!\!\!\!$ false
  $\!\!\!\!\rightarrow\!\!\!\!$ id
  $\!\!\!\!\rightarrow\!\!\!\!$ this
  $\!\!\!\!\rightarrow\!\!\!\!$ new int [ Exp ]
  $\!\!\!\!\rightarrow\!\!\!\!$ new id ( )
  $\!\!\!\!\rightarrow\!\!\!\!$ ! Exp
  $\!\!\!\!\rightarrow\!\!\!\!$ ( Exp )
ExpList $\!\!\!\!\rightarrow\!\!\!\!$ Exp ExpRest $^{\textstyle *}$
  $\!\!\!\!\rightarrow\!\!\!\!$  
ExpRest $\!\!\!\!\rightarrow\!\!\!\!$ , Exp


next up previous
Next: Sample Program Up: MiniJava Language Reference Manual Previous: Lexical Issues
Vidyut Ashim Samanta 2002-06-05

© 2002 Cambridge University Press