lumos-language 1.1.2 → 2.0.2
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/.github/FUNDING.yml +1 -0
- package/.npmrc.ci-backup +3 -0
- package/LICENSE +0 -29
- package/Lumos.png +0 -0
- package/README.md +284 -126
- package/STRUCTURE.md +216 -0
- package/examples/hello.lumos +5 -0
- package/index.cjs +125 -125
- package/index.html +120 -274
- package/package.json +20 -10
- package/src/backends/assembly/arm.js +39 -0
- package/src/backends/assembly/wasm.js +39 -0
- package/src/backends/assembly/x86.js +39 -0
- package/src/backends/compiled/c.js +39 -0
- package/src/backends/compiled/cpp.js +39 -0
- package/src/backends/compiled/csharp.js +39 -0
- package/src/backends/compiled/go.js +39 -0
- package/src/backends/compiled/java.js +39 -0
- package/src/backends/compiled/rust.js +39 -0
- package/src/backends/compiled/swift.js +39 -0
- package/src/backends/database/mongodb.js +39 -0
- package/src/backends/database/mysql.js +39 -0
- package/src/backends/database/postgresql.js +39 -0
- package/src/backends/database/sql.js +39 -0
- package/src/backends/database/sqlite.js +39 -0
- package/src/backends/functional/clojure.js +39 -0
- package/src/backends/functional/elixir.js +39 -0
- package/src/backends/functional/erlang.js +39 -0
- package/src/backends/functional/fsharp.js +39 -0
- package/src/backends/functional/haskell.js +39 -0
- package/src/backends/functional/scala.js +39 -0
- package/src/backends/interpreted/lua.js +39 -0
- package/src/backends/interpreted/perl.js +39 -0
- package/src/backends/interpreted/php.js +39 -0
- package/src/backends/interpreted/python.js +356 -0
- package/src/backends/interpreted/ruby.js +222 -0
- package/src/backends/scripting/bash.js +39 -0
- package/src/backends/scripting/javascript.js +39 -0
- package/src/backends/scripting/powershell.js +39 -0
- package/src/backends/scripting/typescript.js +39 -0
- package/src/backends/scripting/vbscript.js +39 -0
- package/src/backends/specialized/ada.js +39 -0
- package/src/backends/specialized/cobol.js +39 -0
- package/src/backends/specialized/fortran.js +39 -0
- package/src/backends/specialized/lisp.js +39 -0
- package/src/backends/specialized/mlang.js +39 -0
- package/src/backends/specialized/prolog.js +39 -0
- package/src/backends/web/css.js +39 -0
- package/src/backends/web/html.js +39 -0
- package/src/backends/web/jsx.js +39 -0
- package/src/backends/web/vue.js +39 -0
- package/src/cli/fileRunner.js +82 -0
- package/src/cli/repl.js +244 -0
- package/src/compiler/core/compiler.js +1350 -0
- package/src/compiler/framework-integrator.js +846 -0
- package/src/compiler/generators/dynamic-languages.js +620 -0
- package/src/compiler/generators/system-languages.js +1184 -0
- package/src/core/compiler.js +181 -0
- package/src/core/evaluator.js +408 -0
- package/src/core/lexer.js +251 -0
- package/src/core/parser.js +452 -0
- package/src/core/runtime.js +173 -0
- package/tests/run-tests.js +243 -0
package/index.html
CHANGED
|
@@ -1,286 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<
|
|
5
|
-
<
|
|
6
|
-
<
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Lumos Language Enhanced</title>
|
|
7
7
|
<style>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
iframe {
|
|
26
|
-
display: block;
|
|
27
|
-
margin: 0 auto;
|
|
28
|
-
}
|
|
29
|
-
img {
|
|
30
|
-
width: 10%;
|
|
31
|
-
height: 10%;
|
|
32
|
-
}
|
|
33
|
-
#output {
|
|
34
|
-
white-space: pre-wrap;
|
|
35
|
-
margin-top: 1em;
|
|
36
|
-
}
|
|
37
|
-
input[type="text"] {
|
|
38
|
-
width: 100%;
|
|
39
|
-
padding: 0.5em;
|
|
40
|
-
background: #2e2e2e;
|
|
41
|
-
color: white;
|
|
42
|
-
border: none;
|
|
43
|
-
}
|
|
44
|
-
.history-item {
|
|
45
|
-
cursor: pointer;
|
|
46
|
-
color: #9cdcfe;
|
|
47
|
-
}
|
|
48
|
-
#compileButton {
|
|
49
|
-
margin-top: 1em;
|
|
50
|
-
background: #007acc;
|
|
51
|
-
color: white;
|
|
52
|
-
border: none;
|
|
53
|
-
padding: 0.5em 1em;
|
|
54
|
-
cursor: pointer;
|
|
55
|
-
font-weight: bold;
|
|
56
|
-
}
|
|
57
|
-
#compileButton:hover {
|
|
58
|
-
background: #005f9e;
|
|
59
|
-
}
|
|
60
|
-
h5, #logo {
|
|
61
|
-
text-align: center;
|
|
62
|
-
}
|
|
63
|
-
.github {
|
|
64
|
-
mix-blend-mode: darken;
|
|
65
|
-
}
|
|
66
|
-
.npm {
|
|
67
|
-
mix-blend-mode: color;
|
|
68
|
-
}
|
|
69
|
-
.github, .npm {
|
|
70
|
-
width: 100px;
|
|
71
|
-
height: 100px;
|
|
72
|
-
}
|
|
73
|
-
</style>
|
|
74
|
-
</head>
|
|
75
|
-
<body>
|
|
76
|
-
<div class="header">
|
|
77
|
-
<img src="https://cdn.glitch.global/a6e15949-0cae-4ce8-a653-5883a6d0adc5/Lumos.png?v=1748865997035" />
|
|
78
|
-
<h1>Lumos Language</h1>
|
|
79
|
-
</div>
|
|
80
|
-
<h4>Press Enter / Return to execute your code.</h4>
|
|
81
|
-
<input type="text" id="input" placeholder="Enter command..." />
|
|
82
|
-
<button id="compileButton">Compile</button>
|
|
83
|
-
<br />
|
|
84
|
-
<h3>Usage</h3>
|
|
85
|
-
<iframe src="https://cdn.glitch.global/a6e15949-0cae-4ce8-a653-5883a6d0adc5/Lumos.pdf?v=1748869028196" width="80%" height="50%"></iframe>
|
|
86
|
-
<div id="output"></div>
|
|
87
|
-
<script>
|
|
88
|
-
class BreakException {}
|
|
89
|
-
class ContinueException {}
|
|
90
|
-
|
|
91
|
-
const vars = {};
|
|
92
|
-
const functions = {};
|
|
93
|
-
const history = [];
|
|
94
|
-
|
|
95
|
-
function evaluateExpression(expr) {
|
|
96
|
-
try {
|
|
97
|
-
return Function(...Object.keys(vars), `return (${expr})`)(...Object.values(vars));
|
|
98
|
-
} catch (e) {
|
|
99
|
-
throw new Error("Invalid expression: " + expr);
|
|
8
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
9
|
+
body {
|
|
10
|
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
11
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
12
|
+
color: #fff;
|
|
13
|
+
min-height: 100vh;
|
|
14
|
+
padding: 2rem;
|
|
15
|
+
}
|
|
16
|
+
.container {
|
|
17
|
+
max-width: 1200px;
|
|
18
|
+
margin: 0 auto;
|
|
19
|
+
background: rgba(255, 255, 255, 0.1);
|
|
20
|
+
backdrop-filter: blur(10px);
|
|
21
|
+
border-radius: 20px;
|
|
22
|
+
padding: 3rem;
|
|
23
|
+
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
|
100
24
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const timesRegex = /^(\d+)\.times\s+do\s+\|([a-zA-Z_][a-zA-Z0-9_]*)\|([\s\S]+?)end$/;
|
|
107
|
-
const timesMatch = command.match(timesRegex);
|
|
108
|
-
if (timesMatch) {
|
|
109
|
-
const count = parseInt(timesMatch[1]);
|
|
110
|
-
const varName = timesMatch[2];
|
|
111
|
-
const body = timesMatch[3].trim();
|
|
112
|
-
let result = "";
|
|
113
|
-
for (let i = 0; i < count; i++) {
|
|
114
|
-
vars[varName] = i;
|
|
115
|
-
result += interpret(body) + "\n";
|
|
116
|
-
}
|
|
117
|
-
return result.trim();
|
|
25
|
+
h1 {
|
|
26
|
+
font-size: 3.5rem;
|
|
27
|
+
margin-bottom: 1rem;
|
|
28
|
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
|
118
29
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (evaluateExpression(cond1)) return interpret(body1.trim());
|
|
125
|
-
if (cond2 && evaluateExpression(cond2)) return interpret(body2.trim());
|
|
126
|
-
if (body3) return interpret(body3.trim());
|
|
127
|
-
return "If condition was false.";
|
|
30
|
+
h2 {
|
|
31
|
+
font-size: 2rem;
|
|
32
|
+
margin-top: 2rem;
|
|
33
|
+
margin-bottom: 1rem;
|
|
34
|
+
color: #ffd700;
|
|
128
35
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (preprocessed !== null) return preprocessed;
|
|
136
|
-
|
|
137
|
-
command = command.trim();
|
|
138
|
-
|
|
139
|
-
if (/^let\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(.+)$/.test(command)) {
|
|
140
|
-
const [, name, value] = command.match(/^let\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*(.+)$/);
|
|
141
|
-
vars[name] = evaluateExpression(value);
|
|
142
|
-
return `${name} = ${vars[name]}`;
|
|
36
|
+
p { line-height: 1.8; margin-bottom: 1rem; font-size: 1.1rem; }
|
|
37
|
+
.features {
|
|
38
|
+
display: grid;
|
|
39
|
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
40
|
+
gap: 2rem;
|
|
41
|
+
margin: 2rem 0;
|
|
143
42
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
body: body.trim(),
|
|
150
|
-
};
|
|
151
|
-
return `Function ${name} defined.`;
|
|
43
|
+
.feature {
|
|
44
|
+
background: rgba(255, 255, 255, 0.15);
|
|
45
|
+
padding: 1.5rem;
|
|
46
|
+
border-radius: 10px;
|
|
47
|
+
transition: transform 0.3s;
|
|
152
48
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const [, name, argstr] = command.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\((.*)\)$/);
|
|
156
|
-
if (!functions[name]) throw new Error("Undefined function: " + name);
|
|
157
|
-
const func = functions[name];
|
|
158
|
-
const argValues = argstr.split(",").map((s) => evaluateExpression(s.trim()));
|
|
159
|
-
const localVars = {};
|
|
160
|
-
func.args.forEach((arg, i) => (localVars[arg] = argValues[i]));
|
|
161
|
-
|
|
162
|
-
const prevVars = Object.assign({}, vars);
|
|
163
|
-
Object.assign(vars, localVars);
|
|
164
|
-
|
|
165
|
-
let result;
|
|
166
|
-
try {
|
|
167
|
-
result = interpret(func.body);
|
|
168
|
-
} finally {
|
|
169
|
-
Object.assign(vars, prevVars);
|
|
170
|
-
}
|
|
171
|
-
return result;
|
|
49
|
+
.feature:hover {
|
|
50
|
+
transform: translateY(-5px);
|
|
172
51
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const vname = loopMatch[1];
|
|
177
|
-
const start = evaluateExpression(loopMatch[2]);
|
|
178
|
-
const end = evaluateExpression(loopMatch[3]);
|
|
179
|
-
const body = loopMatch[4];
|
|
180
|
-
|
|
181
|
-
for (let i = start; i <= end; i++) {
|
|
182
|
-
vars[vname] = i;
|
|
183
|
-
try {
|
|
184
|
-
interpret(body.trim());
|
|
185
|
-
} catch (e) {
|
|
186
|
-
if (e instanceof BreakException) break;
|
|
187
|
-
if (e instanceof ContinueException) continue;
|
|
188
|
-
throw e;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return `Looped ${vname} from ${start} to ${end}`;
|
|
52
|
+
.feature h3 {
|
|
53
|
+
color: #ffd700;
|
|
54
|
+
margin-bottom: 0.5rem;
|
|
192
55
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
while (evaluateExpression(condition)) {
|
|
200
|
-
try {
|
|
201
|
-
interpret(body.trim());
|
|
202
|
-
} catch (e) {
|
|
203
|
-
if (e instanceof BreakException) break;
|
|
204
|
-
if (e instanceof ContinueException) continue;
|
|
205
|
-
throw e;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return "While loop executed.";
|
|
56
|
+
code {
|
|
57
|
+
background: rgba(0, 0, 0, 0.3);
|
|
58
|
+
padding: 0.2rem 0.5rem;
|
|
59
|
+
border-radius: 4px;
|
|
60
|
+
font-family: 'Courier New', monospace;
|
|
209
61
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const input = document.getElementById("input");
|
|
218
|
-
const output = document.getElementById("output");
|
|
219
|
-
|
|
220
|
-
input.addEventListener("keydown", function (e) {
|
|
221
|
-
if (e.key === "Enter") {
|
|
222
|
-
const command = input.value.trim();
|
|
223
|
-
if (command === "") return;
|
|
224
|
-
|
|
225
|
-
history.push(command);
|
|
226
|
-
|
|
227
|
-
const historyItem = document.createElement("div");
|
|
228
|
-
historyItem.className = "history-item";
|
|
229
|
-
historyItem.textContent = command;
|
|
230
|
-
historyItem.onclick = () => {
|
|
231
|
-
input.value = command;
|
|
232
|
-
input.focus();
|
|
233
|
-
};
|
|
234
|
-
output.appendChild(historyItem);
|
|
235
|
-
|
|
236
|
-
try {
|
|
237
|
-
const result = interpret(command);
|
|
238
|
-
const resultDiv = document.createElement("div");
|
|
239
|
-
resultDiv.textContent = `> ${result}`;
|
|
240
|
-
output.appendChild(resultDiv);
|
|
241
|
-
} catch (err) {
|
|
242
|
-
const errorDiv = document.createElement("div");
|
|
243
|
-
errorDiv.textContent = `! ${err.message}`;
|
|
244
|
-
errorDiv.style.color = "red";
|
|
245
|
-
output.appendChild(errorDiv);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
input.value = "";
|
|
62
|
+
.code-block {
|
|
63
|
+
background: rgba(0, 0, 0, 0.5);
|
|
64
|
+
padding: 1.5rem;
|
|
65
|
+
border-radius: 10px;
|
|
66
|
+
overflow-x: auto;
|
|
67
|
+
margin: 1rem 0;
|
|
249
68
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
historyLine.className = "history-item";
|
|
261
|
-
historyLine.textContent = lineHeader + command;
|
|
262
|
-
output.appendChild(historyLine);
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
const result = interpret(command);
|
|
266
|
-
const resultDiv = document.createElement("div");
|
|
267
|
-
resultDiv.textContent = `> ${result}`;
|
|
268
|
-
output.appendChild(resultDiv);
|
|
269
|
-
} catch (err) {
|
|
270
|
-
const errorDiv = document.createElement("div");
|
|
271
|
-
errorDiv.textContent = `! ${err.message}`;
|
|
272
|
-
errorDiv.style.color = "red";
|
|
273
|
-
output.appendChild(errorDiv);
|
|
274
|
-
}
|
|
69
|
+
.button {
|
|
70
|
+
display: inline-block;
|
|
71
|
+
background: #ffd700;
|
|
72
|
+
color: #333;
|
|
73
|
+
padding: 1rem 2rem;
|
|
74
|
+
text-decoration: none;
|
|
75
|
+
border-radius: 50px;
|
|
76
|
+
font-weight: bold;
|
|
77
|
+
margin-top: 1rem;
|
|
78
|
+
transition: all 0.3s;
|
|
275
79
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
80
|
+
.button:hover {
|
|
81
|
+
background: #ffed4e;
|
|
82
|
+
transform: scale(1.05);
|
|
83
|
+
}
|
|
84
|
+
</style>
|
|
85
|
+
</head>
|
|
86
|
+
<body>
|
|
87
|
+
<div class="container">
|
|
88
|
+
<h1>✨ Lumos Language Enhanced</h1>
|
|
89
|
+
<p><strong>Version 2.0.0</strong> - Multi-Target Compiler & Interpreter</p>
|
|
90
|
+
|
|
91
|
+
<h2>Overview</h2>
|
|
92
|
+
<p>Lumos Language Enhanced is a comprehensive programming language that compiles to over 100 target languages, frameworks, and technologies. From assembly to web frameworks, from functional to imperative paradigms, Lumos supports it all.</p>
|
|
93
|
+
|
|
94
|
+
<div class="features">
|
|
95
|
+
<div class="feature">
|
|
96
|
+
<h3>🚀 Multi-Target Compilation</h3>
|
|
97
|
+
<p>Compile to Python, Rust, JavaScript, C++, Go, Java, and 95+ more languages</p>
|
|
98
|
+
</div>
|
|
99
|
+
<div class="feature">
|
|
100
|
+
<h3>💻 Interactive REPL</h3>
|
|
101
|
+
<p>Test code instantly with full multiline support and live compilation</p>
|
|
102
|
+
</div>
|
|
103
|
+
<div class="feature">
|
|
104
|
+
<h3>🏗️ Framework Support</h3>
|
|
105
|
+
<p>Generate code for Laravel, Django, React, Vue, Next.js, and more</p>
|
|
106
|
+
</div>
|
|
107
|
+
<div class="feature">
|
|
108
|
+
<h3>🔧 Full-Stack Ready</h3>
|
|
109
|
+
<p>Backend, frontend, database, and infrastructure code generation</p>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<h2>Quick Start</h2>
|
|
114
|
+
<div class="code-block">
|
|
115
|
+
<code>npm install lumos-language-enhanced<br>
|
|
116
|
+
lumos<br>
|
|
117
|
+
<br>
|
|
118
|
+
lumos> let x = 42<br>
|
|
119
|
+
lumos> def greet(name) { return "Hello, " + name }<br>
|
|
120
|
+
lumos> .compile python</code>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<h2>Supported Technologies</h2>
|
|
124
|
+
<p><strong>Languages:</strong> C, C++, Rust, Go, Java, C#, Python, Ruby, PHP, JavaScript, TypeScript, Haskell, Scala, Elixir, and many more...</p>
|
|
125
|
+
<p><strong>Frameworks:</strong> Laravel, Django, FastAPI, Express, NestJS, React, Vue, Next.js, Phoenix...</p>
|
|
126
|
+
<p><strong>Databases:</strong> PostgreSQL, MySQL, SQLite, MongoDB, Redis...</p>
|
|
127
|
+
|
|
128
|
+
<a href="README.md" class="button">View Documentation</a>
|
|
129
|
+
<a href="https://github.com/Uchida16104/Lumos-Language" class="button">GitHub Repository</a>
|
|
130
|
+
</div>
|
|
131
|
+
</body>
|
|
286
132
|
</html>
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lumos-language",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Lumos Language -
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "Lumos Language - Enhanced Multi-Target Compiler supporting 100+ languages",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"registry": "https://npm.pkg.github.com"
|
|
7
|
+
},
|
|
5
8
|
"main": "./index.cjs",
|
|
6
9
|
"bin": {
|
|
7
10
|
"lumos": "./index.cjs"
|
|
@@ -10,21 +13,28 @@
|
|
|
10
13
|
"type": "git",
|
|
11
14
|
"url": "git+https://github.com/Uchida16104/Lumos-Language.git"
|
|
12
15
|
},
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"@Uchida16104:registry": "https://npm.pkg.github.com"
|
|
15
|
-
},
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/Uchida16104/Lumos-Language/issues"
|
|
18
18
|
},
|
|
19
|
-
"homepage": "https://
|
|
19
|
+
"homepage": "https://uchida16104.github.io/Lumos-Language",
|
|
20
20
|
"author": "Hirotoshi Uchida",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"type": "commonjs",
|
|
23
23
|
"scripts": {
|
|
24
|
-
"start": "node ./index.cjs
|
|
25
|
-
"test": "
|
|
24
|
+
"start": "node ./index.cjs",
|
|
25
|
+
"test": "node tests/run.js",
|
|
26
|
+
"build": "echo 'Build complete'",
|
|
27
|
+
"dev": "node ./index.cjs"
|
|
26
28
|
},
|
|
27
29
|
"keywords": [
|
|
28
|
-
"programming-language"
|
|
29
|
-
|
|
30
|
+
"programming-language",
|
|
31
|
+
"compiler",
|
|
32
|
+
"interpreter",
|
|
33
|
+
"multi-target",
|
|
34
|
+
"transpiler",
|
|
35
|
+
"code-generation"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=14.0.0"
|
|
39
|
+
}
|
|
30
40
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Backend {
|
|
2
|
+
generate(ast, options = {}) {
|
|
3
|
+
this.output = [];
|
|
4
|
+
this.indent = 0;
|
|
5
|
+
this.generateNode(ast);
|
|
6
|
+
return this.output.join('\n');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
generateNode(node) {
|
|
10
|
+
if (!node) return '';
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'Program': return this.generateProgram(node);
|
|
13
|
+
case 'VariableDeclaration': return this.generateVariableDeclaration(node);
|
|
14
|
+
case 'FunctionDeclaration': return this.generateFunctionDeclaration(node);
|
|
15
|
+
default: return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
generateProgram(node) {
|
|
20
|
+
for (const stmt of node.statements) {
|
|
21
|
+
this.generateNode(stmt);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generateVariableDeclaration(node) {
|
|
26
|
+
const value = node.initializer ? this.generateNode(node.initializer) : 'null';
|
|
27
|
+
this.write(`var ${node.name} = ${value};`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generateFunctionDeclaration(node) {
|
|
31
|
+
this.write(`function ${node.name}() {}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
write(line) {
|
|
35
|
+
this.output.push(' '.repeat(this.indent) + line);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = new Backend();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Backend {
|
|
2
|
+
generate(ast, options = {}) {
|
|
3
|
+
this.output = [];
|
|
4
|
+
this.indent = 0;
|
|
5
|
+
this.generateNode(ast);
|
|
6
|
+
return this.output.join('\n');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
generateNode(node) {
|
|
10
|
+
if (!node) return '';
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'Program': return this.generateProgram(node);
|
|
13
|
+
case 'VariableDeclaration': return this.generateVariableDeclaration(node);
|
|
14
|
+
case 'FunctionDeclaration': return this.generateFunctionDeclaration(node);
|
|
15
|
+
default: return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
generateProgram(node) {
|
|
20
|
+
for (const stmt of node.statements) {
|
|
21
|
+
this.generateNode(stmt);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generateVariableDeclaration(node) {
|
|
26
|
+
const value = node.initializer ? this.generateNode(node.initializer) : 'null';
|
|
27
|
+
this.write(`var ${node.name} = ${value};`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generateFunctionDeclaration(node) {
|
|
31
|
+
this.write(`function ${node.name}() {}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
write(line) {
|
|
35
|
+
this.output.push(' '.repeat(this.indent) + line);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = new Backend();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Backend {
|
|
2
|
+
generate(ast, options = {}) {
|
|
3
|
+
this.output = [];
|
|
4
|
+
this.indent = 0;
|
|
5
|
+
this.generateNode(ast);
|
|
6
|
+
return this.output.join('\n');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
generateNode(node) {
|
|
10
|
+
if (!node) return '';
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'Program': return this.generateProgram(node);
|
|
13
|
+
case 'VariableDeclaration': return this.generateVariableDeclaration(node);
|
|
14
|
+
case 'FunctionDeclaration': return this.generateFunctionDeclaration(node);
|
|
15
|
+
default: return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
generateProgram(node) {
|
|
20
|
+
for (const stmt of node.statements) {
|
|
21
|
+
this.generateNode(stmt);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generateVariableDeclaration(node) {
|
|
26
|
+
const value = node.initializer ? this.generateNode(node.initializer) : 'null';
|
|
27
|
+
this.write(`var ${node.name} = ${value};`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generateFunctionDeclaration(node) {
|
|
31
|
+
this.write(`function ${node.name}() {}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
write(line) {
|
|
35
|
+
this.output.push(' '.repeat(this.indent) + line);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = new Backend();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Backend {
|
|
2
|
+
generate(ast, options = {}) {
|
|
3
|
+
this.output = [];
|
|
4
|
+
this.indent = 0;
|
|
5
|
+
this.generateNode(ast);
|
|
6
|
+
return this.output.join('\n');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
generateNode(node) {
|
|
10
|
+
if (!node) return '';
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'Program': return this.generateProgram(node);
|
|
13
|
+
case 'VariableDeclaration': return this.generateVariableDeclaration(node);
|
|
14
|
+
case 'FunctionDeclaration': return this.generateFunctionDeclaration(node);
|
|
15
|
+
default: return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
generateProgram(node) {
|
|
20
|
+
for (const stmt of node.statements) {
|
|
21
|
+
this.generateNode(stmt);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generateVariableDeclaration(node) {
|
|
26
|
+
const value = node.initializer ? this.generateNode(node.initializer) : 'null';
|
|
27
|
+
this.write(`var ${node.name} = ${value};`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generateFunctionDeclaration(node) {
|
|
31
|
+
this.write(`function ${node.name}() {}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
write(line) {
|
|
35
|
+
this.output.push(' '.repeat(this.indent) + line);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = new Backend();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Backend {
|
|
2
|
+
generate(ast, options = {}) {
|
|
3
|
+
this.output = [];
|
|
4
|
+
this.indent = 0;
|
|
5
|
+
this.generateNode(ast);
|
|
6
|
+
return this.output.join('\n');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
generateNode(node) {
|
|
10
|
+
if (!node) return '';
|
|
11
|
+
switch (node.type) {
|
|
12
|
+
case 'Program': return this.generateProgram(node);
|
|
13
|
+
case 'VariableDeclaration': return this.generateVariableDeclaration(node);
|
|
14
|
+
case 'FunctionDeclaration': return this.generateFunctionDeclaration(node);
|
|
15
|
+
default: return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
generateProgram(node) {
|
|
20
|
+
for (const stmt of node.statements) {
|
|
21
|
+
this.generateNode(stmt);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
generateVariableDeclaration(node) {
|
|
26
|
+
const value = node.initializer ? this.generateNode(node.initializer) : 'null';
|
|
27
|
+
this.write(`var ${node.name} = ${value};`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
generateFunctionDeclaration(node) {
|
|
31
|
+
this.write(`function ${node.name}() {}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
write(line) {
|
|
35
|
+
this.output.push(' '.repeat(this.indent) + line);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = new Backend();
|