The use of our application is accessible by invoking the Makefile in the orth directory by the make command. This will compile the necessary files generating the orth executable, it then executes the test.exp file present in the directory using the orth executable generating the corresponding test.s. It is also possible to test an entire test suite present in the ./tests/ directory using Python3's script test.py.
.
├── orth // Ficheiros src
| ├── orth
| ├── test.exp
| ├── test.s
| ├── Makefile
| └── ...
├── tests
| ├── bad // Bad tests (<name>.exp)
| ├── good // Good tests (<name>.exp)
| ├── compiled // Ficheiros de compilação
| │ ├── bad // Bad tests (<name>.s / <name>.out)
| │ └── good // Good tests (<name>.s / <name>.out)
| ├── results // Ficheiros de Output (good_<name>.out / bad_<name>.out)
| └── solutions // Soluções (good_<name>.out / bad_<name>.out)
├── test.py
└── ...To add a test to the test battery, the following steps are required:
-
Add an
*.expfile in the directory:./tests/bad/- if the test is supposed to fail;./tests/good/- if the test is supposed to pass;
-
Add a
good_*.outorbad_*.outfile (respectively to the previous step) in the./tests/solutionsdirectory. -
Run in the
.directory the command:python3 test.py
-
Use of the Stack: Because Orth is a stack-based language, it uses a stack to store values temporarily during program execution.
4 2 +In the previous program, the values
4and2are stacked on the stack, then a+operation is performed. On execution, both values are taken from the stack and added together, resulting in the value6stacked on the stack.
-
Manipulating the Stack: You can manipulate the stack using the following commands:
dup- duplicates the element at the top of the stack. Example:2 1 dup Stack -> 2 1 1swap- swaps two elements on top of the stack. Example:2 1 swap Stack -> 1 2drop- deletes the element on top of the stack. Example:2 1 drop Stack -> 2over- copies the element at the bottom of the stack to the top of the stack. Example:2 1 over Stack -> 2 1 2rot- rotation of the three elements on top of the stack. Example:1 2 3 rot Stack -> 3 1 2
- Variable Assignment:
Where
1 x letxis an identifier and1is an example expression.
- Access variables:
Where
x @xis an identifier. The value of the variable is added to the top of the stack.
- While cicle:
Where
0 while dup 10 < in dup printi 1 + end dropdup 10 <represents the Boolean expression delimiting the number of iterations in which the body occurs. The body isdup printiand1 +. After the while execution, it is necessary to usedropto empty the stack in order to exit the program.
- If then else:
Here
true if 1 1 + printi else 2 3 + printi end true if 1 1 + printi endtruerepresents the Boolean condition for deciding which body is executed. The true case body is1 1 + printi, while the false case is2 3 + printi. It is also possible to exclude the use ofelse. Note: The stack of types before and after the execution ofifmust be the same.
- Define function:
where
foo proc 1 printi end foo ?foois an identifier and1 printiis an example expression. When the identifierfoois used with?the identifier procedurefoois called whose output is the value1. Note: The stack of types before and after the execution ofprocmust be the same.