Skip to content

Writing Code in Sigun

Irem Hatipoglu edited this page Jun 7, 2023 · 9 revisions

Contents

  1. Start-End Program
  2. Comment Lines
  3. Print an Output
  4. Assignment Operator
  5. Arithmetic Operations
  6. List
  7. If-Else Statement
  8. While Statement
  9. For Statement
  10. For Each Statement
  11. Functions
  12. Break and Continue
  13. Reading String and Integer From The User
  14. Giving Random Variables
  15. Boolean Expressions

Start and End Program

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

Comment Lines

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 ***

Print an Output

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("Hello World!");

Assignment Operator

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";

Operations

Most programming language's arithmetic operations are written in symbols, and they are mostly universal. When someone write "&&", it is known as an "and" operation. Since our language is mostly for children that are unaware of these established symbols, using words instead of symbols seemed much more understandable when learning from scratch. However, we did not change some operators since these operators are used in mathematical operations as well and easy to understand. The operators we use while creating the structure of the Turkish programming language are as follows.

  • Arithmetic Operators: The fundamental symbols employed in mathematical operations are known as arithmetic operators. These operators enable mathematical operations to be carried out between user-supplied or preset data.
                +                  //   Addition
                -                  //   Subtraction
                *                  //   Multiplication
                /                  //   Division
                bölümünden kalan   //   %
  • Logical Operators: Logical comparisons are made using logical operators.
                veya               //   ||  
                ve                 //   &&
                !                  //   Not
                doğru              //   True
                yanlış             //   False
  • Comparison Operators: To compare two variables against one another, comparison operators are utilized. With the help of these operators, condition statements for flow diagrams can be created.
                <                  //   Less Than
                <=                 //   Less Than Equal
                >                  //   Greater Than
                >=                 //   Greater Than Equal
                eşit               //   ==
                eşit değil         //   !=

While "equal" and "not equal" operations have verbal equivalents, they can also have mathematical symbol equivalents. Our programming language is suitable for both uses. 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;

List

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:

                 a = liste ("Sindirella", 7, 35, 
                            "Rapunzel", false);  

If the user would like to create an empty list, it would be enough to just leaving the area between parentheses empty as follows:

                 a = 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:
                x = "Frozen";
                a listesine x ekle;
  • When the user wants to delete a specific item in the list, they need to use the structure like "... listesindeki ... elemanı sil". In the blank spaces, the user should write the name of the list they want to delete an item and in the second blank, they need to write the element they would like to delete just like in the example below:
               a listesindeki "Rapunzel" 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(a listesinin uzunluğu);
  • To entirely clear a previously created and edited list, simply type "... listesini temizle" as seen in the example below.
             // Clear and display the list 
             a listesini temizle;
             yaz(a);

If-Else Statement

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
                };

While Statement

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.

               (condition) olduğu sürece {
                  // While statement body
               };

For Statement

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.
               i değişkeni 1 ile 10 arasında 3 artarken {
                  // For statement body
               };

For Each Statement

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.

                a içindeki her i değeri için {
                   // For-Each statement body
                };

Functions

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.

               [parameters] ile [function name] işi {
                  // Function body 
               };

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. The example is as follows;

               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. The example is as follows;

             a, b ile topla işi{
             topla = a + b;
             topla döndür;
             };
             sonuç = çağır 3,4 ile topla;
             yaz(sonuç);

Break and Continue

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.

             //Break statement
             kır;

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.

             //Continue statement
             atla;

The example below illustrates how "kır" and "atla" are used in the loop. In this case, we expect that the variable i will skip the current iteration, continue with the loop's subsequent iteration when it equals 30, and end the loop when it equals 50. So, 20 25 35 40 45 should be the result.

             i değişkeni 20 ile 60 arasında 5 artarken {
             eğer (i == 30) ise {
             // If statement body
             atla;
             }
             ya da (i == 50) ise {
             // If else statement body
             kır;
             };
             // For statement body
             yaz(i);
             };

Reading String and Integer From The User

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:

        // For String
        yaz("Please enter a word and I will print it for you: ");
        yaz(kelimeyi oku);
        
        // For Integer
        yaz("Please enter a number and I will print it for you: ");
        yaz(sayıyı oku);

At the same time, users can assign the words or numbers they provided to variables and then utilize these variables in various operations as follows:

         // For String
         yaz("Please enter a word: ");
         s = kelimeyi oku;
         yaz(s);
        
         // For Integer
         yaz("Please enter a number: ");
         i = sayıyı oku;
         yaz(i);

Giving Random Variables

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. The use of the structure is as follows. In the example we expect it to return any number between 1000 and 9999.

        password = rastgele (1000,9999);

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.

       Fruits = liste("Apple", "Pear", "Banana", "Blackberry");
       f = rastgele(Fruits);

Boolean Expression

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 Operators. Following that, these variables may be utilized in expressions like if-else or for. The example below shows its usage in a loop.

       a = doğru;
       b = yanlış;

       eğer (a eşit b) ise {
       yaz("a is equal to b");
       }
       değil ise {
       yaz("a is not equal to b");
       };