Previous    Next

GRAMMAR

In the MiniJava grammar, we use the notation N*, where N is a nonterminal, to mean 0, 1, or more repetitions of N.

GRAMMAR A.2
 ProgramMainClass ClassDecl*
 MainClassclass id { public static void main ( String [] id )
 { Statement }}
 ClassDeclclass id { VarDecl* MethodDecl* }
 → class id extends id { VarDecl* MethodDecl* }
 VarDeclType id ;
MethodDeclpublic Type id ( FormalList )
 { VarDecl* Statement* return Exp ;}
FormalListType id FormalRest*
 →
FormalRest →, Type id
 Typeint []
 → booleanintid
 Statement → { Statement* }
 → if ( Exp ) Statement else Statementwhile ( Exp ) StatementSystem.out.println ( Exp ) ;
 → id = Exp ;
 → id [ Exp ]= Exp ;
 ExpExp op ExpExp [ Exp ]
 → Exp . lengthExp . id ( ExpList )
 → INTEGER LITERALtruefalseidthisnew int [ Exp ]
 → new id ()
 → ! Exp
 → ( Exp )
 ExpListExp ExpRest*
 →
 ExpRest → ,Exp



Java End example

JaVaScreenshot Previous    Next
Comments