MicroCosmo is tiny language made for educational purposes. It compiles into CIL and can run under CLR platform.
This repo contains:
- Backend (compiler) for CIL
- Intermediate representation interpreter
- Specification and basic documentation of a language
MicroCosmo is a strongly, static typed programming language.
Memory management done by CLR's GC.
MicroCosmo allows only single line comments using #
symbol:
# Single line comment
MicroCosmo supports builtin types:
string
- UTF-8 immutable container of symbolsint
- 32-bit integer typebool
- Boolean valuedouble
- 64-bit double-precision floating point typeany
- special type, can contain any other type[type] array
- array of some type
Builtin types may be instantiated using literals:
- string:
"str"
,'str2'
- int:
1
,234
,32123
- bool:
true
,false
- double:
1.0
,0.234
,.23
Variable declaration looks like:
let variableName : variableType
Scope of variables is defined inside block statements ({ }
)
Each if
, else
, while
, func
declaration declares also a inner variable scope.
Main variable scope is called "global scope"
MicroCosmo supports several operators on different variable types.
[expression] is [expression]
- equals[expression] is not [expression]
- not equals
number
- double
or int
Binary:
[number] + [number]
- sum[number] - [number]
- difference[number] * [number]
- multiplication[number] / [number]
- division[number] % [number]
- remainder of the division[number] ** [number]
- erection to degree[number] += [number]
- sum and assign new value[number] -= [number]
- difference and assign new value[number] *= [number]
- multiplication and assign new value[number] /= [number]
- division and assign new value[number] %= [number]
- remainder of the division and assign new value[number] **= [number]
- erection to degree and assign new value[number] > [number]
- bigger than[number] < [number]
- less than[number] >= [number]
- bigger than or equals[number] <= [number]
- less than or equals
Unary:
+ [number]
- keep sign- [number]
- change sign
Binary:
[bool] or [bool]
- logical "OR"[bool] and [bool]
- logical "AND"
Unary:
not [bool]
- logical "NOT"
print(a : string)
- prints given string value into screenprintln(a : string)
- prints given string value into screen and adds newline characterreadstr() : string
- gets string from inputreadint() : int
- reads next integer numberreadreal() : double
- reads next double number
MicroCosmo allows to control execution flow using if .. else ..
expression statement:
let someBool : bool
someBool = true
let value : int
if (someBool) {
value = 5
} else {
value = 3
}
Else block is optional:
let a : int
a = readint()
let isFive : bool = a is 5
if (isFive) {
println("4 equals 5")
}
MicroCosmo supports only 1 type of loops - while
:
let i : int
i = 0
while (i < 5) {
printLn(i to string)
i++
}
User can define own functions. All functions have global scope. Functions cannot be defined inside another functions.
If function does not have return value, returnType is not specified.
Functions can return control at any time.
func name(arg1 : type, arg2 : type) : returnType {
# Function body
}
Example:
# Returns true if integer is positive, otherwise false
func sign(value : int) : bool {
return value > 0
}
Programs written in MicroCosmo must have function main
with signature:
func main()
Main function is the entry point for every program.
Example:
func main() {
# ...
}