-
Notifications
You must be signed in to change notification settings - Fork 4
Writing Code in Sigun
- Start-End Program
- Comment Lines
- Print an Output
- Assignment Operator
- Arithmetic Operations
- List
- If-Else Statement
- While Statement
- For Statement
- For Each Statement
- Functions
- Break and Continue
- Reading String and Integer From The User
- Giving Random Variables
- Boolean Expressions
In order to write code in the Sigun programming language, the code block must begin with the word "başla" which means start and then the instructions must be sequenced. Following the completion of the necessary instructions, the code block is ended by using the word "bitir" which means finish in Turkish to signify that the program is complete.
başla
...
bitir
The "***" phrase allows users to place comments between code blocks without any difficulties using comment lines while writing code in the Sigun programming language. By using the three-star symbol specified, one or more lines can be added to the comment line as seen below, according to the user's request.
*** THIS IS
A NOTE ***
In the Sigun programming language, the term "yaz" is used to print an expression, which means the word print in other programming languages that have English syntax. The expression to be printed is provided in parentheses after the "yaz" expression. The sentence is completed with a semicolon once all relevant phrases have been appropriately typed.
yaz("Merhaba Dünya!");
The simplest statement assignment operator in this language uses an indicator for the different data types when initializing. In other words, in the statement a is an Integer as follows:
a = 5;
While in this statement a has a String value when the user writes the assignment operator like this:
a = "5";
The majority of arithmetic operations in programming languages are written in symbols and are largely universal. Because the Sigun language is primarily intended for young people who are unfamiliar with these existing symbols, utilizing words rather than symbols seems much more understandable when learning from scratch.
- bölümünden kalan → %
- veya → ||
- ve → &&
- eşit → ==
- eşit değil → !=
- doğru/yanlış → boolean(True/False)
While "equal" and "not equal" operations have verbal equivalents, they can also have mathematical symbol equivalents. In other words, the following lines are equal to each other.
b == 30;
b eşit 30;
or
b != 30;
b eşit değil 30;
For lists, we used the name "liste". Our lists are able to store more than one type of data and it is dynamic just like python list. This way we are hoping to create a list more like a basket where every type can enter, pop, and be used in different variations of an algorithm. To create a list in the Sigun Programming Language, the keyword "liste" must be written and between the parentheses, the items of that list should be listed as below:
filmler = liste ("Soul", "Sindirella", "Mulan", "Mega Zeka", "Rapunzel", "Moana", "Zootopia", "Arabalar");
If the user would like to create an empty list, it would be enough to just leaving the area between parentheses empty as follows:
deneme = liste ();
Adding new items to lists, deleting elements, specifically reaching an element, reaching the length of the list, updating the list, and emptying the list are all functionalities that could be used in Sigun Programming Language.
First of all, to add an item into the liste users need to write a command that has a structure like "... listesine ... ekle". In the blank spaces, the user should write the name of the list they want to add an item and in the second blank, they need to write the element they would like to add just like in the example below:
*** Adding an element to the list ***
x = "Frozen";
filmler listesine x ekle;
When the user wants to delete a specific item in the list, they need to use the keyword "sil" just like in the example.
*** Removing an item and getting the number of the item in the list ***
silinecek = "Arabalar";
siraNo = filmler listesindeki silinecek elemanının sırası;
filmler listesindeki siraNo. elemanı sil;
To get the length of a previously created list, use the expression "... listesinin uzunluğu" In the blank area in this statement, write the name of the list whose length is to be received.
*** Displaying the length of the list ***
yaz(filmler listesinin uzunluğu);
To entirely clear a previously created and edited list, simply type "temizle" as seen in the example below.
*** Clear the list ***
filmler listesini temizle;
yaz(filmler);
The if in the if-else statement is represented as "Eğer". This word will be written at the beginning of the statement since it does not violate Turkish grammar order and is casually used this way. Then we get the required condition and at the end write "ise" to start the body of the if statement. To add another if statement to the relevant upper one, the use of "ya da" is needed. The same process as after "Eğer" will be used here, and if required to end with an else statement, "değil ise" is used.
eğer (condition) ise
*** if statement body ***
ya da (condition) ise
*** if else statement body ***
değil ise
*** else statement body ***
The if-else statement's overall structure is given above. If a real-world example of this statement is requested, the following code block in the Sigun programming language briefly shows the if-else structure.
yas=21;
eğer (yas>=18) ise {
yaz("Araba ve motosiklet ehliyeti alabilirsiniz");
}
ya da (yas>=16) ise {
yaz("Motosiklet ehliyeti alabilirsiniz");
}
değil ise {
yaz("Hiçbir ehliyet alamazsınız");
};
In order to be compatible with the Turkish language structure, the condition part of the while statement comes first, then the statement. To be able to write a while loop, the users should use "... olduğu sürece" structure and write the condition they would like to use in the blank area in the structure. For example:
*** An example that uses list and while together ***
filmler = liste ("Soul", "Sindirella", "Mulan", "Mega Zeka", "Rapunzel", "Moana", "Zootopia", "Arabalar");
a=1;
(a==1) olduğu sürece{
komut = "ekle";
eğer (komut == "yazdir") ise {
yaz(filmler);
}
ya da (komut == "ekle") ise {
eklenecek = "Frozen";
filmler listesine eklenecek ekle;
yaz(filmler);
}
ya da (komut == "sil") ise{
silinecek = "Soul";
siraNo = filmler listesindeki silinecek elemanının sırası;
filmler listesindeki siraNo. elemanı sil;
yaz(filmler);
}
değil ise {
yaz("geçersiz bir komut girdiniz");
};
};
A normal "for" statement needs three statements to execute:
- The first statement is executed before the execution of the code block and assigns a value to a variable.
- The second statement defines the condition.
- The third and final statement is executed every time after the code block has been executed once. To adjust these to our language, the variable that keeps the counter will be written first, and after that, the word "değişkeni" will be written to keep the order. Then the boundaries will be written and at the end the variable’s situation at the end of each iteration. This situation could either be "artarken" meaning increasing, or "azalırken" meaning decreasing.
toplam=0;
x değişkeni 1 ile 10 arasında 1 artarken {
toplam = toplam + x;
};
yaz("1'den 10'a kadar olan sayıların toplamı:");
yaz(toplam);
To be able to write a code that uses for-each in it, the structure should be like this: "... içindeki her ... değeri için" then the for-each statement body should be written. The user should provide the name of the list they want to loop over in the first space. In order to better understand the use of for-each, the following sample code can be examined.
L = liste (3,7,40,5,2,4,3,77);
toplam = 0;
L içindeki her i değeri için{
yaz(i);
toplam=toplam+i;
};
yaz(toplam);
The usage of the term "işi" is the most significant element when creating a function in the Sigun programming language. The following is the general structure used during function definition: "... ile ... işi". After using the structure, the function body should be implemented. Considering the function definition structure, it is necessary to sort the parameters that will be assigned a value to the first space later by separating them with commas. The function name must be placed in the second space, which is in the field right before the "işi" keyword, so that it may be called afterwards.
a, b ile topla işi{
topla = a + b;
yaz(topla);
}
3,4 ile topla;
The "topla" function is defined in the sample code above, and it makes summation and prints the arguments a and b. Thanks to the numbers written after and the function name following the numbers, the numbers are placed in the place of the parameters in the "topla" function and a result is obtained according to it. Except for the example above, there is more than one way to define a function in the Sigun programming language. There is also a structure as follows, in which the function's result can be called and returned by using the "çağır" keyword while calling the function after defining it.
a ile karesini_bul işi {
sonuc = a*a;
sonuc döndür;
};
kare = çağır 4 ile karesini_bul;
yaz(kare);
The "kır" statement is used to stop loops (for, while) statements, in other words, "kır" keyword means break in Sigun Programming Language. The "kır" statement within a loop terminates the loop completely when a certain condition is met and exits the loop. Thus, the rest of the loop is skipped and the program continues after the loop. The "kır" statement is useful for quickly ending a loop or performing a search in a loop when it meets a certain condition.
The "atla" statement which means continue in Sigun, is used to stop the loop at the current iteration and continue to other conditions of the loop. When the "atla" statement satisfies a certain condition, it skips the current iteration and moves on to the next iteration of the loop. The expression "atla" is useful when omitting a certain condition or neglecting some condition.
g değişkeni 20 ile 40 arasında 5 artarken {
eğer (g==20) ise {
yaz("irem");
atla;
}
ya da (g == 25) ise {
yaz(g);
kır;
}
ya da (g == 30) ise {
yaz(g);
yaz("kirilmadi");
};
};
The system in Sigun Programming Language is capable of collecting a string or an integer from the user. To get a string, use the "kelimeyi oku" phrase, whereas to get an integer, use the "sayıyı oku" term. For example:
yaz("Lütfen bir kelime veriniz, sizin için onu yazdıracağım: ");
yaz(kelimeyi oku);
yaz("Lütfen bir sayı veriniz, sizin için onu yazdıracağım: ");
yaz(sayıyı oku)
At the same time, users can assign the words or numbers they provided to variables and then utilise these variables in various operations as follows:
yaz("Kelime giriniz: ");
kelime = kelimeyi oku;
yaz(kelime);
yaz("Sayı değeri giriniz: ");
sayı = sayıyı oku;
yaz("Şimdi sayınız yazdırılacak");
yaz(sayı);
yaz(10+sayı);
The language Sigun incorporates a random function called "rastgele" that serves two purposes. The first use of the random function involves generating a random integer from a specified range. This is achieved by providing two numerical arguments within the parentheses, separated by a comma.
sifre = rastgele(2,10);
yaz("Şifre 2 ile 10 arasında bir sayı. Tahmin et: ");
tahmin = sayıyı oku;
eğer(tahmin == sifre) ise {
yaz("Doğru tahmin!");
}
değil ise {
yaz("Yanlış tahmin :(");
};
In the second usage of the random function, the function takes a list as input and returns a random object from that list. This random element from the list gets assigned to the variable.
list = liste(1,2,3,4, "aaa", "bbb", "ccc");
int = rastgele(list);
yaz(int);
A variable in the Sigun Programming Language should be specified as "doğru" if it is true, and "yanlış" if it is false, as mentioned above in the Assignment Operator. Following that, these variables may be utilised in expressions like if-else or for.
a=doğru;
c=doğru;
yaz(a);
eğer (a eşit doğru) ise{
yaz("a doğru");
};
eğer(a == yanlış) ise{
yaz("a yanlış");
};
eğer(a == c) ise{
yaz("a'c 'ye eşittir");
};
b=yanlış;
yaz(b);
eğer (b == doğru) ise{
yaz("b yanlış, not b doğru ");
};