@{ println(x) { print(x, "\n"); } treeCopy(x) { l = {}; k = _keys(x); if (k == null) { return clone(x); } else { for (i in k) { l[k[i]] = clone(treeCopy(x[k[i]])); } return clone(l); } } //------------ creation C structure ------------// newId(x) { treeCopy({ identifier: x, __proto__: C_id }); } newComment(com) { { text : com, __proto__: Comment }; } //--- Token ---// newToken(txt, com) { if (com == null) return { text: txt, comment: newComment(""), __proto__: Token }; { text: txt, comment: newComment(com), __proto__: Token }; } newSemicolon(com) { newToken(";", com) } newComma() { newToken(",", " "); } newStar(com) { newToken("*", com); } newBinary(com) { newToken("=", com); } //--- Declaration ---// newStruct() { { declarators: null, specifier: null, semicolon: newSemicolon("\n"), __proto__: C_declaration } // TO FIX } newDeclarators() {} //--- TO FIX ---// newEnum(x) { { attributeL: null, expression: null, name: newId(x), __proto__: C_enum }; } newFunction() {} //-------------------- end ---------------------// // adding the element e at the end of the list l append(s, e) { s[length(s)] = e; } // add or don't change an element in a dictionnary intern(s, e) { lo = 0; hi = length(s) - 1; while (lo <= hi) { mid = (lo+hi)/2; if (e > s[mid]) lo = mid + 1; else if (e < s[mid]) hi = mid - 1; else return e; } for (i = length(s); i > lo; i = i - 1) { s[i] = s[i-1]; } return s[lo] = e; } fusion(s1, s2) { for (i in s2) { append(s1, s2[i]); } return s1; // return treeCopy(s1); } // If g then we add a filter on the application of the function f to each element of seq map(f, seq, g) { out = {}; if (g) { for (i in seq) { e = seq[i]; if (g(e)) { e = f(e); } append(out, e); } } else { for (i in seq) { append(out, f(seq[i])); } } out; } notToken(x) { x.__proto__ != Token } // Select element e of s if the the result of the application of f on e is true select(f, s) { out = {}; for (i in s) { e = s[i]; if (f(e)) { append(out, e); } } out; } // Select element e of s if the the result of the application of f on e is false reject(f, s) { out = {}; for (i in s) { e = s[i]; if (!f(e)) { append(out, e); } } out; } // Get the last element of s last(s) { s[length(s)-1]; } nil; }