Next:
Sample Program
Up:
MiniJava Language Reference Manual
Previous:
Lexical Issues
Grammar
In the MiniJava grammar, we use the notation
N
, where
N
is a nonterminal, to mean 0, 1, or more repetitions of
N
.
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
Next:
Sample Program
Up:
MiniJava Language Reference Manual
Previous:
Lexical Issues
Vidyut Ashim Samanta 2002-06-05
©
2002 Cambridge University Press