μJ1 Specification
program → method
method → ident ( identListopt ) { declarationopt statementrep }
identList → ident |
identList , ident |
declaration → var identList ;
statement → assignment |
printStat |
assignment → variable = expression ;
expression → –opt term |
expression + term |
expression – term |
term → factor |
term * factor |
term / factor |
factor → number |
variable |
( expression ) |
variable → ident
printStat → print itemList ; |
println itemListopt ; |
itemList → printItem |
itemList , printItem |
printItem → literal |
expression |
expression : expression |
μJ2 Specification
statement → assignment |
printStat |
readStat |
whileStat |
ifStat |
readStat → read literalopt ,opt variable ;
whileStat → while condition block
ifStat → if condition block elsePartopt
elsePart → else block |
else ifStat |
condition → ( expression relation expression )
block → { } |
{ statementrep } |
μJ3 Specification
program → methodrep
statement → assignment |
printStat |
readStat |
whileStat |
ifStat |
returnStat |
assignment → variable = expression ; |
invocation ; |
factor → number |
variable |
( expression ) |
invocation |
invocation → ident ( exprListopt )
exprList → expression |
exprList , expression |
returnStat → return expressionopt ;
token ident | number | literal | keyword | relation | operator | separator
keyword var | print | println | read | while | if | else | return
relation == != < <= > >=
operator = + - * /
separator ( ) { } , ; :
In-line comments // are skipped in the lexical stage
opt means optional, rep means repeated one or more time