new version of grace
This commit is contained in:
@@ -1,15 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#define PRINT quine, 10, print, 10, 92, 10, 92, 10, 92, 10, 92, 10, 34, 34, 34, 34, 92, 10, 92, 10, 34, quine, 34, 92, 10, 92, 10, 92, 10, 10, 10, 10, 10
|
||||
#define FT(...) int main(){\
|
||||
/*\
|
||||
comment\
|
||||
*/\
|
||||
FILE *file = fopen("Grace_kid.c", "w");\
|
||||
char *print = #__VA_ARGS__;\
|
||||
char *quine = "#include <stdio.h>%c#define PRINT %s%c#define FT(...) int main(){%c%c /*%c%c comment%c%c */%c%c FILE *file = fopen(%cGrace_kid.c%c, %cw%c);%c%c char *print = #__VA_ARGS__;%c%c char *quine = %c%s%c;%c%c fprintf(file, PRINT);%c%c return 0;%c%c}%c#define FFT(...) FT(__VA_ARGS__)%c%cFFT(PRINT)%c";\
|
||||
fprintf(file, PRINT);\
|
||||
return 0;\
|
||||
}
|
||||
#define FFT(...) FT(__VA_ARGS__)
|
||||
#define xstr(s) #s
|
||||
#define str(s) xstr(s)
|
||||
#define MAIN(s) int main() { char *quine = "#include <stdio.h>\n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "s"\n\nMAIN(str(MAIN(s)))\n"; printf(quine); return 0; }
|
||||
|
||||
FFT(PRINT)
|
||||
MAIN(str(MAIN(s)))
|
||||
|
||||
14
README.md
14
README.md
@@ -1,6 +1,8 @@
|
||||
# DR QUINE
|
||||
|
||||
#### constructing a quine with macro :
|
||||
## 2. GRACE
|
||||
|
||||
#### 2.1 constructing a quine with macro :
|
||||
---
|
||||
|
||||
**a quine could be this structure basically :**
|
||||
@@ -27,7 +29,7 @@ MAIN()
|
||||
```
|
||||
|
||||
|
||||
#### let's try it
|
||||
#### 2.2 let's try it
|
||||
---
|
||||
|
||||
```
|
||||
@@ -53,7 +55,7 @@ int main()
|
||||
**problem :** the `char *quine` string should contain a copy of the whole code in place of "s"
|
||||
|
||||
|
||||
#### second try, macro calling itself : MAIN(MAIN)
|
||||
#### 2.3 second try, macro calling itself : MAIN(MAIN)
|
||||
---
|
||||
|
||||
```
|
||||
@@ -80,7 +82,7 @@ int main()
|
||||
|
||||
|
||||
|
||||
#### lets stringify the content of the inner MAIN
|
||||
#### 2.4 lets stringify the content of the inner MAIN
|
||||
---
|
||||
|
||||
**the previous can be written with an extra step :**
|
||||
@@ -118,10 +120,10 @@ int main()
|
||||
}
|
||||
```
|
||||
|
||||
**problem :** oops, it stringified the paramter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
|
||||
**problem :** oops, it stringified the parameter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
|
||||
|
||||
|
||||
#### working stringification
|
||||
#### 2.5 working stringification
|
||||
---
|
||||
|
||||
```
|
||||
|
||||
2
notes.md
2
notes.md
@@ -272,7 +272,7 @@ int main()
|
||||
}
|
||||
```
|
||||
|
||||
**problem :** oops, it stringified the paramter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
|
||||
**problem :** oops, it stringified the parameter name, not it's expanded version, see https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
|
||||
|
||||
|
||||
#### 2.4 : working stringification
|
||||
|
||||
Reference in New Issue
Block a user