nebulara 2.0.0
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.
- package/Compiler/nbs-bootstrap.c +2229 -0
- package/Compiler/nbs_cli.c +1553 -0
- package/Compiler/neb-cli.exe +0 -0
- package/Compiler/neb-codegen.c +287 -0
- package/Compiler/neb-ffi.c +303 -0
- package/Compiler/neb-ir.c +307 -0
- package/Compiler/neb-knowledge.c +203 -0
- package/Compiler/neb-pipeline.c +787 -0
- package/Compiler/neb-semantic.c +261 -0
- package/Compiler/nebulara.exe +0 -0
- package/README.md +258 -0
- package/SPEC.md +267 -0
- package/bin/neb.js +36 -0
- package/build/neb-cli.exe +0 -0
- package/build/neb-codegen.exe +0 -0
- package/build/neb-ffi.exe +0 -0
- package/build/neb-knowledge.exe +0 -0
- package/build/neb-pipeline.exe +0 -0
- package/build/nebulara.exe +0 -0
- package/dist/index.js +131 -0
- package/package.json +39 -0
- package/std/collections.nbs +72 -0
- package/std/json.nbs +15 -0
- package/std/kanban.nbs +122 -0
- package/std/math.nbs +52 -0
- package/std/net.nbs +22 -0
- package/std/primitives.nbs +30 -0
- package/std/string.nbs +71 -0
- package/std/time.nbs +15 -0
- package/test/broken.nbs +2 -0
- package/test/hello.nbs +6 -0
- package/test/test-arrays.nbs +22 -0
- package/test/test-charat.nbs +7 -0
- package/test/test-cont-debug.nbs +8 -0
- package/test/test-cont-min.nbs +7 -0
- package/test/test-cont-parens.nbs +7 -0
- package/test/test-cont2.nbs +7 -0
- package/test/test-cont3.nbs +7 -0
- package/test/test-control.nbs +18 -0
- package/test/test-functions.nbs +13 -0
- package/test/test-loops.nbs +17 -0
- package/test/test-mod-for.nbs +6 -0
- package/test/test-mod.nbs +5 -0
- package/test/test-new-features.nbs +39 -0
- package/test/test-recursion.nbs +23 -0
- package/test/test-runtime.nbs +8 -0
- package/test/test-strings.nbs +14 -0
- package/test/test-trycatch.nbs +11 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* neb-semantic.c - Semantic Analysis Module for Nebulara
|
|
3
|
+
*
|
|
4
|
+
* Phase 1: Symbol table construction and scope resolution
|
|
5
|
+
* Phase 2: Type checking and inference
|
|
6
|
+
* Phase 3: Error reporting with source locations
|
|
7
|
+
*
|
|
8
|
+
* Build: gcc -o neb-semantic.exe neb-semantic.c -static -O2
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include <stdio.h>
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
#include <string.h>
|
|
14
|
+
|
|
15
|
+
/* Types */
|
|
16
|
+
typedef enum {
|
|
17
|
+
TYPE_UNKNOWN = 0,
|
|
18
|
+
TYPE_INT,
|
|
19
|
+
TYPE_STRING,
|
|
20
|
+
TYPE_BOOL,
|
|
21
|
+
TYPE_ARRAY,
|
|
22
|
+
TYPE_NULL,
|
|
23
|
+
TYPE_FUNC,
|
|
24
|
+
TYPE_FUNC_REF
|
|
25
|
+
} NebType;
|
|
26
|
+
|
|
27
|
+
typedef struct {
|
|
28
|
+
char name[256];
|
|
29
|
+
NebType type;
|
|
30
|
+
int line;
|
|
31
|
+
int col;
|
|
32
|
+
int is_mutable;
|
|
33
|
+
int is_initialized;
|
|
34
|
+
} Symbol;
|
|
35
|
+
|
|
36
|
+
typedef struct Scope {
|
|
37
|
+
Symbol symbols[256];
|
|
38
|
+
int count;
|
|
39
|
+
struct Scope *parent;
|
|
40
|
+
char scope_name[128];
|
|
41
|
+
} Scope;
|
|
42
|
+
|
|
43
|
+
/* Global state */
|
|
44
|
+
static Scope *current_scope = NULL;
|
|
45
|
+
static int error_count = 0;
|
|
46
|
+
static int warning_count = 0;
|
|
47
|
+
|
|
48
|
+
/* Scope management */
|
|
49
|
+
Scope *scope_create(const char *name, Scope *parent) {
|
|
50
|
+
Scope *s = (Scope *)calloc(1, sizeof(Scope));
|
|
51
|
+
strncpy(s->scope_name, name, 127);
|
|
52
|
+
s->parent = parent;
|
|
53
|
+
s->count = 0;
|
|
54
|
+
return s;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
void scope_push(const char *name) {
|
|
58
|
+
current_scope = scope_create(name, current_scope);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
void scope_pop() {
|
|
62
|
+
Scope *old = current_scope;
|
|
63
|
+
if (old && old->parent) {
|
|
64
|
+
current_scope = old->parent;
|
|
65
|
+
}
|
|
66
|
+
free(old);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Symbol operations */
|
|
70
|
+
int symbol_define(const char *name, NebType type, int line, int col, int is_mutable) {
|
|
71
|
+
if (!current_scope) return -1;
|
|
72
|
+
if (current_scope->count >= 256) return -2;
|
|
73
|
+
|
|
74
|
+
/* Check for duplicate in current scope */
|
|
75
|
+
for (int i = 0; i < current_scope->count; i++) {
|
|
76
|
+
if (strcmp(current_scope->symbols[i].name, name) == 0) {
|
|
77
|
+
fprintf(stderr, "SEMANTIC ERROR [%d:%d]: '%s' already defined in this scope\n",
|
|
78
|
+
line, col, name);
|
|
79
|
+
error_count++;
|
|
80
|
+
return -3;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
Symbol *s = ¤t_scope->symbols[current_scope->count];
|
|
85
|
+
strncpy(s->name, name, 255);
|
|
86
|
+
s->type = type;
|
|
87
|
+
s->line = line;
|
|
88
|
+
s->col = col;
|
|
89
|
+
s->is_mutable = is_mutable;
|
|
90
|
+
s->is_initialized = 0;
|
|
91
|
+
current_scope->count++;
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
Symbol *symbol_lookup(const char *name) {
|
|
96
|
+
Scope *s = current_scope;
|
|
97
|
+
while (s) {
|
|
98
|
+
for (int i = 0; i < s->count; i++) {
|
|
99
|
+
if (strcmp(s->symbols[i].name, name) == 0) {
|
|
100
|
+
return &s->symbols[i];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
s = s->parent;
|
|
104
|
+
}
|
|
105
|
+
return NULL;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
int symbol_resolve(const char *name, int line, int col) {
|
|
109
|
+
Symbol *s = symbol_lookup(name);
|
|
110
|
+
if (!s) {
|
|
111
|
+
fprintf(stderr, "SEMANTIC ERROR [%d:%d]: '%s' not defined\n", line, col, name);
|
|
112
|
+
error_count++;
|
|
113
|
+
return -1;
|
|
114
|
+
}
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* Type checking */
|
|
119
|
+
const char *type_name(NebType t) {
|
|
120
|
+
switch (t) {
|
|
121
|
+
case TYPE_INT: return "int";
|
|
122
|
+
case TYPE_STRING: return "string";
|
|
123
|
+
case TYPE_BOOL: return "bool";
|
|
124
|
+
case TYPE_ARRAY: return "array";
|
|
125
|
+
case TYPE_NULL: return "null";
|
|
126
|
+
case TYPE_FUNC:
|
|
127
|
+
case TYPE_FUNC_REF: return "func";
|
|
128
|
+
default: return "unknown";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
NebType type_check_binary(NebType left, const char *op, NebType right, int line, int col) {
|
|
133
|
+
/* Arithmetic: int + int = int */
|
|
134
|
+
if ((strcmp(op, "+") == 0 || strcmp(op, "-") == 0 ||
|
|
135
|
+
strcmp(op, "*") == 0 || strcmp(op, "/") == 0 || strcmp(op, "%") == 0)) {
|
|
136
|
+
if (left == TYPE_INT && right == TYPE_INT) return TYPE_INT;
|
|
137
|
+
/* String concatenation */
|
|
138
|
+
if (left == TYPE_STRING && right == TYPE_STRING) return TYPE_STRING;
|
|
139
|
+
fprintf(stderr, "SEMANTIC ERROR [%d:%d]: type mismatch: %s %s %s\n",
|
|
140
|
+
line, col, type_name(left), op, type_name(right));
|
|
141
|
+
error_count++;
|
|
142
|
+
return TYPE_UNKNOWN;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* Comparison: same-type operands */
|
|
146
|
+
if (strcmp(op, "==") == 0 || strcmp(op, "!=") == 0 ||
|
|
147
|
+
strcmp(op, "<") == 0 || strcmp(op, ">") == 0 ||
|
|
148
|
+
strcmp(op, "<=") == 0 || strcmp(op, ">=") == 0) {
|
|
149
|
+
if (left == right) return TYPE_BOOL;
|
|
150
|
+
/* Allow null comparison */
|
|
151
|
+
if (left == TYPE_NULL || right == TYPE_NULL) return TYPE_BOOL;
|
|
152
|
+
fprintf(stderr, "SEMANTIC WARNING [%d:%d]: comparing %s with %s\n",
|
|
153
|
+
line, col, type_name(left), type_name(right));
|
|
154
|
+
warning_count++;
|
|
155
|
+
return TYPE_BOOL;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return TYPE_UNKNOWN;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Type inference from literal */
|
|
162
|
+
NebType infer_type_from_literal(const char *value) {
|
|
163
|
+
if (!value) return TYPE_NULL;
|
|
164
|
+
if (value[0] == '"') return TYPE_STRING;
|
|
165
|
+
if (value[0] == '[') return TYPE_ARRAY;
|
|
166
|
+
if (strcmp(value, "TRUE") == 0 || strcmp(value, "FALSE") == 0) return TYPE_BOOL;
|
|
167
|
+
if (strcmp(value, "NULL") == 0) return TYPE_NULL;
|
|
168
|
+
/* Check if number */
|
|
169
|
+
int i = 0;
|
|
170
|
+
if (value[0] == '-' || value[0] == '+') i = 1;
|
|
171
|
+
int is_num = 1;
|
|
172
|
+
for (; value[i]; i++) {
|
|
173
|
+
if (value[i] < '0' || value[i] > '9') { is_num = 0; break; }
|
|
174
|
+
}
|
|
175
|
+
if (is_num && i > 0) return TYPE_INT;
|
|
176
|
+
return TYPE_UNKNOWN;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* Built-in function validation */
|
|
180
|
+
NebType check_builtin(const char *name, int arg_count, NebType *arg_types, int line, int col) {
|
|
181
|
+
if (strcmp(name, "PRINT") == 0) return TYPE_NULL;
|
|
182
|
+
if (strcmp(name, "LEN") == 0) {
|
|
183
|
+
if (arg_count != 1) {
|
|
184
|
+
fprintf(stderr, "SEMANTIC ERROR [%d:%d]: LEN expects 1 argument, got %d\n",
|
|
185
|
+
line, col, arg_count);
|
|
186
|
+
error_count++;
|
|
187
|
+
return TYPE_UNKNOWN;
|
|
188
|
+
}
|
|
189
|
+
if (arg_types[0] != TYPE_STRING && arg_types[0] != TYPE_ARRAY) {
|
|
190
|
+
fprintf(stderr, "SEMANTIC ERROR [%d:%d]: LEN expects string or array, got %s\n",
|
|
191
|
+
line, col, type_name(arg_types[0]));
|
|
192
|
+
error_count++;
|
|
193
|
+
return TYPE_UNKNOWN;
|
|
194
|
+
}
|
|
195
|
+
return TYPE_INT;
|
|
196
|
+
}
|
|
197
|
+
if (strcmp(name, "TYPEOF") == 0) return TYPE_STRING;
|
|
198
|
+
if (strcmp(name, "TO_STRING") == 0) return TYPE_STRING;
|
|
199
|
+
if (strcmp(name, "TO_NUMBER") == 0) return TYPE_INT;
|
|
200
|
+
if (strcmp(name, "RANDOM") == 0) return TYPE_INT;
|
|
201
|
+
if (strcmp(name, "TIME") == 0) return TYPE_INT;
|
|
202
|
+
if (strcmp(name, "CONCAT") == 0) return TYPE_STRING;
|
|
203
|
+
|
|
204
|
+
return TYPE_UNKNOWN;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* Report results */
|
|
208
|
+
void semantic_report(void) {
|
|
209
|
+
if (error_count == 0 && warning_count == 0) {
|
|
210
|
+
printf("Semantic analysis: PASS (no errors, no warnings)\n");
|
|
211
|
+
} else {
|
|
212
|
+
printf("Semantic analysis: %d error(s), %d warning(s)\n", error_count, warning_count);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
int semantic_errors(void) {
|
|
217
|
+
return error_count;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* Demo/test function */
|
|
221
|
+
#ifdef NEB_SEMANTIC_TEST
|
|
222
|
+
int main(void) {
|
|
223
|
+
printf("=== Nebulara Semantic Analysis Module ===\n\n");
|
|
224
|
+
|
|
225
|
+
/* Create global scope */
|
|
226
|
+
scope_push("global");
|
|
227
|
+
|
|
228
|
+
/* Define variables */
|
|
229
|
+
symbol_define("x", TYPE_INT, 1, 5, 1);
|
|
230
|
+
symbol_define("name", TYPE_STRING, 2, 5, 1);
|
|
231
|
+
symbol_define("PI", TYPE_INT, 3, 5, 0);
|
|
232
|
+
|
|
233
|
+
/* Create function scope */
|
|
234
|
+
scope_push("factorial");
|
|
235
|
+
symbol_define("n", TYPE_INT, 10, 10, 1);
|
|
236
|
+
|
|
237
|
+
/* Test lookup */
|
|
238
|
+
Symbol *s = symbol_lookup("n");
|
|
239
|
+
if (s) printf("Found '%s' of type %s (defined at line %d)\n",
|
|
240
|
+
s->name, type_name(s->type), s->line);
|
|
241
|
+
|
|
242
|
+
/* Test undefined variable */
|
|
243
|
+
symbol_resolve("undefined_var", 15, 5);
|
|
244
|
+
|
|
245
|
+
/* Test type checking */
|
|
246
|
+
type_check_binary(TYPE_INT, "+", TYPE_INT, 20, 10);
|
|
247
|
+
type_check_binary(TYPE_INT, "+", TYPE_STRING, 21, 10);
|
|
248
|
+
type_check_binary(TYPE_STRING, "+", TYPE_STRING, 22, 10);
|
|
249
|
+
|
|
250
|
+
/* Test built-ins */
|
|
251
|
+
NebType args[] = { TYPE_STRING };
|
|
252
|
+
check_builtin("LEN", 1, args, 30, 5);
|
|
253
|
+
check_builtin("PRINT", 1, args, 31, 5);
|
|
254
|
+
|
|
255
|
+
scope_pop(); /* pop factorial scope */
|
|
256
|
+
scope_pop(); /* pop global scope */
|
|
257
|
+
|
|
258
|
+
semantic_report();
|
|
259
|
+
return error_count > 0 ? 1 : 0;
|
|
260
|
+
}
|
|
261
|
+
#endif
|
|
Binary file
|
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# Nebulara
|
|
2
|
+
|
|
3
|
+
**Nebulara - The AI-Native Universal Programming Language**
|
|
4
|
+
|
|
5
|
+
An interpreter and transpiler for .nbs programs, with bytecode compilation, standard library, and npm distribution.
|
|
6
|
+
|
|
7
|
+
[]()
|
|
8
|
+
[]()
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
# Install from npm
|
|
14
|
+
npm install -g @codurra/nebulara
|
|
15
|
+
|
|
16
|
+
# Run a .nbs file
|
|
17
|
+
neb run hello.nbs
|
|
18
|
+
|
|
19
|
+
# Transpile to JavaScript
|
|
20
|
+
neb transpile hello.nbs --target js
|
|
21
|
+
|
|
22
|
+
# Transpile to Python
|
|
23
|
+
neb transpile hello.nbs --target py
|
|
24
|
+
|
|
25
|
+
# Run the interactive REPL
|
|
26
|
+
neb repl
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Building from source
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Using npm
|
|
33
|
+
node scripts/build.js
|
|
34
|
+
|
|
35
|
+
# Using Make (Linux/macOS/MinGW)
|
|
36
|
+
make all
|
|
37
|
+
|
|
38
|
+
# Using batch file (Windows)
|
|
39
|
+
build.bat
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Language Syntax (Dialect A)
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
# Comments start with #
|
|
46
|
+
|
|
47
|
+
# Variables
|
|
48
|
+
LET name = "Nebulara"
|
|
49
|
+
LET count = 42
|
|
50
|
+
LET flag = TRUE
|
|
51
|
+
LET nothing = NULL
|
|
52
|
+
|
|
53
|
+
# Constants
|
|
54
|
+
CONST PI = 314
|
|
55
|
+
|
|
56
|
+
# Arithmetic
|
|
57
|
+
LET result = 10 + 5 * 2 - 3 / 1
|
|
58
|
+
|
|
59
|
+
# Strings
|
|
60
|
+
LET greeting = "Hello, " + name
|
|
61
|
+
PRINT(TO_UPPER(greeting))
|
|
62
|
+
PRINT(LEN(greeting))
|
|
63
|
+
PRINT(CHAR_AT(greeting, 0))
|
|
64
|
+
PRINT(SUBSTR(greeting, 0, 5))
|
|
65
|
+
PRINT(TRIM(" hello "))
|
|
66
|
+
|
|
67
|
+
# Bitwise operations
|
|
68
|
+
PRINT(5 & 3) # 1 (AND)
|
|
69
|
+
PRINT(5 | 3) # 7 (OR)
|
|
70
|
+
PRINT(1 << 3) # 8 (left shift)
|
|
71
|
+
PRINT(16 >> 2) # 4 (right shift)
|
|
72
|
+
|
|
73
|
+
# Arrays
|
|
74
|
+
LET arr = [10, 20, 30, 40]
|
|
75
|
+
PRINT(arr[0]) # 10
|
|
76
|
+
arr[1] = 99 # Array mutation
|
|
77
|
+
PUSH(arr, 50) # Append
|
|
78
|
+
LET last = POP(arr) # Remove last
|
|
79
|
+
|
|
80
|
+
# Control flow
|
|
81
|
+
IF? count > 10 THEN:
|
|
82
|
+
PRINT("big")
|
|
83
|
+
ELSEIF? count > 5 THEN:
|
|
84
|
+
PRINT("medium")
|
|
85
|
+
ELSE:
|
|
86
|
+
PRINT("small")
|
|
87
|
+
END!
|
|
88
|
+
|
|
89
|
+
# Loops
|
|
90
|
+
WHILE? count > 0 THEN:
|
|
91
|
+
count = count - 1
|
|
92
|
+
END!
|
|
93
|
+
|
|
94
|
+
FOR! i = 0 TO 10 (STEP 2):
|
|
95
|
+
PRINT(i)
|
|
96
|
+
END!
|
|
97
|
+
|
|
98
|
+
# Break and CONTINUE
|
|
99
|
+
FOR! i = 0 TO 100:
|
|
100
|
+
IF? i == 5 THEN: BREAK END!
|
|
101
|
+
IF? i % 2 == 0 THEN: CONTINUE END!
|
|
102
|
+
PRINT(i)
|
|
103
|
+
END!
|
|
104
|
+
|
|
105
|
+
# Functions
|
|
106
|
+
FUNC! add(a, b):
|
|
107
|
+
RETURN a + b
|
|
108
|
+
END!
|
|
109
|
+
|
|
110
|
+
LET sum = add(3, 4)
|
|
111
|
+
|
|
112
|
+
# Recursive functions
|
|
113
|
+
FUNC! factorial(n):
|
|
114
|
+
IF? n <= 1 THEN:
|
|
115
|
+
RETURN 1
|
|
116
|
+
END!
|
|
117
|
+
RETURN n * factorial(n - 1)
|
|
118
|
+
END!
|
|
119
|
+
|
|
120
|
+
# Exception handling
|
|
121
|
+
TRY!:
|
|
122
|
+
THROW "something went wrong"
|
|
123
|
+
CATCH! err:
|
|
124
|
+
PRINT("Caught: " + err)
|
|
125
|
+
ENDTRY!
|
|
126
|
+
|
|
127
|
+
# Type checking
|
|
128
|
+
PRINT(TYPEOF(42)) # int
|
|
129
|
+
PRINT(TYPEOF("hello")) # string
|
|
130
|
+
PRINT(TYPEOF(TRUE)) # bool
|
|
131
|
+
PRINT(TYPEOF(NULL)) # null
|
|
132
|
+
PRINT(TYPEOF([1, 2, 3])) # array
|
|
133
|
+
|
|
134
|
+
# Built-in functions
|
|
135
|
+
PRINT(ABS(-42)) # 42
|
|
136
|
+
PRINT(MIN(10, 20)) # 10
|
|
137
|
+
PRINT(MAX(10, 20)) # 20
|
|
138
|
+
PRINT(SQRT(16)) # 4
|
|
139
|
+
PRINT(POW(2, 10)) # 1024
|
|
140
|
+
PRINT(CHAR(65)) # A
|
|
141
|
+
PRINT(ORD("Z")) # 90
|
|
142
|
+
PRINT(RANDOM()) # 0-99
|
|
143
|
+
PRINT(TIME()) # Unix timestamp
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Architecture
|
|
147
|
+
|
|
148
|
+
### Interpreters
|
|
149
|
+
|
|
150
|
+
| Binary | Source | Description |
|
|
151
|
+
|--------|--------|-------------|
|
|
152
|
+
| `nebulara.exe` | `nbs-bootstrap.c` | Primary interpreter (2200+ lines). Full AST, bytecode compiler, VM with 40+ opcodes. |
|
|
153
|
+
| `neb-cli.exe` | `nbs_cli.c` | Extended CLI interpreter. Additional features: TRY/CATCH, bitwise ops, build-to-bytecode, syntax highlighting. |
|
|
154
|
+
|
|
155
|
+
### Toolchain Modules
|
|
156
|
+
|
|
157
|
+
| Binary | Source | Description |
|
|
158
|
+
|--------|--------|-------------|
|
|
159
|
+
| `neb-pipeline.exe` | `neb-pipeline.c` | `.nbs` to JavaScript/Python transpiler (end-to-end) |
|
|
160
|
+
| `neb-semantic.exe` | `neb-semantic.c` | Scope and type checker (standalone demo) |
|
|
161
|
+
| `neb-ir.exe` | `neb-ir.c` | Three-address code IR (standalone demo) |
|
|
162
|
+
| `neb-codegen.exe` | `neb-codegen.c` | x86/x64 instruction encoder (standalone demo) |
|
|
163
|
+
| `neb-transpiler-js.exe` | `neb-transpiler-js.c` | JS transpiler helpers |
|
|
164
|
+
| `neb-transpiler-py.exe` | `neb-transpiler-py.c` | Python transpiler helpers |
|
|
165
|
+
| `neb-ffi.exe` | `neb-ffi.c` | FFI bridge (stub) |
|
|
166
|
+
| `neb-knowledge.exe` | `neb-knowledge.c` | Knowledge graph (standalone demo) |
|
|
167
|
+
|
|
168
|
+
### Standard Library (`std/`)
|
|
169
|
+
|
|
170
|
+
| File | Functions |
|
|
171
|
+
|------|-----------|
|
|
172
|
+
| `primitives.nbs` | `IS_INT()`, `IS_STRING()`, `IS_BOOL()`, `IS_NULL()`, `IS_ARRAY()`, `IS_FUNC()`, `IS_NUMBER()` |
|
|
173
|
+
| `math.nbs` | `abs()`, `min()`, `max()`, `clamp()`, `sum_array()`, `average()` |
|
|
174
|
+
| `string.nbs` | `concat()`, `repeat()`, `reverse()`, `contains()`, `to_upper()`, `to_lower()`, `trim()`, `substring()` |
|
|
175
|
+
| `collections.nbs` | `find()`, `contains()`, `reverse_array()`, `sum_array()`, `max_array()`, `min_array()` |
|
|
176
|
+
| `time.nbs` | `now()`, `elapsed()`, `sleep()` (stub) |
|
|
177
|
+
| `json.nbs` | `json_stringify()` (wraps TO_STRING), `json_parse()` (stub) |
|
|
178
|
+
| `net.nbs` | All stubs |
|
|
179
|
+
|
|
180
|
+
### npm Package
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
@codurra/nebulara
|
|
184
|
+
bin/neb.js - CLI entry point (neb / nebulara commands)
|
|
185
|
+
dist/index.js - Programmatic API
|
|
186
|
+
registry/ - Local package registry
|
|
187
|
+
build/ - All 10 compiled binaries
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**API:**
|
|
191
|
+
```javascript
|
|
192
|
+
const { run, runString, transpileToJS, transpileToPython, check } = require('@codurra/nebulara');
|
|
193
|
+
|
|
194
|
+
run('./hello.nbs');
|
|
195
|
+
runString('PRINT("Hello!")');
|
|
196
|
+
transpileToJS('./app.nbs'); // Returns JavaScript source
|
|
197
|
+
transpileToPython('./app.nbs'); // Returns Python source
|
|
198
|
+
check('./app.nbs'); // Type checking
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Registry
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Publish a package
|
|
205
|
+
neb publish ./my-package
|
|
206
|
+
|
|
207
|
+
# Install a package
|
|
208
|
+
neb install @username/package-name
|
|
209
|
+
|
|
210
|
+
# Search packages
|
|
211
|
+
neb search "web framework"
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Built-in Functions (35+)
|
|
215
|
+
|
|
216
|
+
| Function | Description |
|
|
217
|
+
|----------|-------------|
|
|
218
|
+
| `PRINT(expr)` | Print value with newline |
|
|
219
|
+
| `LEN(x)` | String length or array count |
|
|
220
|
+
| `TYPEOF(x)` | Returns type name as string |
|
|
221
|
+
| `TO_STRING(x)` | Convert to string |
|
|
222
|
+
| `TO_NUMBER(x)` | Convert to integer |
|
|
223
|
+
| `TO_UPPER(s)` | Uppercase string |
|
|
224
|
+
| `TO_LOWER(s)` | Lowercase string |
|
|
225
|
+
| `CHAR_AT(s, i)` | Character at index (returns 1-char string) |
|
|
226
|
+
| `SUBSTR(s, start, len)` | Extract substring |
|
|
227
|
+
| `TRIM(s)` | Remove leading/trailing whitespace |
|
|
228
|
+
| `CHAR(n)` | Integer to ASCII character |
|
|
229
|
+
| `ORD(s)` | First character to integer |
|
|
230
|
+
| `ABS(n)` | Absolute value |
|
|
231
|
+
| `MIN(a, b)` | Minimum of two values |
|
|
232
|
+
| `MAX(a, b)` | Maximum of two values |
|
|
233
|
+
| `SQRT(n)` | Square root |
|
|
234
|
+
| `POW(base, exp)` | Exponentiation |
|
|
235
|
+
| `RANDOM()` | Random integer 0-99 |
|
|
236
|
+
| `TIME()` | Current Unix timestamp |
|
|
237
|
+
| `READ_FILE(path)` | Read file contents as string |
|
|
238
|
+
| `WRITE_FILE(path, content)` | Write string to file |
|
|
239
|
+
| `PUSH(arr, val)` | Append value to array |
|
|
240
|
+
| `POP(arr)` | Remove and return last element |
|
|
241
|
+
|
|
242
|
+
## Test Suite
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
test/hello.nbs - Basic PRINT, LET, arithmetic
|
|
246
|
+
test/test-functions.nbs - Functions, params, return values
|
|
247
|
+
test/test-loops.nbs - WHILE, FOR, FOR with STEP
|
|
248
|
+
test/test-control.nbs - BREAK/CONTINUE
|
|
249
|
+
test/test-recursion.nbs - Factorial, Fibonacci
|
|
250
|
+
test/test-arrays.nbs - Indexing, length, sum, string arrays
|
|
251
|
+
test/test-strings.nbs - Concatenation, builtins, type checking
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Run all tests: `node scripts/test.js`
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
Proprietary - CODURRA Labs & Technologies
|