Smoola Documentation - gsoosk/SmoolaCompiler GitHub Wiki

Smoola is an object orientend language like Java.

There is a main class in this language which has a main method. This method executes at first.

Codes of this language contained in a file with .sml postfix.

General Structure

A program in Smoola language contains these parts :

  • Main Class
    • main Method
  • Other Classes
    • Variable Declarations
    • Method Declarations

A simple Smoola program be like this :

class Test{
    def main(): int{
        writeln((​new​ BabyTest()).testMethod(​1​,​2​));
        ​return​ 0;
    }
}

class​ ​BabyTest​{
​    var​ test1: ​int​[];
    ​var​ test2: boolean;
​    def ​testMethod​(f1: ​int​, f2: ​int​) : ​int​{
​​    ​    var​ i: ​int​;
​    ​    i = ​0​;
​    ​    test1 = ​new​ ​int​[​10​];
​​    ​    while​(i <> ​10​){ 
​    ​    ​    test1[i] = i;
        }
​​    ​    if​(test1[​1​] == ​1​) then
​    ​    ​    test2 = ​true​; 
​    ​    ​else​ {
​    ​    ​    test2 = ​false​; 
​    ​    } ​
​    ​    return​ test2; 
​    }
}

Syntactic Rules

  • This language is case sensetive.
  • tab and space doesn't change​ the ​output of the ​program.

Comment

Comment in this language implement by # character. like python.

class​ ​Test​{  
	​def​ ​main​(): int{
		writeln((new Class1()).testMethod(​“hi there!”​));
		return​ 0;  
		# This is a comment!
	}
}

Rules For Naming Classes, Variables and Methods

All Classes, Variables and Methods name should follow these rules :

  • Just contains of A...Z,a...z,_,0...9 characters.
  • Doesn't start with 0...9.
  • Doesn't similar to reserved words

reserved words are :

boolean string int class def
then if writeln extends var
this false true while else
new return
  • Name of every class is unique .
  • Name of every method in one class, is unique. ( In fact this language does'nt support MethodOverloading)
  • Name of every variable in one scope is unique. This language powered by static scpoing.

Class And Method

  • Main Class has only one main method.
    • Main method has no input argument.
    • Main method returns an int.
    • There is no variable initialization in the ma​in method.
  • Main Class is first class in the program.
  • Main Class doesn't extend​ other class.
  • Each Class can extend​ only one other class using extends keyword and using its parrent methods and fields.

  • Other Classes can have one or many methods and varaiables.
  • Variable declarations position is at first of a class and first of a method.
  • There is no overriding for methods of a Class.
  • Every method should have return value and last instruction should be return
def​ ​method​(arg1: int, arg2: boolean): int{ 
	# body
	return 1;
}

  • Method call is an Expression not a Statement
  • Method call in one line just in main is acceptable .

For making a new instance of a Class we use new word :

var instance : ClassName;
instance = new ClassName();

NOTE : All of non-preemptive variables are Object like Java.


class​ ​MainClass​{​
	def​ ​main​(): int {
		return​ ​new Test2().method2()​;
	}
}  

class​ ​Test1​{
	var​ i: int;  
	def​ ​method1​(): string{
		var​ j: string;  
		j = ​"hello world!"​;
		return​ j;
	}
}

class​ ​Test2​ ​extends​ ​Test1​{
	def​ ​method2​(): int{
		i = ​10​;
		return​ i;
	}
}

Types

Smoola has three premptive type :

  • int
  • string
  • boolean

Each variable could be as type of other classes.

In Smoola we have an array type int[]. It's one dimensional and type of int.

Variables

variable declaration is like :

var​ identifier: ​type​;
  • In Smoola we can't declare multiple variables in one line.

If there was no default value all variables seted to these default values :

int 0
boolean false
string ""

NOTE : Class and Array does not have initial value.


After declaration of an Array we should set its length.

variable = ​new​ ​int​[​10​]; 
variable = ​new​ ClassName();

Array length should not bee 0 or negative.

Operators

There is 4 types of operators in Smoola.

Calculating Operators

All of these operators used on numbers. If we assume A=20 and B=10 we have something like this :

Example Description Associative Operator
A + B = 30 Add Left +
A - B = 10 Sub Left -
A * B = 200 Mult Left -
A/B = 2 B/A = 0 Div Left /
-A=-20 Minus Right -

Comparison Operators

These operators compare two value and their output is true or false

Example Description Associative Operator
(A == B) = false Equal Left ==
(A <> B) = true Not Equal Left <>
(A < B) = false Less Than Left <
(A > B) = true Greater Than Left >

Logical Operators

Logical operators just can applied on Boolean values.

Example Description Associative Operator
(A && B) = false Logical And Left &&
(A || B) = true Logical Or Left ||
(!A) = false Logical Not Right !

Assign Operator