-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaxl.code
More file actions
364 lines (290 loc) · 9.49 KB
/
axl.code
File metadata and controls
364 lines (290 loc) · 9.49 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#ifndef AXL_TAXONOMY_H
#define AXL_TAXONOMY_H
/// Taxonomy categories for verb-noun classification
typedef enum TaxonomyCategory {
TAXONOMY_NONE = 0,
// Verb categories
VERB_IDENTITY, // Identification/declaration (let, const, var)
VERB_ACTION, // Actions (=, +, -, etc.)
VERB_STATE, // State verbs (is, has, etc.)
// Noun categories
NOUN_SUBJECT, // Subject nouns (identifiers on left side)
NOUN_OBJECT, // Object nouns (values, literals)
NOUN_MODIFIER // Modifiers (adjectives, etc.)
} TaxonomyCategory;
#endif // AXL_TAXONOMY_H#ifndef AXL_DAG_H
#define AXL_DAG_H
#include <stddef.h>
#include <stddef.h>
#include <axl/core/token.h> // For TokenType
#include <axl/core/taxonomy.h> // For TaxonomyCategory
// Forward declarations
typedef enum TokenType TokenType;
typedef enum TaxonomyCategory TaxonomyCategory;
/// Resolution states for semantic nodes.
typedef enum {
STATE_UNKNOWN = 0,
STATE_TRUE,
STATE_FALSE
} TruthValue;
/// Edge in the semantic DAG.
typedef struct DAGEdge {
struct DAGNode *target;
float weight; // Carries source node's weight
} DAGEdge;
/// Node in the semantic DAG.
/// One-to-one with a matched trie node.
typedef struct DAGNode {
TokenType type; // LET, IDENT, ASSIGN, LITERAL, etc.
TaxonomyCategory category; // Verb–noun tag
TruthValue state; // Resolved truth value
DAGEdge *in_edges; // Array of incoming edges
size_t in_count;
DAGEdge *out_edges; // Array of outgoing edges
size_t out_count;
} DAGNode;
/// Create an empty DAG node.
DAGNode* dag_node_create(TokenType t,
TaxonomyCategory cat);
/// Link `from` → `to` with given weight.
void dag_add_edge(DAGNode *from,
DAGNode *to,
float weight);
/// Topologically resolve all nodes' truth values.
void dag_resolve(DAGNode *nodes[],
size_t node_count);
/// Initialize the DAG subsystem
int dag_init(void);
#endif // AXL_DAG_H
// include/axl/core/integration/trie_dag.h
#ifndef AXL_TRIE_DAG_INTEGRATION_H
#define AXL_TRIE_DAG_INTEGRATION_H
#include <axl/core/trie.h>
#include <axl/core/dag.h>
// Forward declarations
struct DAGNode;
struct TrieNode;
// Minimal placeholder for compilation
bool execute_axl_with_busting(const char* axl_path, const char* axml_path);
#endif // AXL_TRIE_DAG_INTEGRATION_H
#ifndef AXL_TAXONOMY_H
#define AXL_TAXONOMY_H
/// Taxonomy categories for verb-noun classification
typedef enum TaxonomyCategory {
TAXONOMY_NONE = 0,
// Verb categories
VERB_IDENTITY, // Identification/declaration (let, const, var)
VERB_ACTION, // Actions (=, +, -, etc.)
VERB_STATE, // State verbs (is, has, etc.)
// Noun categories
NOUN_SUBJECT, // Subject nouns (identifiers on left side)
NOUN_OBJECT, // Object nouns (values, literals)
NOUN_MODIFIER // Modifiers (adjectives, etc.)
} TaxonomyCategory;
#endif // AXL_TAXONOMY_H#ifndef AXL_TRIE_H
#define AXL_TRIE_H
#include <stdbool.h>
#include <regex.h>
#include <axl/core/taxonomy.h>
#include <stdbool.h>
#include <regex.h>
/// A node in the regex-bound trie.
/// Each node matches a regex pattern (e.g. "let|const").
typedef struct TrieNode {
char *pattern_str; // Raw regex string
regex_t pattern; // Compiled regex
bool terminal; // Marks end of a token pattern
float weight; // Semantic ranking weight
TaxonomyCategory category; // Verb–noun classification
struct TrieNode *children[256]; // ASCII-indexed child pointers
} TrieNode;
/// Allocate and compile a new trie node.
/// pattern_str must outlive the node.
TrieNode* trie_node_create(const char *pattern_str,
TaxonomyCategory cat,
float weight);
/// Insert a pattern into the trie (recursively compiles sub-patterns).
void trie_insert(TrieNode *root,
const char *pattern_str,
TaxonomyCategory cat,
float weight);
/// Match `text[0..len)` against node->pattern.
bool trie_match_node(TrieNode *node,
const char *text,
size_t len);
/// Initialize the trie subsystem
int trie_init(void);
#endif // AXL_TRIE_H
#ifndef AXL_DAG_H
#define AXL_DAG_H
#include <stddef.h>
#include <stddef.h>
#include <axl/core/token.h> // For TokenType
#include <axl/core/taxonomy.h> // For TaxonomyCategory
// Forward declarations
typedef enum TokenType TokenType;
typedef enum TaxonomyCategory TaxonomyCategory;
/// Resolution states for semantic nodes.
typedef enum {
STATE_UNKNOWN = 0,
STATE_TRUE,
STATE_FALSE
} TruthValue;
/// Edge in the semantic DAG.
typedef struct DAGEdge {
struct DAGNode *target;
float weight; // Carries source node's weight
} DAGEdge;
/// Node in the semantic DAG.
/// One-to-one with a matched trie node.
typedef struct DAGNode {
TokenType type; // LET, IDENT, ASSIGN, LITERAL, etc.
TaxonomyCategory category; // Verb–noun tag
TruthValue state; // Resolved truth value
DAGEdge *in_edges; // Array of incoming edges
size_t in_count;
DAGEdge *out_edges; // Array of outgoing edges
size_t out_count;
} DAGNode;
/// Create an empty DAG node.
DAGNode* dag_node_create(TokenType t,
TaxonomyCategory cat);
/// Link `from` → `to` with given weight.
void dag_add_edge(DAGNode *from,
DAGNode *to,
float weight);
/// Topologically resolve all nodes' truth values.
void dag_resolve(DAGNode *nodes[],
size_t node_count);
/// Initialize the DAG subsystem
int dag_init(void);
#endif // AXL_DAG_H
#ifndef AXL_TOKEN_H
#define AXL_TOKEN_H
/// Token types for lexical analysis
typedef enum TokenType {
TOKEN_UNKNOWN = 0,
// Keywords
TOKEN_LET,
TOKEN_CONST,
TOKEN_VAR,
// Operators
TOKEN_ASSIGN,
TOKEN_PLUS,
TOKEN_MINUS,
// Identifiers and literals
TOKEN_IDENT,
TOKEN_LITERAL,
// Syntax elements
TOKEN_SEMICOLON,
TOKEN_LPAREN,
TOKEN_RPAREN
} TokenType;
#endif // AXL_TOKEN_H// include/axl/core/axml/parser.h
#ifndef AXL_AXML_PARSER_H
#define AXL_AXML_PARSER_H
#include <stdbool.h>
#include <axl/core/utils/memory.h>
typedef enum {
BUST_IMMEDIATE,
BUST_DELAYED,
BUST_CONDITIONAL
} BustPolicy;
typedef enum {
CARDINALITY_ZERO_ONE, // 0:1
CARDINALITY_ONE_ZERO, // 1:0
CARDINALITY_ONE_ONE, // 1:1
CARDINALITY_ONE_MANY, // 1:N
CARDINALITY_MANY_ONE, // N:1
CARDINALITY_MANY_MANY // N:M
} CardinalityType;
typedef struct AxmlBinding {
char* name;
char* value;
char** values;
size_t value_count;
CardinalityType cardinality;
struct AxmlBinding* next;
} AxmlBinding;
typedef struct AxmlConcept {
char* id;
AxmlBinding* bindings;
struct AxmlConcept* next;
} AxmlConcept;
typedef struct AxmlSymbol {
char* id;
char* visual;
struct AxmlSymbol* next;
} AxmlSymbol;
typedef struct AxmlConfig {
char* source_path;
BustPolicy bust_policy;
bool retain_memory;
AxmlConcept* concepts;
AxmlSymbol* symbols;
} AxmlConfig;
/**
* Parse an AXML configuration file
*/
AxmlConfig* axml_parse_file(const char* filename);
/**
* Free AXML configuration resources
*/
void axml_free_config(AxmlConfig* config);
#endif // AXL_AXML_PARSER_H
#ifndef AXL_TRIE_H
#define AXL_TRIE_H
#include <stdbool.h>
#include <regex.h>
#include <axl/core/taxonomy.h>
#include <stdbool.h>
#include <regex.h>
/// A node in the regex-bound trie.
/// Each node matches a regex pattern (e.g. "let|const").
typedef struct TrieNode {
char *pattern_str; // Raw regex string
regex_t pattern; // Compiled regex
bool terminal; // Marks end of a token pattern
float weight; // Semantic ranking weight
TaxonomyCategory category; // Verb–noun classification
struct TrieNode *children[256]; // ASCII-indexed child pointers
} TrieNode;
/// Allocate and compile a new trie node.
/// pattern_str must outlive the node.
TrieNode* trie_node_create(const char *pattern_str,
TaxonomyCategory cat,
float weight);
/// Insert a pattern into the trie (recursively compiles sub-patterns).
void trie_insert(TrieNode *root,
const char *pattern_str,
TaxonomyCategory cat,
float weight);
/// Match `text[0..len)` against node->pattern.
bool trie_match_node(TrieNode *node,
const char *text,
size_t len);
/// Initialize the trie subsystem
int trie_init(void);
#endif // AXL_TRIE_H
#ifndef AXL_TOKEN_H
#define AXL_TOKEN_H
/// Token types for lexical analysis
typedef enum TokenType {
TOKEN_UNKNOWN = 0,
// Keywords
TOKEN_LET,
TOKEN_CONST,
TOKEN_VAR,
// Operators
TOKEN_ASSIGN,
TOKEN_PLUS,
TOKEN_MINUS,
// Identifiers and literals
TOKEN_IDENT,
TOKEN_LITERAL,
// Syntax elements
TOKEN_SEMICOLON,
TOKEN_LPAREN,
TOKEN_RPAREN
} TokenType;
#endif // AXL_TOKEN_H