From 5eb974e1ec60ebe9c7e173020ec8f362899ada95 Mon Sep 17 00:00:00 2001 From: Theo Souchon Date: Fri, 24 Feb 2023 12:43:07 +0900 Subject: [PATCH] Fixing println and other stuff --- AUTHORS | 3 + README.md | 5 +- src/ccmeta.leg | 25 ++-- src/parsimonyLibrary/boot.mc | 243 +++++++++++++++++++---------------- 4 files changed, 153 insertions(+), 123 deletions(-) diff --git a/AUTHORS b/AUTHORS index d4d2519..af34221 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,3 +11,6 @@ Mahe Tardy (2020) Nathan Razafimanantsoa, Kumar Mahadayya (2021) C AST + +Theo Souchon (2022-2023) + ? diff --git a/README.md b/README.md index 3980493..6d2c52b 100644 --- a/README.md +++ b/README.md @@ -88,4 +88,7 @@ $ man peg - metalanguage implementation #### Nathan Razafimanantsoa, Kumar Mahadayya (2021) -- C AST \ No newline at end of file +- C AST + +#### Theo Souchon (2022-2023) +- ? \ No newline at end of file diff --git a/src/ccmeta.leg b/src/ccmeta.leg index 4bacac4..2aa5018 100644 --- a/src/ccmeta.leg +++ b/src/ccmeta.leg @@ -3665,6 +3665,7 @@ void printTree(oop element, language id); void readEvalPrint(oop scope, char *fileName) { + // TODO inputStackPush(fileName); input_t *top= inputStack; jbRecPush(); @@ -3758,6 +3759,7 @@ oop prim_scope(oop scope, oop params) return fixScope(scope); } +// TODO oop prim_parseFrom(oop scope, oop params) { if (map_size(params) != 1) return null; @@ -3767,23 +3769,23 @@ oop prim_parseFrom(oop scope, oop params) struct _yycontext *yy = yyctx; if (!strcmp(s, "declaration")) { oop res = yyparsefrom(yy_declaration) ? __ : null ; - yylval = res; // TODO + yylval = res; return res; } else if (!strcmp(s, "expression")) { oop res = yyparsefrom(yy_expression) ? __ : null ; - yylval = res; // TODO + yylval = res; return res; } else if (!strcmp(s, "statement")) { oop res = yyparsefrom(yy_statement) ? __ : null ; - yylval = res; // TODO + yylval = res; return res; } else if (!strcmp(s, "id")) { oop res = yyparsefrom(yy_id) ? __ : null ; - yylval = res; // TODO + yylval = res; return res; } else if (!strcmp(s, "func")) { oop res = yyparsefrom(yy_functionDefinition) ? __ : null ; - yylval = res; // TODO + yylval = res; return res; } printf("%s expected\n", s); @@ -4810,11 +4812,9 @@ void printTree(oop element, language id) { printf("\n"); } - - -int main(int argc, char **argv) +void init() { -# if (USE_GC) + # if (USE_GC) GC_INIT(); # endif @@ -4879,8 +4879,13 @@ int main(int argc, char **argv) fixScope(globals); - /* File scope */ + /* File scope */ pushScope(); +} + +int main(int argc, char **argv) +{ + init(); int repled = 0; /* Checking arguments */ diff --git a/src/parsimonyLibrary/boot.mc b/src/parsimonyLibrary/boot.mc index dc6dbc2..2af2c20 100644 --- a/src/parsimonyLibrary/boot.mc +++ b/src/parsimonyLibrary/boot.mc @@ -1,142 +1,161 @@ @{ - println(x) { print(x, "\n"); } + println() { + apply(print, __arguments__); + print("\n"); + __arguments__; + } - //------------ creation C structure ------------// + __requires__ = {}; - newId(x, comm) { - if (comm == null) { - { identifier: x, __proto__: C_id }; - } else { - { identifier: x, comment: { text : comm, __proto__: Comment }, __proto__: C_id }; + require(__fileName__) { + if (__requires__[__fileName__] != null) { + return __requires__[__fileName__] } + import(__fileName__); + __requires__[__fileName__]= scope(); + return scope(); + } + + millis() { + microseconds() / 1000; + } + + //------------ creation C structure ------------// + + newId(x, comm) { + if (comm == null) { + { identifier: x, __proto__: C_id }; + } else { + { identifier: x, comment: { text : comm, __proto__: Comment }, __proto__: C_id }; } + } - newText(x) { { value: x, __proto__: C_string }; } - - newComment(com) { { text : com, __proto__: Comment }; } - - //--- Token ---// + newText(x) { { value: x, __proto__: C_string }; } + + 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 }; - } + newToken(txt, com) { + if (com == null) return { text: txt, comment: newComment(""), __proto__: Token }; + { text: txt, comment: newComment(com), __proto__: Token }; + } - newSemicolon(com) { newToken(";", com) } + newSemicolon(com) { newToken(";", com) } - newComma() { newToken(",", " "); } + newComma() { newToken(",", " "); } - newStar(com) { newToken("*", com); } + newStar(com) { newToken("*", com); } - newBinary(com) { newToken("=", com); } - - //--- Declaration ---// + newBinary(com) { newToken("=", com); } + + //--- Declaration ---// - newStruct() { - { - declarators: null, - specifier: null, - semicolon: newSemicolon("\n"), - __proto__: C_declaration - } // TO FIX - } + newStruct() { + { + declarators: null, + specifier: null, + semicolon: newSemicolon("\n"), + __proto__: C_declaration + } // TO FIX + } - newEnum(x) { { attributeL: null, expression: null, name: newId(x), __proto__: C_enum }; } + newEnum(x) { { attributeL: null, expression: null, name: newId(x), __proto__: C_enum }; } - newFunction() {} + newFunction() {} - //-------------------- end ---------------------// + //-------------------- end ---------------------// - // Get the last element of s - last(s) { - s[length(s)-1]; - } + // Get the last element of s + last(s) { + s[length(s)-1]; + } - // adding the element e at the end of the list l - append(s, e) { - s[length(s)] = e; - } + // adding the element e at the end of the list l + append(s, e) { + s[length(s)] = e; + } - push(s, e) { - append(s, e); - } + push(s, e) { + append(s, e); + } - pop(s, e) { - if (e == null) { - e = length(s) - 1 - } - ret = s[e]; - t = {}; - for (i in s) { - if (i == e) continue; - append(t, s[i]); - } - s = treeCopy(t); - ret; + pop(s, e) { + if (e == null) { + e = length(s) - 1 } - - // 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; + ret = s[e]; + t = {}; + for (i in s) { + if (i == e) continue; + append(t, s[i]); } - - fusion(s1, s2) { - for (i in s2) { - append(s1, s2[i]); - } - return s1; + s = treeCopy(t); + ret; + } + + // 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; + } - // 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])); - } + fusion(s1, s2) { + for (i in s2) { + append(s1, s2[i]); + } + return 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; } + out; + } - notToken(x) { x.__proto__ != Token } + 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 true + select(f, s) { + out = {}; + for (i in s) { + e = s[i]; + if (f(e)) { append(out, e); } } - - // 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; + 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); } } - - - nil; + out; + } + + + nil; }