Mapl grammar ( N* denotes 0, 1 or more repetitions of N )
Program MethodDecl
ProcDecl FunDecl FormalList
FormalRest Type
Statement
Block Exp
PrimaryExp
Var ExpList
® ProcDecl MethodDecl*
® ProcDecl
® FunDecl
® proc id ( FormalList ) { Statement* }
® fun Type id ( FormalList ) { Statement* return Exp ; } ® Type id FormalRest*
®
® , Type id
® Type [ ]
® boolean
® int
® Block
® local Type id ;
® Var = Exp ;
® PrimaryExp [ Exp ] = Exp ;
® if ( Exp ) then Statement else Statetment ® while ( Exp ) do Statement
® output Exp ;
® outchar Exp ;
® id ( ExpList ) ;
® { Statement* }
® PrimaryExp op PrimaryExp
® PrimaryExp [ Exp ]
® PrimaryExp . length
® PrimaryExp
® INTEGER_LITERAL
® true
® false
® Var
® new Type [ Exp ]
® id ( ExpList )
® ! PrimaryExp
® isnull PrimaryExp
® ( Exp )
® id
® Exp ExpRest*
®
® , Exp
ExpRest
See overleaf for definitions of op, id, INTEGER_LITERAL and the comment syntax.
1
op is one of the following binary operators: and < == div + - * id is a sequence of letters, digits and underscores, starting with a letter. INTEGER_LITERAL is a sequence of decimal digits. [Note that this means that negative numbers are not integer literals.] Comments: these can either be placed between /* and */ or make up the remainder of a line beginning with // 2