Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
/ set Public archive

Set is an imperative programming language with focus on teaching mathematics, therefore, it is aimed at teachers and students. The language handles sets as one of the primitive types.

License

Notifications You must be signed in to change notification settings

brenomfviana/set

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Description

Set is an imperative programming language with focus on teaching mathematics, therefore, it is aimed at teachers and students. The language handles sets as one of the primitive types.

About the interpreter

The interpreter of the set programming language was a homework of the Concepts and Paradigms Programming Language course of the Federal University of Rio Grande do Norte (UFRN). The interpreter was developed using the Haskell language. We used Alex to generate the Haskell lexical analyzer for our language and we used the Parsec library to implement the parser and the interpreter.

Note: One of the language's basic primitive type was not implemented due to time issues.

Compiling

To compile the interpreter use the make.sh file.

./make

Running a program

To run a set program use the following command:

./set <file-name>

Requirements implemented

  • Primitive types
  • Array type
  • If statement
  • While statement
  • Break statement
  • Continue statement
  • Print
  • User input
  • Set type
  • Matrix type
  • Pointer type
  • User types
  • Function
  • Procedure

Learning

A set program has the following structure:

program <program-name>
    <statements>
end <program-name>

Hello World in set:

program helloworld
    print("Hello World!");
end helloworld

Comments:

program helloworld
    # Comments
    print("Hello World!");
end helloworld

Primitive Data types:

Natural
Nat : x := 1;
Integer
Int : x := 1;
Int : y := -1;
Real
Real : x := 1.0;
Real : y := -1.0;
Bool
Bool : x := true;
Bool : y := false;
Text
Text : x := "Hello world";
Array
# Array[Type,Size] : x;
Array[Nat,3] : x;
x[0] := 1;
x[1] := 2;
x[2] := 3;
print("{x[0]=" + x[0] + ",x[1]=" + x[1] + ",x[2]=" + x[2] + "}");
Coercion
Types Coercion
Nat Int, Real, Text
Int Real, Text
Real Text
Bool Text
Text -
Array Text

Expressions:

Arithmetic operations
  1. Sum:

     program sum
         Nat : x := 1;
         Int : y;
         y := 1;
         Int sum := x + y; # Result: 2
         print(sum);
     end sum
    
  2. Subtraction:

     program subtraction
         Nat : x := 1;
         Int : y := 1;
         print(x - y); # Result: 0
     end subtraction
    
  3. Multiplication:

     program multiplication
         Real : x := 5.0;
         Int : y := 2;
         print(x * y); # Result: 10.0
     end multiplication
    
  4. Division:

     program division
         Real : x := 10.0;
         Int : y := 2;
         print(x / y); # Result: 5.0
     end division
    
Boolean operations
  1. Equality

     program equality
         print(2 == 2); # Result: True
         print(2 == 1); # Result: False
     end equality
    
  2. Conjunction

     program conjunction
         print((1 == 1) && (2 == 2)); # Result: True
         print((1 == 1) && (2 == 1)); # Result: False
         print((2 == 1) && (1 == 1)); # Result: False
         print((2 == 1) && (2 == 1)); # Result: False
     end conjunction
    
  3. Disjunction

     program disjunction
         print((1 == 1) || (2 == 2)); # Result: True
         print((1 == 1) || (2 == 1)); # Result: True
         print((2 == 1) || (1 == 1)); # Result: True
         print((2 == 1) || (2 == 1)); # Result: False
     end disjunction
    
  4. Greater than

     program greaterthan
         print(2 > 1); # Result: True
         print(1 > 2); # Result: False
         print(1 > 1); # Result: False
     end greaterthan
    
  5. Smaller than

     program smallerthan
         print(2 < 1); # Result: False
         print(1 < 2); # Result: True
         print(1 < 1); # Result: False
     end smallerthan
    
  6. Greater than or equal to

    program greaterthanorequal
        print(2 >= 1); # Result: True
        print(1 >= 2); # Result: False
        print(1 >= 1); # Result: True
    end greaterthanorequal
    
  7. Smaller than or equal to

    program smallerthanorequal
        print(2 <= 1); # Result: False
        print(1 <= 2); # Result: True
        print(1 <= 1); # Result: True
    end smallerthanorequal
    
String manipulation operations
  1. Concatenation:

    program concat
        Real : x := 2.0;
        Real : y := 2.0;
        Text : s := "of the sum:";
        print("Result " + s + (x + y)); # Result: "Result of the sum: 4.0"
    end concat
    

Condition structure

The only condition structure is the if-elseif-else:

program conditionstructure
    if (1 > 2)
        print("Something wrong.");
    elseif (2 > 1)
        print("OK.");
    else
        print("Something wrong.");
    endif
end conditionstructure

Repetition structure

The only repetition structure is the while:

program repetitionstructure
    Nat : count := 0;
    while(count < 10)
        count := count + 1;
        print(count);
    endwhile
end repetitionstructure

Input and Output

program inputoutput
    Text : t;
    input(t); # Get user input
    print(t); # Print user input
program inputoutput

Team

Breno Viana Felipe Barbalho Patrícia Cruz Raul Silveira Jackson Rauup

About

Set is an imperative programming language with focus on teaching mathematics, therefore, it is aimed at teachers and students. The language handles sets as one of the primitive types.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •