User Tools

Site Tools


cc17:eminijava

This is an old revision of the document!


A PCRE internal error occured. This might be caused by a faulty plugin

====== Extended MiniJava (E-MiniJava) ====== [[http://www.cambridge.org/resources/052182060X/|MiniJava]] is a subset of the programming language Java as described in the Appendix of the [[http://www.cs.princeton.edu/~appel/modern/|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** | | | |**boolean** | | | |**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. [[plc16:lecture_3|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. ==== + ==== The ''+'' operator can be applied to both ''int'' and ''String'' operands. When ''+'' is applied to integers, the result is always integer. When at least one operand is String, the result is the concatenation of operands. For concatenation of an ''int'' to ''String'' the string representation of the integer operand is considered. 5 + 5 => 10 "comp" + "iler" => "compiler" "comp" + 5 => "comp5" 5 + "comp" => "5comp" ==== < , - , * , / ==== These are the usual arithmetic operators and are applied to ''int'' operands only. ==== == ==== Equality works on all pairs of operands that * either both belong to class types (even different ones), or * are of the same type (''int'', ''String'', ''boolean'', ''int[]''). The semantics of equality is * **value-equality** for ''int'', ''boolean'' and ''string'' * **reference-equality** for objects and arrays 10 == 10 => true new A() == new A() => false new A() == new B() => false "comp" == 10 => // Type Error... "c" + "omp" == "co" + "mp" => true ==== println ==== **System.out.println** can be used on ''int'', ''Strings'' and ''Booleans''.

cc17/eminijava.1486081685.txt.gz · Last modified: 2017/02/02 19:28 by hossein