le compilateur super performant
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

symbol_table.test.c 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "symbol_table.h"
  2. #include <stdio.h>
  3. #include <assert.h>
  4. #include <string.h>
  5. int main() {
  6. int err;
  7. SymbolTable table;
  8. SymbolItem *item;
  9. init_table(&table);
  10. err = add_symbol(&table, TYPE_CONST, "y");
  11. printf("Adding y symbol\n");
  12. assert(err == 0);
  13. err = add_symbol(&table, TYPE_INT, "x");
  14. printf("Adding x symbol\n");
  15. assert(err == 0);
  16. err = add_symbol(&table, TYPE_CONST, "y");
  17. printf("Adding y symbol\n");
  18. assert(err == -1);
  19. item = get_symbol_item(&table, "y");
  20. printf("Getting item y: \n");
  21. print_item(item);
  22. err = mark_symbol_initialized(&table, "y");
  23. printf("Mark y initialized\n");
  24. assert(err == 0);
  25. print_item(item);
  26. err = mark_symbol_initialized(&table, "y");
  27. printf("Mark y initialized\n");
  28. assert(err == -2);
  29. print_item(item);
  30. err = mark_symbol_initialized(&table, "b");
  31. printf("Mark b initialized\n");
  32. assert(err == -1);
  33. const SymbolItem* var1 = add_temp_symbol(&table, TYPE_INT);
  34. printf("Add _temp99 temporary variable\n");
  35. assert(strcmp(var1->name, "_temp99") == 0);
  36. const SymbolItem* var2 = add_temp_symbol(&table, TYPE_INT);
  37. printf("Add _temp98 temporary variable\n");
  38. assert(strcmp(var2->name, "_temp98") == 0);
  39. item = get_symbol_item(&table, "_temp98");
  40. printf("_temp98:\n");
  41. print_item(item);
  42. item = get_symbol_item(&table, "_temp0");
  43. printf("_temp5:\n");
  44. print_item(item);
  45. printf("\n=================\n");
  46. printf("Full table: \n");
  47. print_table(&table);
  48. }