dirac-lang 0.1.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.
Files changed (110) hide show
  1. package/.env.example +8 -0
  2. package/COMMUNITY.md +465 -0
  3. package/LIBRARIES.md +172 -0
  4. package/NAMESPACES.md +366 -0
  5. package/PROMOTION.md +257 -0
  6. package/QUICKSTART-LIBRARY.md +93 -0
  7. package/README.md +257 -0
  8. package/config.yml +6 -0
  9. package/config.yml.openai +4 -0
  10. package/dirac-http/examples/demo.di +9 -0
  11. package/dirac-http/lib/index.di +12 -0
  12. package/dist/chunk-NDIRTD3D.js +217 -0
  13. package/dist/chunk-S625X7ME.js +1071 -0
  14. package/dist/cli.d.ts +1 -0
  15. package/dist/cli.js +261 -0
  16. package/dist/index.d.ts +144 -0
  17. package/dist/index.js +22 -0
  18. package/dist/session-4QG7OERD.js +42 -0
  19. package/examples/add-demo.di +74 -0
  20. package/examples/add.bk +11 -0
  21. package/examples/advanced-math-demo.di +53 -0
  22. package/examples/calculator.di +32 -0
  23. package/examples/comprehensive.bk +29 -0
  24. package/examples/defvar-variable-demo.di +18 -0
  25. package/examples/direct-call.di +17 -0
  26. package/examples/disk-analysis.di +16 -0
  27. package/examples/executable-hello.di +7 -0
  28. package/examples/execute-demo.di +38 -0
  29. package/examples/file-manager.di +77 -0
  30. package/examples/file-stats.di +18 -0
  31. package/examples/hello.bk +1 -0
  32. package/examples/hello.di +5 -0
  33. package/examples/import-demo.di +31 -0
  34. package/examples/inline-test.bk +7 -0
  35. package/examples/lib/advanced-math.di +81 -0
  36. package/examples/lib/fileops.di +26 -0
  37. package/examples/lib/math.di +25 -0
  38. package/examples/lib/mongodb.di +96 -0
  39. package/examples/llm-agent.di +32 -0
  40. package/examples/llm-basic.di +12 -0
  41. package/examples/llm-command-no-exec.di +13 -0
  42. package/examples/llm-command.di +13 -0
  43. package/examples/llm-complex.di +141 -0
  44. package/examples/llm-recursive.di +31 -0
  45. package/examples/llm-reflection-test.di +19 -0
  46. package/examples/llm-subs.di +132 -0
  47. package/examples/llm-use-subs.di +6 -0
  48. package/examples/loop.di +12 -0
  49. package/examples/math-test.di +22 -0
  50. package/examples/mongodb-count-events.di +8 -0
  51. package/examples/mongodb-import-demo.di +25 -0
  52. package/examples/mongodb-simple-test.di +18 -0
  53. package/examples/nl-agent.di +47 -0
  54. package/examples/parameters-demo.di +68 -0
  55. package/examples/params-test.di +10 -0
  56. package/examples/recipe-chain.di +38 -0
  57. package/examples/recursive-llm.di +44 -0
  58. package/examples/sample-library/README.md +152 -0
  59. package/examples/sample-library/examples/demo.di +34 -0
  60. package/examples/sample-library/lib/index.di +65 -0
  61. package/examples/sample-library/package.json +31 -0
  62. package/examples/seamless.di +45 -0
  63. package/examples/shell-test.bk +10 -0
  64. package/examples/simple-import.di +13 -0
  65. package/examples/simple-recursive.di +26 -0
  66. package/examples/story-builder.di +45 -0
  67. package/examples/subroutine.di +23 -0
  68. package/examples/system-llm.di +21 -0
  69. package/examples/system-simple.di +3 -0
  70. package/examples/system-test.di +13 -0
  71. package/examples/task-assistant.di +27 -0
  72. package/examples/test-parameters.di +50 -0
  73. package/examples/two-styles.di +28 -0
  74. package/examples/var-debug.di +6 -0
  75. package/examples/var-inline.di +4 -0
  76. package/examples/var-test2.di +6 -0
  77. package/examples/variable-simple.di +16 -0
  78. package/examples/variable-test.di +22 -0
  79. package/filePath +1 -0
  80. package/greeting.txt +1 -0
  81. package/package.json +41 -0
  82. package/src/cli.ts +118 -0
  83. package/src/index.ts +33 -0
  84. package/src/llm/ollama.ts +58 -0
  85. package/src/runtime/braket-parser.ts +234 -0
  86. package/src/runtime/interpreter.ts +135 -0
  87. package/src/runtime/parser.ts +151 -0
  88. package/src/runtime/session.ts +228 -0
  89. package/src/tags/assign.ts +37 -0
  90. package/src/tags/call.ts +156 -0
  91. package/src/tags/defvar.ts +56 -0
  92. package/src/tags/eval.ts +68 -0
  93. package/src/tags/execute.ts +52 -0
  94. package/src/tags/expr.ts +128 -0
  95. package/src/tags/if.ts +58 -0
  96. package/src/tags/import.ts +66 -0
  97. package/src/tags/index.ts +37 -0
  98. package/src/tags/llm.ts +207 -0
  99. package/src/tags/loop.ts +43 -0
  100. package/src/tags/mongodb.ts +70 -0
  101. package/src/tags/output.ts +23 -0
  102. package/src/tags/parameters.ts +79 -0
  103. package/src/tags/require_module.ts +19 -0
  104. package/src/tags/subroutine.ts +52 -0
  105. package/src/tags/system.ts +70 -0
  106. package/src/tags/variable.ts +25 -0
  107. package/src/types/index.ts +101 -0
  108. package/src/utils/llm-adapter.ts +113 -0
  109. package/tools/create-library.sh +175 -0
  110. package/tsconfig.json +19 -0
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,261 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ execute
4
+ } from "./chunk-S625X7ME.js";
5
+ import "./chunk-NDIRTD3D.js";
6
+
7
+ // src/cli.ts
8
+ import "dotenv/config";
9
+ import fs from "fs";
10
+ import yaml from "js-yaml";
11
+ import { resolve, extname } from "path";
12
+
13
+ // src/runtime/braket-parser.ts
14
+ var BraKetParser = class {
15
+ lines = [];
16
+ currentLine = 0;
17
+ /**
18
+ * Parse bra-ket notation and compile to XML
19
+ */
20
+ parse(source) {
21
+ this.lines = source.split("\n");
22
+ this.currentLine = 0;
23
+ const xml = ["<dirac>"];
24
+ this.parseBlock(xml, -1);
25
+ xml.push("</dirac>");
26
+ return xml.join("\n");
27
+ }
28
+ /**
29
+ * Parse a block of lines at a given indentation level
30
+ */
31
+ parseBlock(output, parentIndent) {
32
+ while (this.currentLine < this.lines.length) {
33
+ const line = this.parseLine(this.lines[this.currentLine]);
34
+ if (line.type === "empty") {
35
+ this.currentLine++;
36
+ continue;
37
+ }
38
+ if (line.indent <= parentIndent) {
39
+ break;
40
+ }
41
+ if (line.type === "bra") {
42
+ const attrs = line.attrs ? ` ${this.convertAttributes(line.attrs)}` : "";
43
+ output.push(`${" ".repeat(line.indent)}<subroutine name="${line.tag}"${attrs}>`);
44
+ this.currentLine++;
45
+ this.parseBlock(output, line.indent);
46
+ output.push(`${" ".repeat(line.indent)}</subroutine>`);
47
+ continue;
48
+ }
49
+ if (line.type === "ket") {
50
+ const indent = " ".repeat(line.indent);
51
+ const attrs = line.attrs ? ` ${this.convertAttributes(line.attrs)}` : "";
52
+ const nextLine = this.currentLine + 1 < this.lines.length ? this.parseLine(this.lines[this.currentLine + 1]) : null;
53
+ if (nextLine && nextLine.indent > line.indent && nextLine.type !== "empty") {
54
+ output.push(`${indent}<${line.tag}${attrs}>`);
55
+ this.currentLine++;
56
+ this.parseBlock(output, line.indent);
57
+ output.push(`${indent}</${line.tag}>`);
58
+ } else {
59
+ if (line.text) {
60
+ const content = this.convertInlineKets(line.text);
61
+ output.push(`${indent}<${line.tag}${attrs}>${content}</${line.tag}>`);
62
+ } else {
63
+ output.push(`${indent}<${line.tag}${attrs}/>`);
64
+ }
65
+ this.currentLine++;
66
+ }
67
+ continue;
68
+ }
69
+ if (line.type === "text") {
70
+ const indent = " ".repeat(line.indent);
71
+ const content = this.convertInlineKets(line.text || "");
72
+ output.push(`${indent}${content}`);
73
+ this.currentLine++;
74
+ continue;
75
+ }
76
+ }
77
+ }
78
+ /**
79
+ * Parse a single line into structured form
80
+ */
81
+ parseLine(raw) {
82
+ const match = raw.match(/^(\s*)(.*)/);
83
+ const indent = match ? Math.floor(match[1].length / 2) : 0;
84
+ const content = match ? match[2] : "";
85
+ if (!content.trim()) {
86
+ return { indent, type: "empty", raw };
87
+ }
88
+ const braMatch = content.match(/^<([a-zA-Z_][a-zA-Z0-9_-]*)\s*([^|]*)\|$/);
89
+ if (braMatch) {
90
+ return {
91
+ indent,
92
+ type: "bra",
93
+ tag: braMatch[1],
94
+ attrs: braMatch[2].trim() || void 0,
95
+ raw
96
+ };
97
+ }
98
+ const ketMatch = content.match(/^\|([a-zA-Z_][a-zA-Z0-9_-]*)\s*([^>]*?)>\s*(.*)/);
99
+ if (ketMatch) {
100
+ return {
101
+ indent,
102
+ type: "ket",
103
+ tag: ketMatch[1],
104
+ attrs: ketMatch[2].trim() || void 0,
105
+ text: ketMatch[3] || void 0,
106
+ raw
107
+ };
108
+ }
109
+ return {
110
+ indent,
111
+ type: "text",
112
+ text: content,
113
+ raw
114
+ };
115
+ }
116
+ /**
117
+ * Convert bra-ket attribute syntax to XML
118
+ * Examples:
119
+ * name=value → name="value"
120
+ * x=5 y=10 → x="5" y="10"
121
+ * select=@* → select="@*"
122
+ */
123
+ convertAttributes(attrs) {
124
+ if (!attrs) return "";
125
+ const parts = [];
126
+ let current = "";
127
+ let inQuotes = false;
128
+ let quoteChar = "";
129
+ for (let i = 0; i < attrs.length; i++) {
130
+ const char = attrs[i];
131
+ if ((char === '"' || char === "'") && (i === 0 || attrs[i - 1] !== "\\")) {
132
+ if (!inQuotes) {
133
+ inQuotes = true;
134
+ quoteChar = char;
135
+ current += char;
136
+ } else if (char === quoteChar) {
137
+ inQuotes = false;
138
+ current += char;
139
+ } else {
140
+ current += char;
141
+ }
142
+ } else if (char === " " && !inQuotes) {
143
+ if (current.trim()) {
144
+ parts.push(current.trim());
145
+ current = "";
146
+ }
147
+ } else {
148
+ current += char;
149
+ }
150
+ }
151
+ if (current.trim()) {
152
+ parts.push(current.trim());
153
+ }
154
+ return parts.map((part) => {
155
+ const match = part.match(/^([a-zA-Z_][a-zA-Z0-9_-]*)=(.+)$/);
156
+ if (!match) return part;
157
+ const [, name, value] = match;
158
+ if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
159
+ return `${name}=${value}`;
160
+ }
161
+ return `${name}="${value}"`;
162
+ }).join(" ");
163
+ }
164
+ /**
165
+ * Convert inline kets within text content
166
+ * Example: "Hello |variable name=x> world" → "Hello <variable name="x"/> world"
167
+ */
168
+ convertInlineKets(text) {
169
+ return text.replace(/\|([a-zA-Z_][a-zA-Z0-9_-]*)\s*([^>]*?)>/g, (match, tag, attrs) => {
170
+ const attrStr = attrs.trim() ? ` ${this.convertAttributes(attrs.trim())}` : "";
171
+ return `<${tag}${attrStr}/>`;
172
+ });
173
+ }
174
+ };
175
+
176
+ // src/cli.ts
177
+ async function main() {
178
+ const args = process.argv.slice(2);
179
+ if (args.length === 0) {
180
+ console.error("Usage: dirac <file.di|file.bk>");
181
+ console.error("");
182
+ console.error("File formats:");
183
+ console.error(" .di XML notation (verbose)");
184
+ console.error(" .bk Bra-ket notation (compact)");
185
+ console.error("");
186
+ console.error("Options:");
187
+ console.error(" --debug Enable debug output");
188
+ console.error(" --emit-xml Output intermediate XML (for .bk files)");
189
+ console.error(" --model <name> Set default LLM model");
190
+ console.error(" --max-llm <n> Maximum LLM calls (default: 100)");
191
+ console.error(" --max-depth <n> Maximum recursion depth (default: 50)");
192
+ process.exit(1);
193
+ }
194
+ const config = {};
195
+ let filePath;
196
+ let emitXml = false;
197
+ let configFile;
198
+ for (let i = 0; i < args.length; i++) {
199
+ const arg = args[i];
200
+ if (arg === "--debug") {
201
+ config.debug = true;
202
+ } else if (arg === "--emit-xml") {
203
+ emitXml = true;
204
+ } else if (arg === "--model" && i + 1 < args.length) {
205
+ config.model = args[++i];
206
+ } else if (arg === "--provider" && i + 1 < args.length) {
207
+ config.llmProvider = args[++i];
208
+ } else if ((arg === "-f" || arg === "--config") && i + 1 < args.length) {
209
+ configFile = args[++i];
210
+ } else if (arg === "--max-llm" && i + 1 < args.length) {
211
+ config.maxLLMCalls = parseInt(args[++i], 10);
212
+ } else if (arg === "--max-depth" && i + 1 < args.length) {
213
+ config.maxDepth = parseInt(args[++i], 10);
214
+ } else if (!arg.startsWith("--")) {
215
+ filePath = arg;
216
+ }
217
+ }
218
+ if (configFile) {
219
+ try {
220
+ const loadedConfig = yaml.load(fs.readFileSync(resolve(configFile), "utf8")) || {};
221
+ Object.assign(config, loadedConfig);
222
+ } catch (err) {
223
+ console.error("Failed to load config file:", err);
224
+ process.exit(1);
225
+ }
226
+ }
227
+ if (!filePath) {
228
+ console.error("Error: No input file specified");
229
+ process.exit(1);
230
+ }
231
+ try {
232
+ const fullPath = resolve(process.cwd(), filePath);
233
+ let source = fs.readFileSync(fullPath, "utf-8");
234
+ const ext = extname(fullPath);
235
+ if (ext === ".bk") {
236
+ if (config.debug) {
237
+ console.error(`[Dirac] Compiling bra-ket notation to XML`);
238
+ }
239
+ const braketParser = new BraKetParser();
240
+ const xml = braketParser.parse(source);
241
+ if (emitXml) {
242
+ console.log(xml);
243
+ return;
244
+ }
245
+ source = xml;
246
+ }
247
+ if (config.debug) {
248
+ console.error(`[Dirac] Executing ${fullPath}`);
249
+ }
250
+ config.filePath = fullPath;
251
+ const result = await execute(source, config);
252
+ process.stdout.write(result);
253
+ } catch (error) {
254
+ console.error("Error:", error instanceof Error ? error.message : String(error));
255
+ if (config.debug && error instanceof Error && error.stack) {
256
+ console.error(error.stack);
257
+ }
258
+ process.exit(1);
259
+ }
260
+ }
261
+ main();
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Core types for Dirac interpreter
3
+ * Directly based on MASK C implementation
4
+ */
5
+ interface DiracElement {
6
+ tag: string;
7
+ attributes: Record<string, string>;
8
+ children: DiracElement[];
9
+ text?: string;
10
+ }
11
+ /**
12
+ * Variable info - maps to VarInfo in MASK
13
+ */
14
+ interface Variable {
15
+ name: string;
16
+ value: any;
17
+ visible: boolean;
18
+ boundary: number;
19
+ passby: 'value' | 'ref';
20
+ refName?: string;
21
+ }
22
+ /**
23
+ * Parameter metadata for introspection
24
+ */
25
+ interface ParameterMetadata {
26
+ name: string;
27
+ type?: string;
28
+ required?: boolean;
29
+ description?: string;
30
+ enum?: string[];
31
+ }
32
+ /**
33
+ * Subroutine info - maps to Subroutine in MASK
34
+ */
35
+ interface Subroutine {
36
+ name: string;
37
+ element: DiracElement;
38
+ boundary: number;
39
+ extends?: string;
40
+ description?: string;
41
+ parameters?: ParameterMetadata[];
42
+ }
43
+ /**
44
+ * Execution context - maps to MaskSession in MASK
45
+ */
46
+ interface DiracSession {
47
+ variables: Variable[];
48
+ subroutines: Subroutine[];
49
+ varBoundary: number;
50
+ subBoundary: number;
51
+ parameterStack: DiracElement[][];
52
+ output: string[];
53
+ llmClient?: any;
54
+ limits: {
55
+ maxLLMCalls: number;
56
+ currentLLMCalls: number;
57
+ maxDepth: number;
58
+ currentDepth: number;
59
+ };
60
+ isReturn: boolean;
61
+ isBreak: boolean;
62
+ debug: boolean;
63
+ currentFile?: string;
64
+ importedFiles?: Set<string>;
65
+ }
66
+ interface DiracConfig {
67
+ apiKey?: string;
68
+ model?: string;
69
+ debug?: boolean;
70
+ maxLLMCalls?: number;
71
+ maxDepth?: number;
72
+ filePath?: string;
73
+ llmProvider?: string;
74
+ llmModel?: string;
75
+ }
76
+
77
+ /**
78
+ * XML Parser for Dirac (.di files)
79
+ */
80
+
81
+ declare class DiracParser {
82
+ private parser;
83
+ constructor();
84
+ parse(source: string): DiracElement;
85
+ private convertOrderedToElement;
86
+ private convertToElement;
87
+ }
88
+
89
+ /**
90
+ * Session management - maps to MASK session functions
91
+ */
92
+
93
+ declare function createSession(config?: DiracConfig): DiracSession;
94
+ declare function getOutput(session: DiracSession): string;
95
+ declare function getAvailableSubroutines(session: DiracSession): Array<{
96
+ name: string;
97
+ description?: string;
98
+ parameters?: Array<{
99
+ name: string;
100
+ type?: string;
101
+ required?: boolean;
102
+ description?: string;
103
+ enum?: string[];
104
+ }>;
105
+ }>;
106
+
107
+ /**
108
+ * Core interpreter - maps to mask_integrate in MASK
109
+ */
110
+
111
+ declare function integrate(session: DiracSession, element: DiracElement): Promise<void>;
112
+
113
+ /**
114
+ * LLM Adapter - Auto-generate prompts and JSON→XML converters
115
+ * from Dirac subroutine definitions
116
+ */
117
+
118
+ interface LLMPromptGenerator {
119
+ generatePrompt(userInput: string): string;
120
+ intentToXML(intent: any): string | null;
121
+ }
122
+ /**
123
+ * Create LLM adapter from session's registered subroutines
124
+ */
125
+ declare function createLLMAdapter(session: DiracSession): LLMPromptGenerator;
126
+ /**
127
+ * Higher-level helper: execute user command via LLM
128
+ */
129
+ declare function executeUserCommand(session: DiracSession, userInput: string, llmExecuteFn: (prompt: string) => Promise<string>): Promise<{
130
+ success: boolean;
131
+ xml?: string;
132
+ error?: string;
133
+ }>;
134
+
135
+ /**
136
+ * Main entry point for Dirac interpreter
137
+ */
138
+
139
+ /**
140
+ * Execute Dirac source code
141
+ */
142
+ declare function execute(source: string, config?: DiracConfig): Promise<string>;
143
+
144
+ export { type DiracConfig, type DiracElement, DiracParser, type DiracSession, type LLMPromptGenerator, type ParameterMetadata, createLLMAdapter, createSession, execute, executeUserCommand, getAvailableSubroutines, getOutput, integrate };
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import {
2
+ DiracParser,
3
+ createLLMAdapter,
4
+ execute,
5
+ executeUserCommand,
6
+ integrate
7
+ } from "./chunk-S625X7ME.js";
8
+ import {
9
+ createSession,
10
+ getAvailableSubroutines,
11
+ getOutput
12
+ } from "./chunk-NDIRTD3D.js";
13
+ export {
14
+ DiracParser,
15
+ createLLMAdapter,
16
+ createSession,
17
+ execute,
18
+ executeUserCommand,
19
+ getAvailableSubroutines,
20
+ getOutput,
21
+ integrate
22
+ };
@@ -0,0 +1,42 @@
1
+ import {
2
+ cleanSubroutinesToBoundary,
3
+ cleanToBoundary,
4
+ createSession,
5
+ emit,
6
+ getAvailableSubroutines,
7
+ getCurrentParameters,
8
+ getOutput,
9
+ getSubroutine,
10
+ getVariable,
11
+ hasVariable,
12
+ popParameters,
13
+ popSubroutinesToBoundary,
14
+ popToBoundary,
15
+ pushParameters,
16
+ registerSubroutine,
17
+ setBoundary,
18
+ setSubroutineBoundary,
19
+ setVariable,
20
+ substituteVariables
21
+ } from "./chunk-NDIRTD3D.js";
22
+ export {
23
+ cleanSubroutinesToBoundary,
24
+ cleanToBoundary,
25
+ createSession,
26
+ emit,
27
+ getAvailableSubroutines,
28
+ getCurrentParameters,
29
+ getOutput,
30
+ getSubroutine,
31
+ getVariable,
32
+ hasVariable,
33
+ popParameters,
34
+ popSubroutinesToBoundary,
35
+ popToBoundary,
36
+ pushParameters,
37
+ registerSubroutine,
38
+ setBoundary,
39
+ setSubroutineBoundary,
40
+ setVariable,
41
+ substituteVariables
42
+ };
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env dirac
2
+ <dirac>
3
+ <!--
4
+ Method 1: Using <expr> tag (clean, declarative)
5
+ -->
6
+ <subroutine name="ADD">
7
+ <expr eval="plus">
8
+ <arg><parameters select="@x"/></arg>
9
+ <arg><parameters select="@y"/></arg>
10
+ </expr>
11
+ </subroutine>
12
+
13
+ <output>Method 1 (expr tag):&#10;</output>
14
+ <output> 1 + 2 = </output>
15
+ <ADD x="1" y="2"/>
16
+ <output>&#10;</output>
17
+
18
+ <output> 5 + 7 = </output>
19
+ <ADD x="5" y="7"/>
20
+ <output>&#10;</output>
21
+
22
+ <output> 100 + 200 = </output>
23
+ <ADD x="100" y="200"/>
24
+ <output>&#10;</output>
25
+
26
+ <!--
27
+ Method 2: Using getParams() in eval (programmatic)
28
+ -->
29
+ <subroutine name="MULTIPLY">
30
+ <eval>
31
+ const caller = getParams();
32
+ if (caller && caller.attributes) {
33
+ const x = parseInt(caller.attributes.x || 0);
34
+ const y = parseInt(caller.attributes.y || 0);
35
+ console.log(x * y);
36
+ }
37
+ </eval>
38
+ </subroutine>
39
+
40
+ <output>&#10;Method 2 (eval with getParams):&#10;</output>
41
+ <output>3 * 4 = </output>
42
+ <MULTIPLY x="3" y="4"/>
43
+ <output>&#10;</output>
44
+
45
+ <output>5 * 6 = </output>
46
+ <MULTIPLY x="5" y="6"/>
47
+ <output>&#10;</output>
48
+
49
+ <!-- More expr examples -->
50
+ <output>&#10;More operations:&#10;</output>
51
+ <output>10 - 3 = </output>
52
+ <expr eval="minus"><arg>10</arg><arg>3</arg></expr>
53
+ <output>&#10;</output>
54
+
55
+ <output>7 * 8 = </output>
56
+ <expr eval="times"><arg>7</arg><arg>8</arg></expr>
57
+ <output>&#10;</output>
58
+
59
+ <output>20 / 4 = </output>
60
+ <expr eval="divide"><arg>20</arg><arg>4</arg></expr>
61
+ <output>&#10;</output>
62
+
63
+ <output>17 mod 5 = </output>
64
+ <expr eval="mod"><arg>17</arg><arg>5</arg></expr>
65
+ <output>&#10;</output>
66
+
67
+ <output>5 &lt; 10 = </output>
68
+ <expr eval="lt"><arg>5</arg><arg>10</arg></expr>
69
+ <output>&#10;</output>
70
+
71
+ <output>5 &gt; 10 = </output>
72
+ <expr eval="gt"><arg>5</arg><arg>10</arg></expr>
73
+ <output>&#10;</output>
74
+ </dirac>
@@ -0,0 +1,11 @@
1
+ <add|
2
+ |parameters select=@x>
3
+ |parameters select=@y>
4
+ |expr op=plus>
5
+ |arg>
6
+ |variable name=x>
7
+ |arg>
8
+ |variable name=y>
9
+
10
+ |output>5 + 3 =
11
+ |add x=5 y=3>
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env dirac
2
+ <dirac>
3
+ <!-- Import advanced math library -->
4
+ <import src="./lib/advanced-math.di"/>
5
+
6
+ <output>Advanced Math Library Demo&#10;&#10;</output>
7
+
8
+ <!-- Square root -->
9
+ <output>Square root of 16: </output>
10
+ <MATH_SQRT n="16"/>
11
+ <output>&#10;</output>
12
+
13
+ <output>Square root of 2: </output>
14
+ <MATH_SQRT n="2"/>
15
+ <output>&#10;</output>
16
+
17
+ <!-- Factorial -->
18
+ <output>Factorial of 5: </output>
19
+ <MATH_FACTORIAL n="5"/>
20
+ <output>&#10;</output>
21
+
22
+ <output>Factorial of 10: </output>
23
+ <MATH_FACTORIAL n="10"/>
24
+ <output>&#10;</output>
25
+
26
+ <!-- GCD -->
27
+ <output>GCD(48, 18): </output>
28
+ <MATH_GCD a="48" b="18"/>
29
+ <output>&#10;</output>
30
+
31
+ <output>GCD(100, 35): </output>
32
+ <MATH_GCD a="100" b="35"/>
33
+ <output>&#10;</output>
34
+
35
+ <!-- Prime check -->
36
+ <output>Is 17 prime? </output>
37
+ <MATH_PRIME n="17"/>
38
+ <output>&#10;</output>
39
+
40
+ <output>Is 20 prime? </output>
41
+ <MATH_PRIME n="20"/>
42
+ <output>&#10;</output>
43
+
44
+ <!-- Random number -->
45
+ <output>Random number [0-100]: </output>
46
+ <MATH_RANDOM min="0" max="100"/>
47
+ <output>&#10;</output>
48
+
49
+ <!-- Statistics -->
50
+ <output>&#10;Statistics for [1,2,3,4,5,10,100]:&#10;</output>
51
+ <MATH_STATS data="[1,2,3,4,5,10,100]"/>
52
+ <output>&#10;</output>
53
+ </dirac>
@@ -0,0 +1,32 @@
1
+ ```xml
2
+ <?xml version="1.0"?>
3
+ <!-- Basic Arithmetic Calculator -->
4
+ <dirac>
5
+ <!-- Declaration of variables -->
6
+ <defvar name="num1" value="0" />
7
+ <defvar name="num2" value="0" />
8
+ <defvar name="result" value="0" />
9
+ <defvar name="operation" value="" />
10
+
11
+ <!-- User input for first number -->
12
+ <LLM output="num1">Please enter the first number:</LLM>
13
+
14
+ <!-- User input for second number -->
15
+ <LLM output="num2">Please enter the second number:</LLM>
16
+
17
+ <!-- User input for the operation -->
18
+ <LLM output="operation">Please choose the operation (+, -, *, /):</LLM>
19
+
20
+ <!-- Perform selected operation -->
21
+ <if test="${operation} == '+'">
22
+ <set var="result" value="${num1} + ${num2}" />
23
+ </if>
24
+ <if test="${operation} == '-'">
25
+ <set var="result" value="${num1} - ${num2}" />
26
+ </if>
27
+ <if test="${operation} == '*'">
28
+ <set var="result" value="${num1} * ${num2}" />
29
+ </if>
30
+ <if test="${operation} == '/'">
31
+ <if test="${num2} == 0">
32
+ <output>Division by zero is not allowed.</output>
@@ -0,0 +1,29 @@
1
+ |output>Bra-Ket Notation Demo
2
+
3
+ <factorial|
4
+ |parameters select=@n>
5
+ |variable name=n>
6
+ |if>
7
+ |expr op=eq>
8
+ |arg>
9
+ |variable name=n>
10
+ |arg>1
11
+ |output>1
12
+ |expr op=times>
13
+ |arg>
14
+ |variable name=n>
15
+ |arg>
16
+ |factorial>
17
+ |expr op=minus>
18
+ |arg>
19
+ |variable name=n>
20
+ |arg>1
21
+
22
+ |output>Factorial of 5 =
23
+ |factorial n=5>
24
+ |output>
25
+
26
+ <format|
27
+ |output>Name: |variable name=name>, Age: |variable name=age>
28
+
29
+ |format name=Alice age=30>
@@ -0,0 +1,18 @@
1
+ <dirac>
2
+ <!-- Simple example: defvar sets, variable gets -->
3
+ <defvar name="greeting">Hello, World!</defvar>
4
+ <output><variable name="greeting"/></output>
5
+ <output>&#10;</output>
6
+
7
+ <!-- Subroutine with parameter -->
8
+ <subroutine name="greet">
9
+ <parameters select="@name">
10
+ <defvar name="localname"/>
11
+ </parameters>
12
+ <output>Greetings, <variable name="localname"/>!</output>
13
+ </subroutine>
14
+
15
+ <greet name="Alice"/>
16
+ <output>&#10;</output>
17
+ <greet name="Bob"/>
18
+ </dirac>