symbol_table.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Andrea Di Biagio
  3. * Politecnico di Milano, 2007
  4. *
  5. * symbol_table.h
  6. * Formal Languages & Compilers Machine, 2007/2008
  7. *
  8. */
  9. #ifndef _SYMBOL_TABLE_H
  10. #define _SYMBOL_TABLE_H
  11. #include <stdio.h>
  12. #include "sy_table_constants.h"
  13. struct t_symbol_table;
  14. /* Typedef for the struct t_symbol_table */
  15. typedef struct t_symbol_table t_symbol_table;
  16. /* a symbol inside the sy_table. An element of the symbol table is composed by
  17. * three fields: <ID>, <type> and <Location>.
  18. * `ID' is a not-NULL string that is used as key identifier for a symbol
  19. * inside the table.
  20. * `type' is an integer value that is used to determine the correct type
  21. * of a symbol. Valid values for `type' are defined into "sy_table_constants.h".
  22. * `reg_location' refers to a register location (i.e. which register contains
  23. * the value of `ID'). */
  24. typedef struct
  25. {
  26. char *ID; /* symbol identifier */
  27. int type; /* type associated with the symbol */
  28. int reg_location; /* a register location */
  29. }t_symbol;
  30. /* put a symbol into the symbol table */
  31. extern int putSym(t_symbol_table *table, char *ID, int type);
  32. /* set the location of the symbol with ID as identifier */
  33. extern int setLocation(t_symbol_table *table, char *ID, int reg);
  34. /* get the location of the symbol with the given ID */
  35. extern int getLocation(t_symbol_table *table, char *ID, int *errorcode);
  36. /* get the type associated with the symbol with ID as identifier */
  37. extern int getTypeFromID(t_symbol_table *table, char *ID, int type);
  38. /* initialize the symbol table */
  39. extern t_symbol_table * initialize_sy_table();
  40. /* finalize the symbol table */
  41. extern int finalize_sy_table(t_symbol_table *table);
  42. /* given a register identifier (location), it returns the ID of the variable
  43. * stored inside the register `location'. This function returns NULL
  44. * if the location is an invalid location. */
  45. extern char * getIDfromLocation(t_symbol_table *table
  46. , int location, int *errorcode);
  47. #ifndef NDEBUG
  48. /* This function print out to the file `fout' the content of the
  49. * symbol table given as input. The resulting text is formatted in
  50. * the following way: <ID> -- <TYPE> -- <REGISTER> */
  51. extern void printSymbolTable(t_symbol_table *table, FILE *fout);
  52. #endif
  53. #endif