Shijak is a general-purpose programming language designed with a focus on structured programming.
The Shijak compiler takes source code written in Shijak and translates it into MIPS assembly code.
To test it, you can use the online-compiler
- int
- float
- char
- bool
- arrays
- bags (user-defined structures)
Variables must be declared before use:
let identifier: TYPE;
fun main(): void {
let i: int;
let f: float;
let c: char;
let b: bool;
5 >> eq i;
5.5 >> eq f;
'b' >> eq c;
true >> eq b;
output i;
}
fun main(): void {
let arr: int[];
alloc int[3] >> arr;
1 >> eq arr[0];
2 >> eq arr[1];
3 >> eq arr[2];
free arr;
}
bag person {
age: int,
name: char[]
}
fun main(): void {
let shijak: bag person;
fill bag person >> shijak;
alloc char[6] >> shijak.name;
'S' >> eq shijak.name[0];
'h' >> eq shijak.name[1];
'i' >> eq shijak.name[2];
'j' >> eq shijak.name[3];
'a' >> eq shijak.name[4];
'k' >> eq shijak.name[5];
25 >> eq shijak.age;
free shijak.name;
free shijak;
}
!(logical NOT)*,/,&&+,-,||%- Comparison:
>,<,>=,<=,==,!= >>(chaining operator)
The >> operator passes the result of the left expression into the right expression via the keyword in.
fun main(): void {
let rez: int;
5 + 10 >> in * 2 >> in / 3 >> eq rez;
output rez;
}
5.5 >> eq num;
fun add(num1: int, num2: int): int {
num1 + num2 >> return;
}
alloc int[10] >> arr;
fill bag person >> shijak;
Shijak supports the following statements:
- Variable declaration:
let - Conditional statements:
if,elif,else - Loops:
while - Loop control:
break,continue - Input / Output:
input,output - Memory management:
alloc,free - Return statement:
return - Bag initialization:
fill
fun main(): void {
let num: int;
input num;
if (num < 0) {
output -1;
} elif (num == 0) {
output 0;
} else {
output 1;
}
}
fun main(): void {
let num: int;
input num;
while (num >= 0) {
num - 1 >> eq num;
}
}
Functions support recursion and typed parameters.
fun addNumbersInArray(arr: int[], len: int): int {
if (len == 0) {
0 >> return;
}
addNumbersInArray(arr, len - 1)
>> in + arr[len - 1]
>> return;
}
fun main(): void {
let arr: int[];
alloc int[3] >> arr;
1 >> eq arr[0];
5 >> eq arr[1];
3 >> eq arr[2];
output addNumbersInArray(arr, 3);
}
fun main(): void {
let num: int;
input num;
output num;
}
Additional examples are available in the examples folder located in the root directory of the project.
- The logical NOT operator (!) may behave inconsistently.
- Mixed-type arithmetic is not symmetric:
int + float → floatfloat + int → int- Parentheses are required when using logical operators:
(5 > 4) && (5 < 6)
- Fix known issues
- Improve type consistency
- Add support for strings
The current stable implementation of the compiler is located in:
package com.company.old
A newer version, currently under development and based on object-oriented design principles, can be found in:
package com.company.compiler