-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.c
146 lines (95 loc) · 1.98 KB
/
source.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Single Line Comment
/*
* Multi
* Line
* Comment
*/
/*
* Supported variable types:
* 4 byte int
* 4 byte float
* string (ASCII 1 byte per character)
*
*
*
*/
// Potential ways to declare and initialize variables
int a := 5;
let a : int := 5;
let a<int> := 5;
float b := 3.2;
string c := "Hello, world!";
// Interates over each element in iterable
for (variable_name in iterable) {
}
// Classic for loop
for (int i := 0; i < 10; i := i + 1) {
}
// Classic while loop
while (true) {
}
// if, else if, else construct
if (false) {
} elif (false) {
} elif (true) {
} else {
}
// Multi conditioned if
if[3] (true), (file), (good_format) {
file := open("some.txt", "r");
// Condition check can be delayed until inside the body.
// Condition index starts at 0
check(1);
for (line in file) {
good_format = check_format(line);
check(2); // Condition check can be repeated multiple times
}
close(file);
case 0 {
// Cases contain unique code and other case blocks are not entered
// Similar to switch statements except "break" is forced
}
case 1 {
// also similar to anonymous functions since
// check(1)
// calls
// case 1 {}
}
case 2 {
close(file); //Since file exists in the outer scope, we can still access it here.
}
// Code that's always executed after the case blocks
}
if (x > 1) {
int y = get_int();
x := x - y;
check(0);
case 0 {
// Case 0 is NOT called if first condition fails before entering the if block
// because it might use variables whose scope is restricted to the if block
//
// Case 0 IS called if check(0) is called and fails in the body of the if statement
// This makes it so you can repeat the initial check at a later point.
print("{y} is too big\n", y);
x := x + y;
}
}
/*
* Multi Conditioned ifs can be used with elif structure
*
*/
// Ok
if[2] (bool1) (bool2) {
case 0 {
}
case 1 {
}
} elif[3] (bool3) (bool4) (bool5) {
case 0 {
}
case 1 {
}
case 2 {
}
} else {
}