No Description
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.

table_symboles.h 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef TABLE_SYMBOLES_H
  2. #define TABLE_SYMBOLES_H
  3. #define TABLE_SIZE 50
  4. #define VARIABLE_SIZE 30
  5. enum Symbole_Type {TYPE_INT , TYPE_CONST_INT};
  6. enum Initialised_Variable{INITIALISED , NOT_INITIALISED};
  7. typedef struct Symboles {
  8. char Variable_Name[VARIABLE_SIZE];
  9. int addr ;
  10. enum Symbole_Type type;
  11. enum Initialised_Variable init;
  12. int symbole_depth;
  13. } Symbole;
  14. typedef struct Table_Symboles {
  15. Symbole array[TABLE_SIZE];
  16. int indexAvailableTop;
  17. int indexAvailableBottom;
  18. int depth;
  19. } Table_Symboles;
  20. /**
  21. * Initialises indexAvailableTop at 0 and indexAvailableBottom at TABLE_SIZE - 1
  22. * @param table
  23. */
  24. void initialise_table(Table_Symboles * table);
  25. /**
  26. * Adds a symbole at the top (regular varaibles)
  27. * @param table
  28. * @param varName
  29. * @param type
  30. * @param init
  31. * @return if symbole added successfully, -1 if the table is full and -2 if the varaible already exists in the table
  32. */
  33. int add_symbole_top(Table_Symboles * table, char * varName, enum Symbole_Type type , enum Initialised_Variable init, int depth);
  34. /**
  35. * Adds a symbole at the bottom (temp variables)
  36. * @param table
  37. * @param varName
  38. * @param type
  39. * @param init
  40. * @return 0 if symbole added successfully, -1 if the table is full and -2 if the varaible already exists in the table
  41. */
  42. int add_symbole_bottom(Table_Symboles * table, char * varName, enum Symbole_Type type , enum Initialised_Variable init);
  43. /**
  44. * Verifies if a varaible name is already present in the table to avoid duplicates
  45. * @param table
  46. * @param varName
  47. * @return -1 if the varaible name exists, 0 if it doesn't
  48. */
  49. int variable_exists(Table_Symboles * table, char * varName);
  50. /**
  51. * Removes symbole from table having certain depth
  52. * @param table
  53. * @param depth
  54. * @return -1 if the symbole isn't in the table, 0 otherwise
  55. */
  56. int remove_symboles(Table_Symboles * table, int depth);
  57. /**
  58. * Initialises an already exisiting symbole
  59. * @param table
  60. * @param varName
  61. * @return -1 if the symbole isn't in the table, 0 otherwise
  62. */
  63. int initialise_symbole(Table_Symboles * table, char * varName);
  64. /**
  65. * Prints a symbole with this format
  66. * varName | Type | Address | Initialised/Not_Initialised
  67. * @param symbole
  68. */
  69. void print_symbole(Symbole * symbole);
  70. /**
  71. * Prints the table
  72. * @param table
  73. */
  74. void print_table(Table_Symboles * table);
  75. #endif