User Tools

Site Tools


cc17:eminijava

This is an old revision of the document!


Extended MiniJava (E-MiniJava)

MiniJava is a subset of the programming language Java as described in the Appendix of the Tiger book. Extended MiniJava (E-MiniJava) is an extension to MiniJava that we use in this course. Each group will gradually develop a compiler through implementing different phases of the compiler step by step.

General Overview

  • Object oriented. It supports classes with inheritance and method overriding (but not overloading).
  • Imperative. All class fields and local variables are mutable. While-loop and conditional statement are the main control structure.
  • It supports the following types: Ints, Booleans, Strings, Int arrays and reference types (classes).
  • All classes in a E-MiniJava program are included in a single source file.

BNF

The syntax of Tool is given by the following BNF grammar:

Program::=MainClass ( ClassDeclaration )* <EOF>
MainClass::=class Identifier { public static void main ( String [ ] Identifier ) { Statement } }
ClassDeclaration::=class Identifier ( extends Identifier )? { ( VarDeclaration )* ( MethodDeclaration )* }
VarDeclaration::=Type Identifier ;
MethodDeclaration::=public Type Identifier ( ( Type Identifier ( , Type Identifier )* )? ) { ( VarDeclaration )* ( Statement )* return Expression ; }
Type::=Int
Bool
String
Int [ ]
Identifier
Statement::={ ( Statement )* }
if ( Expression ) Statement ( else Statement )?
while ( Expression ) Statement
System.out.println ( Expression ) ;
Identifier = Expression ;
Identifier [ Expression ] = Expression ;
sidef ( Expression ) ;
Expression::=Expression ( && | || | == | < | + | - | * | / ) Expression
Expression [ Expression ]
Expression . length
Expression . Identifier ( ( Expression ( , Expression )* )? )
<INTEGER_LITERAL>
" <STRING_LITERAL> "
true
false
Identifier
this
new Int [ Expression ]
new Identifier ( )
! Expression
( Expression )
Identifier::=<IDENTIFIER>
  • <IDENTIFIER> represents a sequence of letters, digits and underscores, starting with a letter. An identifier is not a keyword. Identifiers are case-sensitive.
  • <INTEGER_LITERAL> represents a sequence of digits
  • <STRING_LITERAL> represents a sequence of arbitrary characters, except new lines and ". You don't need to support escape characters such as \n.
  • <EOF> represents the special end-of-file character

Language Semantics

The precise way to describe the semantics of a programming language is by using mathematical description, for example operational semantics (see e.g. Lecture 3 of PLC course). Since studying semantics is not officially part of the Compiler Construction course and some students may not have the background knowledge for mathematical semantics, we give an informal description of some of the language constructs.

cc17/eminijava.1486073726.txt.gz · Last modified: 2017/02/02 17:15 by hossein