brett-compiler 1.0.26 → 1.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +276 -0
  2. package/dist/README.md +276 -0
  3. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # Brett Language Reference
2
+
3
+ Brett is a statically-typed, C-style programming language with modern control structures, functions, and object/array support. This guide covers all syntax and language features.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Program Structure](#program-structure)
10
+ 2. [Variables](#variables)
11
+ 3. [Functions](#functions)
12
+ 4. [Control Flow](#control-flow)
13
+ - [If and Else](#if-and-else)
14
+ - [While](#while)
15
+ - [Do-While](#do-while)
16
+ - [For](#for)
17
+ - [Switch](#switch)
18
+ 5. [Try, Catch, and Finally](#try-catch-and-finally)
19
+ 6. [Expressions](#expressions)
20
+ - [Literals](#literals)
21
+ - [Identifiers](#identifiers)
22
+ - [Operators](#operators)
23
+ - [Function Calls](#function-calls)
24
+ - [Arrays](#arrays)
25
+ - [Objects](#objects)
26
+ - [Member Access and Indexing](#member-access-and-indexing)
27
+ - [Increment and Decrement](#increment-and-decrement)
28
+ 7. [Types](#types)
29
+ 8. [Miscellaneous](#miscellaneous)
30
+
31
+ ---
32
+
33
+ ## Program Structure
34
+
35
+ A Brett program is a series of statements, optionally organized into blocks:
36
+
37
+ ```brett
38
+ program : statement* EOF ;
39
+
40
+ block : '{' statement* '}' ;
41
+ ```
42
+
43
+ Example:
44
+
45
+ ```brett
46
+ {
47
+ let x = 10;
48
+ let y = 20;
49
+ }
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Variables
55
+
56
+ Brett supports mutable (`let`) and immutable (`const`) variables:
57
+
58
+ ```brett
59
+ let x = 5; // mutable
60
+ const y: number = 10; // immutable, type-annotated
61
+ ```
62
+
63
+ - Optional type annotations are allowed: `let z: string = "hello";`
64
+ - Immutable variables must always be initialized.
65
+
66
+ ---
67
+
68
+ ## Functions
69
+
70
+ Functions are declared with `def`:
71
+
72
+ ```brett
73
+ def add(a: number, b: number): number {
74
+ return a + b;
75
+ }
76
+ ```
77
+
78
+ - Parameters can have optional type annotations.
79
+ - Functions can have an optional return type.
80
+ - Blocks define the function body.
81
+
82
+ ---
83
+
84
+ ## Control Flow
85
+
86
+ ### If and Else
87
+
88
+ ```brett
89
+ if (x > 0) {
90
+ print("Positive");
91
+ } else {
92
+ print("Non-positive");
93
+ }
94
+ ```
95
+
96
+ - Standard `if-else` branching.
97
+
98
+ ### While
99
+
100
+ ```brett
101
+ while (x < 10) {
102
+ x++;
103
+ }
104
+ ```
105
+
106
+ - Repeats the block while the condition is true.
107
+
108
+ ### Do-While
109
+
110
+ ```brett
111
+ do {
112
+ x++;
113
+ } while (x < 10);
114
+ ```
115
+
116
+ - Executes the block at least once, then checks the condition.
117
+
118
+ ### For
119
+
120
+ ```brett
121
+ for (let i = 0; i < 10; i++) {
122
+ print(i);
123
+ }
124
+ ```
125
+
126
+ - Supports initialization, condition, and iteration expressions.
127
+ - Can omit parts of the `for` declaration if not needed.
128
+
129
+ ### Switch
130
+
131
+ ```brett
132
+ switch {
133
+ case 1 => { print("One"); }
134
+ case 2 => { print("Two"); }
135
+ default => { print("Other"); }
136
+ }
137
+ ```
138
+
139
+ - Expression-based cases using `=>`.
140
+ - Optional `default` case.
141
+
142
+ ---
143
+
144
+ ## Try, Catch, and Finally
145
+
146
+ ```brett
147
+ try {
148
+ riskyOperation();
149
+ } catch (e: Error) {
150
+ print("Caught an error: " + e);
151
+ } finally {
152
+ cleanup();
153
+ }
154
+ ```
155
+
156
+ - Standard exception handling.
157
+ - `finally` block executes regardless of exceptions.
158
+
159
+ ---
160
+
161
+ ## Expressions
162
+
163
+ Brett supports a rich set of expressions.
164
+
165
+ ### Literals
166
+
167
+ ```brett
168
+ 42 // number
169
+ 3.14 // float
170
+ "hello" // string
171
+ true
172
+ false
173
+ nil
174
+ ```
175
+
176
+ ### Identifiers
177
+
178
+ ```brett
179
+ let name = "Alice";
180
+ ```
181
+
182
+ ### Operators
183
+
184
+ Binary operators:
185
+
186
+ ```brett
187
+ +, -, *, /, <, <=, >, >=, ==, !=
188
+ ```
189
+
190
+ Assignment (right-associative):
191
+
192
+ ```brett
193
+ x = 10;
194
+ y = x = 5;
195
+ ```
196
+
197
+ ### Function Calls
198
+
199
+ ```brett
200
+ print("Hello, world!");
201
+ sum(3, 4);
202
+ ```
203
+
204
+ ### Arrays
205
+
206
+ ```brett
207
+ let nums = [1, 2, 3, 4];
208
+ ```
209
+
210
+ ### Objects
211
+
212
+ ```brett
213
+ let person = {
214
+ name: "Alice",
215
+ age: 30
216
+ };
217
+ ```
218
+
219
+ ### Member Access and Indexing
220
+
221
+ ```brett
222
+ person.name; // "Alice"
223
+ nums[0]; // 1
224
+ ```
225
+
226
+ ### Increment and Decrement
227
+
228
+ ```brett
229
+ x++; // post-increment
230
+ ++x; // pre-increment
231
+ x--; // post-decrement
232
+ --x; // pre-decrement
233
+ ```
234
+
235
+ ---
236
+
237
+ ## Types
238
+
239
+ ```brett
240
+ string, number, bool, any, void
241
+ ```
242
+
243
+ - Arrays: `number[]`, `string[]`
244
+ - Custom types: `MyType`
245
+
246
+ ---
247
+
248
+ ## Miscellaneous
249
+
250
+ - **Break / Continue**:
251
+
252
+ ```brett
253
+ for (let i = 0; i < 10; i++) {
254
+ if (i == 5) break;
255
+ if (i % 2 == 0) continue;
256
+ }
257
+ ```
258
+
259
+ - **Return**:
260
+
261
+ ```brett
262
+ return x + y;
263
+ ```
264
+
265
+ ---
266
+
267
+ ### Comments
268
+
269
+ ```brett
270
+ // single-line comment
271
+ /* multi-line comment */
272
+ ```
273
+
274
+ ---
275
+
276
+ This guide covers **all core features** of Brett, from variables and functions to advanced control flow and expressions.
package/dist/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # Brett Language Reference
2
+
3
+ Brett is a statically-typed, C-style programming language with modern control structures, functions, and object/array support. This guide covers all syntax and language features.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [Program Structure](#program-structure)
10
+ 2. [Variables](#variables)
11
+ 3. [Functions](#functions)
12
+ 4. [Control Flow](#control-flow)
13
+ - [If and Else](#if-and-else)
14
+ - [While](#while)
15
+ - [Do-While](#do-while)
16
+ - [For](#for)
17
+ - [Switch](#switch)
18
+ 5. [Try, Catch, and Finally](#try-catch-and-finally)
19
+ 6. [Expressions](#expressions)
20
+ - [Literals](#literals)
21
+ - [Identifiers](#identifiers)
22
+ - [Operators](#operators)
23
+ - [Function Calls](#function-calls)
24
+ - [Arrays](#arrays)
25
+ - [Objects](#objects)
26
+ - [Member Access and Indexing](#member-access-and-indexing)
27
+ - [Increment and Decrement](#increment-and-decrement)
28
+ 7. [Types](#types)
29
+ 8. [Miscellaneous](#miscellaneous)
30
+
31
+ ---
32
+
33
+ ## Program Structure
34
+
35
+ A Brett program is a series of statements, optionally organized into blocks:
36
+
37
+ ```brett
38
+ program : statement* EOF ;
39
+
40
+ block : '{' statement* '}' ;
41
+ ```
42
+
43
+ Example:
44
+
45
+ ```brett
46
+ {
47
+ let x = 10;
48
+ let y = 20;
49
+ }
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Variables
55
+
56
+ Brett supports mutable (`let`) and immutable (`const`) variables:
57
+
58
+ ```brett
59
+ let x = 5; // mutable
60
+ const y: number = 10; // immutable, type-annotated
61
+ ```
62
+
63
+ - Optional type annotations are allowed: `let z: string = "hello";`
64
+ - Immutable variables must always be initialized.
65
+
66
+ ---
67
+
68
+ ## Functions
69
+
70
+ Functions are declared with `def`:
71
+
72
+ ```brett
73
+ def add(a: number, b: number): number {
74
+ return a + b;
75
+ }
76
+ ```
77
+
78
+ - Parameters can have optional type annotations.
79
+ - Functions can have an optional return type.
80
+ - Blocks define the function body.
81
+
82
+ ---
83
+
84
+ ## Control Flow
85
+
86
+ ### If and Else
87
+
88
+ ```brett
89
+ if (x > 0) {
90
+ print("Positive");
91
+ } else {
92
+ print("Non-positive");
93
+ }
94
+ ```
95
+
96
+ - Standard `if-else` branching.
97
+
98
+ ### While
99
+
100
+ ```brett
101
+ while (x < 10) {
102
+ x++;
103
+ }
104
+ ```
105
+
106
+ - Repeats the block while the condition is true.
107
+
108
+ ### Do-While
109
+
110
+ ```brett
111
+ do {
112
+ x++;
113
+ } while (x < 10);
114
+ ```
115
+
116
+ - Executes the block at least once, then checks the condition.
117
+
118
+ ### For
119
+
120
+ ```brett
121
+ for (let i = 0; i < 10; i++) {
122
+ print(i);
123
+ }
124
+ ```
125
+
126
+ - Supports initialization, condition, and iteration expressions.
127
+ - Can omit parts of the `for` declaration if not needed.
128
+
129
+ ### Switch
130
+
131
+ ```brett
132
+ switch {
133
+ case 1 => { print("One"); }
134
+ case 2 => { print("Two"); }
135
+ default => { print("Other"); }
136
+ }
137
+ ```
138
+
139
+ - Expression-based cases using `=>`.
140
+ - Optional `default` case.
141
+
142
+ ---
143
+
144
+ ## Try, Catch, and Finally
145
+
146
+ ```brett
147
+ try {
148
+ riskyOperation();
149
+ } catch (e: Error) {
150
+ print("Caught an error: " + e);
151
+ } finally {
152
+ cleanup();
153
+ }
154
+ ```
155
+
156
+ - Standard exception handling.
157
+ - `finally` block executes regardless of exceptions.
158
+
159
+ ---
160
+
161
+ ## Expressions
162
+
163
+ Brett supports a rich set of expressions.
164
+
165
+ ### Literals
166
+
167
+ ```brett
168
+ 42 // number
169
+ 3.14 // float
170
+ "hello" // string
171
+ true
172
+ false
173
+ nil
174
+ ```
175
+
176
+ ### Identifiers
177
+
178
+ ```brett
179
+ let name = "Alice";
180
+ ```
181
+
182
+ ### Operators
183
+
184
+ Binary operators:
185
+
186
+ ```brett
187
+ +, -, *, /, <, <=, >, >=, ==, !=
188
+ ```
189
+
190
+ Assignment (right-associative):
191
+
192
+ ```brett
193
+ x = 10;
194
+ y = x = 5;
195
+ ```
196
+
197
+ ### Function Calls
198
+
199
+ ```brett
200
+ print("Hello, world!");
201
+ sum(3, 4);
202
+ ```
203
+
204
+ ### Arrays
205
+
206
+ ```brett
207
+ let nums = [1, 2, 3, 4];
208
+ ```
209
+
210
+ ### Objects
211
+
212
+ ```brett
213
+ let person = {
214
+ name: "Alice",
215
+ age: 30
216
+ };
217
+ ```
218
+
219
+ ### Member Access and Indexing
220
+
221
+ ```brett
222
+ person.name; // "Alice"
223
+ nums[0]; // 1
224
+ ```
225
+
226
+ ### Increment and Decrement
227
+
228
+ ```brett
229
+ x++; // post-increment
230
+ ++x; // pre-increment
231
+ x--; // post-decrement
232
+ --x; // pre-decrement
233
+ ```
234
+
235
+ ---
236
+
237
+ ## Types
238
+
239
+ ```brett
240
+ string, number, bool, any, void
241
+ ```
242
+
243
+ - Arrays: `number[]`, `string[]`
244
+ - Custom types: `MyType`
245
+
246
+ ---
247
+
248
+ ## Miscellaneous
249
+
250
+ - **Break / Continue**:
251
+
252
+ ```brett
253
+ for (let i = 0; i < 10; i++) {
254
+ if (i == 5) break;
255
+ if (i % 2 == 0) continue;
256
+ }
257
+ ```
258
+
259
+ - **Return**:
260
+
261
+ ```brett
262
+ return x + y;
263
+ ```
264
+
265
+ ---
266
+
267
+ ### Comments
268
+
269
+ ```brett
270
+ // single-line comment
271
+ /* multi-line comment */
272
+ ```
273
+
274
+ ---
275
+
276
+ This guide covers **all core features** of Brett, from variables and functions to advanced control flow and expressions.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brett-compiler",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "Een compiler voor de .Brett taal",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",