home *** CD-ROM | disk | FTP | other *** search
/ cs.rhul.ac.uk / www.cs.rhul.ac.uk.zip / www.cs.rhul.ac.uk / pub / rdp / rdp_cs3460.tar / rdp_aux.h < prev    next >
C/C++ Source or Header  |  1998-05-07  |  9KB  |  239 lines

  1. /****************************************************************************
  2. *
  3. * RDP release 1.50 by Adrian Johnstone (A.Johnstone@rhbnc.ac.uk) 20 December 1997
  4. *
  5. * rdp_aux.h - rdp semantic routines
  6. *
  7. * This file may be freely distributed. Please mail improvements to the author.
  8. *
  9. ****************************************************************************/
  10. #ifndef RDP_AUX_H
  11. #define RDP_AUX_H
  12.  
  13. #include "arg.h"
  14. #include "symbol.h"
  15. #include "set.h"
  16. #include "graph.h"
  17.  
  18. #define RDP_RESERVED_WORDS                                       \
  19. /* ANSI C reserved words */ \
  20. "auto", "break", "case", "char", "const", "continue", "default", \
  21. "do", "double", "else", "enum", "extern", "float", "for", \
  22. "goto", "if", "int", "long", "register", "return", "short", \
  23. "signed", "sizeof", "static", "struct", "switch", "typedef", \
  24. "union", "unsigned", "void", "volatile", "while", \
  25. /* C++ reserved words */ \
  26. "operator", \
  27. /* ANSI C library names (a selection) */ \
  28. "printf"
  29.  
  30. #define RDP_DATA                                                            \
  31. char * id; \
  32. int token; \
  33. unsigned token_value;         /* token value for tokens */ \
  34. unsigned extended_value;      /* extended value for tokens */ \
  35. kind_type kind; \
  36. char * return_type;           /* return_type name */ \
  37. unsigned return_type_stars;   /* number of indirections in return type */ \
  38. char * token_string;          /* pointer to token value as a string */ \
  39. char * token_enum;            /* pointer to token value as enum element */ \
  40. char * extended_enum;         /* pointer to extended value as enum element */ \
  41. int promote_default;          /* default promotion operator */ \
  42. int promote;                  /* promotion operator for inline calls */ \
  43. int delimiter_promote;        /* promotion operator for iterator delimiters */ \
  44. int \
  45. comment_only: \
  46. 1,                            /* flag to suppress unused production warning if production contains only comments */ \
  47. contains_null: \
  48. 1,                            /* for quick first calculation */ \
  49. parameterised: \
  50. 1,                            /* production has inherited attributes */ \
  51. code_successor: \
  52. 1,                            /* mark items that follow a code item */ \
  53. code_terminator: \
  54. 1,                            /* mark last code item in sequence */ \
  55. code_only: \
  56. 1,                            /* primary production with code only */ \
  57. been_defined: \
  58. 1,                            /* has appeared on LHS of ::= */ \
  59. in_use: \
  60. 1,                            /* production being checked flag */ \
  61. ll1_violation: \
  62. 1,                            /* ll(1) violation detected */ \
  63. first_done: \
  64. 1,                            /* first() completed on this production */ \
  65. follow_done: \
  66. 1;                            /* follow() completed on this production */ \
  67. set_ first;                   /* set of first symbols */ \
  68. unsigned call_count;          /* how many times production is called */ \
  69. unsigned first_cardinality;   /* number of elements in first set */ \
  70. set_ follow;                  /* set of follow symbols */ \
  71. unsigned follow_cardinality;  /* number of elements in follow set */ \
  72. unsigned code_pass;           /* active parser pass for code element */ \
  73. unsigned long lo;             /* minimum iteration count */ \
  74. unsigned long hi;             /* maximum iteration count */ \
  75. rdp_param_list * params,      /* list of parameter names (and types) */ \
  76. * actuals;                    /* list of actuals filled in by item_ret */ \
  77. struct rdp_list_node * list;  /* list of alternatives or items */ \
  78. struct rdp_data_node * supplementary_token;  /* spare token pointer */ \
  79. char * close;                 /* extended keyword close string */
  80.  
  81. enum scan_extended_class_type
  82. {
  83.   E_SIMPLE,                   /* i.e. not extended! */ E_STRING, E_STRING_ESC, 
  84.   E_COMMENT, E_COMMENT_NEST, E_COMMENT_LINE, 
  85.   E_COMMENT_VISIBLE, E_COMMENT_NEST_VISIBLE, E_COMMENT_LINE_VISIBLE
  86. }; 
  87.  
  88. enum rdp_promote_op{PROMOTE_DONT, PROMOTE_DEFAULT, PROMOTE, PROMOTE_AND_COPY, PROMOTE_ABOVE}; 
  89.  
  90. enum rdp_iter_op{ITER_FLAT, ITER_LEFT, ITER_RIGHT}; 
  91.  
  92. enum rdp_param_type{PARAM_ID, PARAM_STRING, PARAM_REAL, PARAM_INTEGER}; 
  93.  
  94. typedef struct rdp_param_node
  95. {
  96.   char * id; 
  97.   long int n; 
  98.   double r; 
  99.   char * type; 
  100.   unsigned stars; 
  101.   enum rdp_param_type flavour; 
  102.   struct rdp_param_node * next; 
  103. }rdp_param_list; 
  104.  
  105. typedef struct rdp_string_list_node
  106. {
  107.   char * str1, 
  108.   * str2; 
  109.   struct rdp_string_list_node * next; 
  110. }rdp_string_list; 
  111.  
  112. typedef struct rdp_arg_list_node
  113. {
  114.   enum arg_kind_type kind; 
  115.   char * var; 
  116.   char * key; 
  117.   char * desc; 
  118.   struct rdp_arg_list_node * next; 
  119. }rdp_arg_list; 
  120.  
  121. typedef struct rdp_table_list_node
  122. {
  123.   char * name; 
  124.   unsigned size; 
  125.   unsigned prime; 
  126.   char * compare; 
  127.   char * hash; 
  128.   char * print; 
  129.   char * data_fields; 
  130.   struct rdp_table_list_node * next; 
  131. }rdp_table_list; 
  132.  
  133. typedef struct rdp_index_table_list_node
  134. {
  135.   char * name; 
  136.   unsigned size; 
  137.   char * compare; 
  138.   char * print; 
  139.   char * data_fields; 
  140.   struct rdp_index_table_list_node * next; 
  141. }rdp_index_table_list; 
  142.  
  143. typedef enum                  /* Production classifications */
  144. {
  145.   K_EXTENDED, 
  146.   K_INTEGER, K_REAL, K_STRING, K_CODE, K_TOKEN, 
  147.   K_PRIMARY, K_SEQUENCE, K_LIST
  148. }kind_type; 
  149.  
  150. typedef enum
  151. {
  152.   RDP_OLD, RDP_NEW, RDP_ANY
  153. }symbol_type; 
  154.  
  155.  
  156. extern rdp_string_list
  157. * rdp_dir_include;            /* strings from INCLUDE directives */
  158.  
  159. extern rdp_arg_list
  160. * rdp_dir_args;               /* data from ARG_* directives */
  161.  
  162. extern rdp_table_list
  163. * rdp_dir_symbol_table; 
  164.  
  165. extern rdp_index_table_list
  166. * rdp_dir_index_table; 
  167.  
  168. extern void * rdp_base;       /* symbol table for the parser */
  169.  
  170. typedef struct rdp_list_node
  171. {
  172.   char * return_name; 
  173.   struct rdp_data_node * production; 
  174.   rdp_param_list * actuals;   /* list of actuals used by production call */
  175.   struct rdp_list_node * next; 
  176.   int promote;                /* promotion operator for this node */
  177.   int promote_epsilon;        /* promotion operator for epsilons generated by this node */
  178.   char * default_action;      /* action to be executed of lo=0 and body not taken */ \
  179. }rdp_list; 
  180.  
  181. extern char
  182. * rdp_primary_id;             /* identifier for parent production */
  183.  
  184. extern void * rdp_base;       /* pointer to production chain scope */
  185.  
  186. extern set_ rdp_production_set;  /* set of production kinds */
  187.  
  188. extern int
  189. rdp_comment_only,             /* Flag to track productions that contain only comments */
  190. rdp_rule_count,               /* Number of rules declared * 2 */
  191. rdp_force,                    /* flag to force output file writing */
  192. rdp_expanded,                 /* flag to force expanded BNF printing */
  193. rdp_error_production_name,    /* flag to force writing of production name into error messages */
  194. rdp_parser_only,              /* omit semantic actions flag */
  195. rdp_trace,                    /* add trace messages flag */
  196. rdp_verbose;                  /* verbose mode flag */
  197.  
  198. extern unsigned rdp_component;  /* sub-production component number */
  199. extern unsigned rdp_token_count;  /* number of tokens + extendeds */
  200.  
  201. extern struct rdp_data_node * rdp_start_prod; 
  202.  
  203. extern char
  204. * rdp_dir_title,              /* string from TITLE directive */
  205. * rdp_dir_suffix,             /* string from SUFFIX directive */
  206. * rdp_dir_pre_parse,          /* string from PRE_PARSE directive */
  207. * rdp_dir_post_parse,         /* string from POST_PARSE directive */
  208. * rdp_dir_output_file,        /* string from OUTPUT_FILE directive */
  209. * rdp_dir_tree_fields;        /* fild names for tree node from TREE directive */
  210.  
  211. extern unsigned
  212. rdp_dir_tree,                 /* TREE flag */
  213. rdp_dir_epsilon_tree,         /* EPSILON_TRTEE tree flag */
  214. rdp_dir_annotated_epsilon_tree,  /* ANNOTATED_EPSILON_TRTEE tree flag */
  215. rdp_dir_case_insensitive,     /* CASE_INSENSITIVE flag */
  216. rdp_dir_show_skips,           /* SHOW_SKIPS flag */
  217. rdp_dir_newline_visible,      /* NEWLINE_VISIBLE flag */
  218. rdp_dir_passes,               /* PASSES directive */
  219. rdp_dir_hash_size,            /* HASH_SIZE directive */
  220. rdp_dir_hash_prime,           /* HASH_PRIME directive */
  221. rdp_dir_max_errors,           /* MAX_ERRORS directive */
  222. rdp_dir_max_warnings;         /* MAX_WARNINGS directive */
  223.  
  224. extern unsigned long rdp_dir_text_size;  /* TEXT_SIZE directive */
  225. extern unsigned long rdp_dir_tab_width;  /* TAB_WIDTH directive */
  226.  
  227. /* globally visible functions */
  228.  
  229. void rdp_add_arg(enum arg_kind_type kind, char * key, char * var, char * desc); 
  230. struct rdp_data_node * rdp_find(char * id, kind_type kind, symbol_type symbol); 
  231. struct rdp_data_node * rdp_find_extended(char * open, char * close, int token); 
  232. void rdp_post_parse(char * outputfilename, int force); 
  233. void rdp_pre_parse(void); 
  234. void * rdp_process_token(char * name); 
  235.  
  236. #endif
  237.  
  238. /* End of rdp_aux.h */
  239.