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 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* TABLE DES SYMBOLE DU COMPILATEUR (PILE)
  2. -----------------------------------------------------
  3. | symbole | adresse | type | initialisé |
  4. -----------------------------------------------------
  5. | | | | |
  6. | | | | |
  7. | | | | |
  8. | i | 0x777756b8 | int | false |
  9. | size | 0x777756b8 | int | true |
  10. -----------------------------------------------------
  11. Types pour l'implémentation :
  12. - enum type_t : [int]
  13. - struct symbole : {
  14. char nom[30];
  15. uintptr_t adresse;
  16. enum type_t type;
  17. char initialized;
  18. }
  19. Opérations possible :
  20. - init -> pile * -> void
  21. - push -> symbole -> pile * -> void
  22. - pop -> pile * -> symbole
  23. - status -> nom -> pile -> char */
  24. #include <stdint.h>
  25. /**************************************/
  26. /**************************************/
  27. /**** Gestion des types possibles ****/
  28. /**************************************/
  29. /**************************************/
  30. //Enumération des types de base reconnus
  31. enum base_type_t {UNKNOWN, INT};
  32. //Table enregistrant la taille de ces types de bases (indexée sur les types)
  33. extern int taille_types[];
  34. //Structure gérant les types
  35. struct type_t {
  36. //Champs enregsitrant le type de base
  37. enum base_type_t base;
  38. //Si la variable est un pointeur, on enregitre son niveau (nombre de *)
  39. int pointeur_level;
  40. //Si il s'agit d'un tableau, on enregistre sa taille (nombre de cases)
  41. int nb_blocs;
  42. };
  43. //Constante pour les entiers
  44. extern const struct type_t integer;
  45. /**************************************/
  46. /**************************************/
  47. /***** Gestion de la profondeur *****/
  48. /**************************************/
  49. /**************************************/
  50. //Incrémente la profondeur
  51. void inc_prof();
  52. //Récupère la profondeur
  53. int get_prof();
  54. //Détruit toutes les variables de la profondeur actuelle puis décrémente la profondeur
  55. void reset_prof();
  56. /**************************************/
  57. /**************************************/
  58. /*Table des symboles : fonctionnement */
  59. /**************************************/
  60. /**************************************/
  61. //Structure représentant un symbole
  62. struct symbole_t {
  63. //Son Nom
  64. char nom[30];
  65. //Son Adresse
  66. uintptr_t adresse;
  67. //Son type
  68. struct type_t type;
  69. //Est il initialisé
  70. int initialized;
  71. //Sa profondeur de création
  72. int profondeur;
  73. };
  74. //Fonction d'affichage d'un symbole
  75. void print_symbole(struct symbole_t symbole);
  76. //Fonction d'initialisation de la table, à appeler une fois
  77. void init(void);
  78. /**************************************/
  79. /**************************************/
  80. /** Table des symboles : primitives **/
  81. /**************************************/
  82. /**************************************/
  83. //Ajout d'un symbole a la table
  84. int push(char * nom, int isInit, struct type_t type);
  85. //Destruction et récupération du premier élément de la table
  86. struct symbole_t pop();
  87. //Retourne la dernière adresse disponible
  88. int get_last_addr();
  89. //Renvoi un pointeur vers le symbole correspondant au nom de variable
  90. struct symbole_t * get_variable(char * nom);
  91. //Affiche la table des symboles
  92. void print();