syntactic.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <stdio.h>
  2. #include "aFun.h"
  3. #include "../../src/core/__code.h"
  4. char *str = "10 '20.32 100var\n"
  5. "|10||20.32|int->num\n"
  6. "{if true 10}\n"
  7. "of(HelloWorld)\n"
  8. "[Hello]\n"
  9. ",[Hello]\n"
  10. ;
  11. void test1(void);
  12. void test2(void);
  13. int main() {
  14. test1();
  15. test2();
  16. return 0;
  17. }
  18. void test1(void) {
  19. af_Parser *parser = makeParserByString(str, false, stderr);
  20. af_Code *code = parserCode("test1.af", parser);
  21. freeParser(parser);
  22. freeAllCode(code);
  23. }
  24. void test2(void) {
  25. FilePath path = "./test.af";
  26. FILE *file = fopen(path, "wb");
  27. if (file == NULL) {
  28. perror("File open error");
  29. exit(EXIT_FAILURE);
  30. }
  31. if (fwrite(str, sizeof(char), strlen(str), file) != strlen(str)) {
  32. fprintf(stderr, "File write error.\n");
  33. exit(EXIT_FAILURE);
  34. }
  35. fclose(file);
  36. af_Parser *parser = makeParserByFile(path, stderr);
  37. af_Code *code = parserCode("test2.af", parser);
  38. printCode(code);
  39. freeParser(parser);
  40. freeAllCode(code);
  41. }