Program ::= MainClassDecl {ClassDecl} MainClassDecl ::= "class" ID "{" "public" "static" "void" "main" "(" "String" "[" "]" ID ")" "{" {Stmt} "}" "}" ClassDecl ::= "class" ID ["extends" ID] "{" {ClassVarDecl} {MethodDecl} "}" ClassVarDecl ::= Type ID ";" MethodDecl ::= "public" Type ID "(" [Formal {"," Formal}] ")" "{" {Stmt} "return" Expr ";" "}" Formal ::= Type ID Type ::= BaseType | ID BaseType ::= "int" | "boolean" Stmt ::= Type ID "=" Expr ";" | "{" {Stmt} "}" | "if" "(" Expr ")" Stmt "else" Stmt | "while" "(" Expr ")" Stmt | "System.out.println" "(" Expr ")" ";" | ID "=" Expr ";" Expr ::= Expr BinOp Expr | UnOp Expr | Expr "." ID "(" [Expr {"," Expr}] ")" | "new" ID "(" ")" | ID | "this" | Integer | "null" | "true" | "false" | "(" Expr ")" BinOp ::= "+" | "-" | "*" | "/" | "<" | "<=" | ">=" | ">" | "==" | "!=" | "&&" UnOp ::= "-" | "!" ID is an identifier terminal symbol Integer is an integer literal constant terminal symbol