You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-29Lines changed: 71 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,62 +1,99 @@
1
1
<h1align="center">Overview</h1>
2
2
3
-
**Mariana** is a simple interpreted language created using standard C. It came about from my desire to design something with "perfect" syntax (in my opinion). It's developed purely for learning purposes.
3
+
**Mariana** is a simple interpreted language created using C. It came about from my desire to design something with "perfect" syntax (in my opinion). It's developed purely for learning purposes.
4
4
5
5
Being aware that this language will never be used in production, and is merely a small personal project, this README will be used as a discussion platform during the development process, such as, for instance, architectural decisions concerning syntax.
6
6
7
7
<h1align="center">Getting Started</h1>
8
8
9
-
I plan to develop an installation script. For now, you can clone the source code and compile it directly:
9
+
"I am in the process of developing an installation script. However, for now, you can clone the source code and compile it manually. Follow these steps:
During the project development, I personally chose to build my own testing "framework" to stick to the idea of using only standard C. You can run all the tests with:
23
-
```bash
24
-
make test
20
+
make
25
21
```
26
-
27
-
If all tests pass, the output will look something like:
This command will first run all [tests](). If all tests pass, the source code will then be compiled. If you want to only compile the source code without running the tests, you can use `make dev`.
30
24
31
-
32
-
On the other hand, if any test fails, the program will exit, and the output will look something like:
25
+
Once you've done that, navigate to the project folder and execute the following command:
With that done, within the project folder you can run the following command:
37
-
38
-
```
27
+
```bash
39
28
./program
40
29
```
41
30
42
-
This will start a small REPL.
31
+
This will launch a simple Read-Eval-Print Loop (REPL)."
43
32
44
33
<h1 align="center">Syntax</h1>
45
34
46
35
```mariana
47
36
// Function definition
48
-
def func add(def x, def y) {
37
+
var add_numbers = fn(def x, def y) {
49
38
return x + y;
50
39
}
51
40
52
-
def x = 5; // Variable definition. All variables are constants by default.
53
-
def mut y = 10; // Mutable variable definition
41
+
var x = 5; // Variable definition. All variables are constants by default.
42
+
var mut y = 10; // Mutable variable definition
54
43
55
-
def result = add(x, y);
44
+
var result = add(x, y);
56
45
x = 0; // This will throw an error.
57
46
y = 0; // This will pass.
58
47
59
-
println("{x} + {y} = {result}");
48
+
println("${x} + ${y} = ${result}");
49
+
```
50
+
51
+
<h1 align="center">Tests</h1>
52
+
53
+
During the course of this project's development, I considered several testing frameworks, such as Check. However, my evaluation led me to the conclusion that introducing such a framework could potentially overcomplicate things.
54
+
55
+
As a result, I decided to implement my own testing "framework". Running these tests is simple, just execute the following command:
56
+
57
+
```
58
+
make test
59
+
```
60
+
61
+
If all tests pass successfully, the console will display a message similar to the following:
62
+
63
+
![]()
64
+
65
+
However, if a test fails, the program will halt execution at the point of failure, allowing for easier debugging.
66
+
67
+
You can find the definitions for all tests in the files that end with the "_test.h" suffix, while the `_test.c` files contain the implementations of these tests. The `./src/main_test.c` file serves as the test runner, executing all test implementations.
68
+
69
+
Tests are named following the pattern "**test_should_pass_if_\[condition]**". For example:
Each `_test.c` file contains local helper functions that assist in performing specific tasks within the file, but are not accessible for other tests. For this reason, I would categorize this as a library, rather than a framework. For instance, in ***src/ast/ast_test.c***, you'll find the `create_program` function:
74
+
75
+
```C
76
+
struct Program* create_program(char* input) {
77
+
struct Lexer* lexer = new_lexer(input);
78
+
struct Parser* parser = new_parser(lexer);
79
+
struct Program* program = parser->parse_program(parser);
80
+
81
+
return program;
82
+
}
83
+
```
84
+
85
+
This function assists us in creating new programs within tests:
0 commit comments