home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / BYACC.ZIP / BYACC.H < prev    next >
C/C++ Source or Header  |  1992-06-11  |  12KB  |  469 lines

  1. void  set_EFF(void);
  2. void  set_first_derives(void);
  3. void  closure(short  *core,int  n);
  4. void  finalize_closure(void);
  5. #include <assert.h>
  6. #include <ctype.h>
  7. #include <stdio.h>
  8.  
  9.  
  10. /*  machine dependent definitions            */
  11. /*  the following definitions are for the VAX        */
  12. /*  they might have to be changed for other machines    */
  13.  
  14. /*  MAXCHAR is the largest character value        */
  15. /*  MAXSHORT is the largest value of a C short        */
  16. /*  MINSHORT is the most negative value of a C short    */
  17. /*  MAXTABLE is the maximum table size            */
  18. /*  BITS_PER_WORD is the number of bits in a C unsigned    */
  19. /*  WORDSIZE computes the number of words needed to    */
  20. /*    store n bits                    */
  21. /*  ROWSIZE computes the number of chars needed to    */
  22. /*    store enough words to represent n bits        */
  23. /*  BIT returns the value of the n-th bit starting    */
  24. /*    from r (0-indexed)                */
  25. /*  SETBIT sets the n-th bit starting from r        */
  26.  
  27. #define    MAXCHAR        255
  28. #define    MAXSHORT    32767
  29. #define MINSHORT    -32768
  30. #define MAXTABLE    32500
  31. #define BITS_PER_WORD   16
  32. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  33. #define    ROWSIZE(n)    (sizeof(unsigned)*WORDSIZE(n))
  34. #define BIT(r, n)       ((((r)[(n) >> 4]) >> ((n) & 15)) & 1)
  35. #define SETBIT(r, n)    ((r)[(n) >> 4] |= (1 << ((n) & 15)))
  36.  
  37.  
  38. /*  character names  */
  39.  
  40. #define    NUL        '\0'    /*  the null character  */
  41. #define    NEWLINE        '\n'    /*  line feed  */
  42. #define    SP        ' '     /*  space  */
  43. #define    BS        '\b'    /*  backspace  */
  44. #define    HT        '\t'    /*  horizontal tab  */
  45. #define    VT        '\013'  /*  vertical tab  */
  46. #define    CR        '\r'    /*  carriage return  */
  47. #define    FF        '\f'    /*  form feed  */
  48. #define    QUOTE        '\''    /*  single quote  */
  49. #define    DOUBLE_QUOTE    '\"'    /*  double quote  */
  50. #define    BACKSLASH    '\\'    /*  backslash  */
  51.  
  52.  
  53. /* defines for constructing filenames */
  54.  
  55. #define DEFINES_SUFFIX  "tab.h"
  56. #define OUTPUT_SUFFIX   "tab.c"
  57. #define VERBOSE_SUFFIX  ".out"
  58.  
  59.  
  60. /* keyword codes */
  61.  
  62. #define TOKEN 0
  63. #define LEFT 1
  64. #define RIGHT 2
  65. #define NONASSOC 3
  66. #define MARK 4
  67. #define TEXT 5
  68. #define TYPE 6
  69. #define START 7
  70. #define UNION 8
  71. #define IDENT 9
  72.  
  73.  
  74. /*  symbol classes  */
  75.  
  76. #define UNKNOWN 0
  77. #define TERM 1
  78. #define NONTERM 2
  79.  
  80.  
  81. /*  the undefined value  */
  82.  
  83. #define UNDEFINED (-1)
  84.  
  85.  
  86. /*  action codes  */
  87.  
  88. #define SHIFT 1
  89. #define REDUCE 2
  90. #define ERROR 3
  91.  
  92.  
  93. /*  character macros  */
  94.  
  95. #define IS_IDENT(c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  96. #define    IS_OCTAL(c)    ((c) >= '0' && (c) <= '7')
  97. #define    NUMERIC_VALUE(c)    ((c) - '0')
  98.  
  99.  
  100. /*  symbol macros  */
  101.  
  102. #define ISTOKEN(s)    ((s) < start_symbol)
  103. #define ISVAR(s)    ((s) >= start_symbol)
  104.  
  105.  
  106. /*  storage allocation macros  */
  107.  
  108. #define CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
  109. #define FREE(x)         (free((x)))
  110. #define MALLOC(n)    (malloc((unsigned)(n)))
  111. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  112. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  113. #define REALLOC(p,n)    (realloc((p),(unsigned)(n)))
  114.  
  115.  
  116. /*  the structure of a symbol table entry  */
  117.  
  118. typedef struct bucket bucket;
  119. struct bucket
  120. {
  121.     struct bucket *link;
  122.     struct bucket *next;
  123.     char *name;
  124.     char *tag;
  125.     short value;
  126.     short index;
  127.     short prec;
  128.     char class;
  129.     char assoc;
  130. };
  131.  
  132.  
  133. /*  the structure of the LR(0) state machine  */
  134.  
  135. typedef struct core core;
  136. struct core
  137. {
  138.     struct core *next;
  139.     struct core *link;
  140.     short number;
  141.     short accessing_symbol;
  142.     short nitems;
  143.     short items[1];
  144. };
  145.  
  146.  
  147. /*  the structure used to record shifts  */
  148.  
  149. typedef struct shifts shifts;
  150. struct shifts
  151. {
  152.     struct shifts *next;
  153.     short number;
  154.     short nshifts;
  155.     short shifts[1];
  156. };
  157.  
  158.  
  159. /*  the structure used to store reductions  */
  160.  
  161. typedef struct reductions reductions;
  162. struct reductions
  163. {
  164.     struct reductions *next;
  165.     short number;
  166.     short nreds;
  167.     short rules[1];
  168. };
  169.  
  170.  
  171. /*  the structure used to represent parser actions  */
  172.  
  173. typedef struct action action;
  174. struct action
  175. {
  176.     struct action *next;
  177.     short symbol;
  178.     short number;
  179.     short prec;
  180.     char action_code;
  181.     char assoc;
  182.     char suppressed;
  183. };
  184.  
  185.  
  186. /* global variables */
  187.  
  188. extern char dflag;
  189. extern char lflag;
  190. extern char tflag;
  191. extern char vflag;
  192.  
  193. extern char *myname;
  194. extern char *cptr;
  195. extern char *line;
  196. extern int lineno;
  197. extern int outline;
  198.  
  199. extern char *banner[];
  200. extern char *header[];
  201. extern char *body[];
  202. extern char *trailer[];
  203.  
  204. extern char *action_file_name;
  205. extern char *defines_file_name;
  206. extern char *input_file_name;
  207. extern char *output_file_name;
  208. extern char *text_file_name;
  209. extern char *union_file_name;
  210. extern char *verbose_file_name;
  211.  
  212. extern FILE *action_file;
  213. extern FILE *defines_file;
  214. extern FILE *input_file;
  215. extern FILE *output_file;
  216. extern FILE *text_file;
  217. extern FILE *union_file;
  218. extern FILE *verbose_file;
  219.  
  220. extern int nitems;
  221. extern int nrules;
  222. extern int nsyms;
  223. extern int ntokens;
  224. extern int nvars;
  225.  
  226. extern char unionized;
  227. extern char line_format[];
  228.  
  229. extern int   start_symbol;
  230. extern char  **symbol_name;
  231. extern short *symbol_value;
  232. extern short *symbol_prec;
  233. extern char  *symbol_assoc;
  234.  
  235. extern short *ritem;
  236. extern short *rlhs;
  237. extern short *rrhs;
  238. extern short *rprec;
  239. extern char  *rassoc;
  240.  
  241. extern short **derives;
  242. extern char *nullable;
  243.  
  244. extern bucket *first_symbol;
  245.  
  246. extern int nstates;
  247. extern core *first_state;
  248. extern shifts *first_shift;
  249. extern reductions *first_reduction;
  250. extern short *accessing_symbol;
  251. extern core **state_table;
  252. extern shifts **shift_table;
  253. extern reductions **reduction_table;
  254. extern unsigned *LA;
  255. extern short *LAruleno;
  256. extern short *lookaheads;
  257. extern short *goto_map;
  258. extern short *from_state;
  259. extern short *to_state;
  260.  
  261. extern action **parser;
  262. extern int SRtotal;
  263. extern int RRtotal;
  264. extern short *SRconflicts;
  265. extern short *RRconflicts;
  266. extern short *defred;
  267. extern short *rules_used;
  268. extern short nunused;
  269. extern short final_state;
  270.  
  271. /* global functions */
  272.  
  273. /*extern char *allocate();*/
  274. extern bucket *lookup();
  275. extern bucket *make_bucket();
  276.  
  277.  
  278. /* system variables */
  279.  
  280. /*extern int errno;*/
  281.  
  282.  
  283. /* system functions */
  284.  
  285. /*extern void free();*/
  286. /*extern char *calloc();*/
  287. /*extern char *malloc();*/
  288. /*extern char *realloc();*/
  289. /*extern char *strcpy();*/
  290. void  fatal(char  *msg);
  291. void  no_space(void);
  292. void  open_error(char  *filename);
  293. void  unexpected_EOF(void);
  294. void  print_pos(char  *st_line,char  *st_cptr);
  295. void  syntax_error(int  st_lineno,char  *st_line,char  *st_cptr);
  296. void  unterminated_comment(int  c_lineno,char  *c_line,char  *c_cptr);
  297. void  unterminated_string(int  s_lineno,char  *s_line,char  *s_cptr);
  298. void  unterminated_text(int  t_lineno,char  *t_line,char  *t_cptr);
  299. void  unterminated_union(int  u_lineno,char  *u_line,char  *u_cptr);
  300. void  over_unionized(char  *u_cptr);
  301. void  illegal_tag(int  t_lineno,char  *t_line,char  *t_cptr);
  302. void  illegal_character(char  *c_cptr);
  303. void  used_reserved(char  *s);
  304. void  tokenized_start(char  *s);
  305. void  retyped_warning(char  *s);
  306. void  reprec_warning(char  *s);
  307. void  revalued_warning(char  *s);
  308. void  terminal_start(char  *s);
  309. void  restarted_warning(void);
  310. void  no_grammar(void);
  311. void  terminal_lhs(int  s_lineno);
  312. void  prec_redeclared(void);
  313. void  unterminated_action(int  a_lineno,char  *a_line,char  *a_cptr);
  314. void  dollar_warning(int  a_lineno,int  i);
  315. void  dollar_error(int  a_lineno,char  *a_line,char  *a_cptr);
  316. void  untyped_lhs(void);
  317. void  untyped_rhs(int  i,char  *s);
  318. void  unknown_rhs(int  i);
  319. void  default_action_warning(void);
  320. void  undefined_goal(char  *s);
  321. void  undefined_symbol_warning(char  *s);
  322. void  lalr(void);
  323. void  set_state_table(void);
  324. void  set_accessing_symbol(void);
  325. void  set_shift_table(void);
  326. void  set_reduction_table(void);
  327. void  set_maxrhs(void);
  328. void  initialize_LA(void);
  329. void  set_goto_map(void);
  330. int  map_goto(int  state,int  symbol);
  331. void  initialize_F(void);
  332. void  build_relations(void);
  333. void  add_lookback_edge(int  stateno,int  ruleno,int  gotono);
  334. short  * *transpose(short  * *R,int  n);
  335. void  compute_FOLLOWS(void);
  336. void  compute_lookaheads(void);
  337. void  digraph(short  * *relation);
  338. void  traverse(int  i);
  339. void  allocate_itemsets(void);
  340. void  allocate_storage(void);
  341. void  append_states(void);
  342. void  free_storage(void);
  343. void  generate_states(void);
  344. int  get_state(int  symbol);
  345. void  initialize_states(void);
  346. void  new_itemsets(void);
  347. struct  core *new_state(int  symbol);
  348. void  show_cores(void);
  349. void  show_ritems(void);
  350. void  show_rrhs(void);
  351. void  show_shifts(void);
  352. void  save_shifts(void);
  353. void  save_reductions(void);
  354. void  set_derives(void);
  355. void  free_derives(void);
  356. void  set_nullable(void);
  357. void  free_nullable(void);
  358. void  lr0(void);
  359. void  done(int  k);
  360. void  onintr(void);
  361. void  set_signals(void);
  362. void  usage(void);
  363. void  getargs(int  argc,char  * *argv);
  364. char  *allocate(unsigned n);
  365. void  create_file_names(void);
  366. void  open_files(void);
  367. int  main(int  argc,char  * *argv);
  368. void  make_parser(void);
  369. struct  action *parse_actions(int  stateno);
  370. struct  action *get_shifts(int  stateno);
  371. struct  action *add_reductions(int  stateno,struct  action *actions);
  372. struct  action *add_reduce(struct  action *actions,int  ruleno,int  symbol);
  373. void  find_final_state(void);
  374. void  unused_rules(void);
  375. void  remove_conflicts(void);
  376. void  end_conflicts(struct  action *p,struct  action *q);
  377. void  resolve_conflicts(struct  action *first,struct  action *last);
  378. void  total_conflicts(void);
  379. int  sole_reduction(int  stateno);
  380. void  defreds(void);
  381. void  free_action_row(struct  action *p);
  382. void  free_parser(void);
  383. void  output(void);
  384. void  output_rule_data(void);
  385. void  output_yydefred(void);
  386. void  output_actions(void);
  387. void  token_actions(void);
  388. void  goto_actions(void);
  389. int  default_goto(int  symbol);
  390. void  save_column(int  symbol,int  default_state);
  391. void  sort_actions(void);
  392. void  pack_table(void);
  393. int  matching_vector(int  vector);
  394. int  pack_vector(int  vector);
  395. void  output_base(void);
  396. void  output_table(void);
  397. void  output_check(void);
  398. int  is_C_identifier(char  *name);
  399. void  output_defines(void);
  400. void  output_stored_text(void);
  401. void  output_debug(void);
  402. void  output_stype(void);
  403. void  output_trailing_text(void);
  404. void  output_semantic_actions(void);
  405. void  free_itemsets(void);
  406. void  free_shifts(void);
  407. void  free_reductions(void);
  408. void  cachec(int  c);
  409. void  get_line(void);
  410. char  *dup_line(void);
  411. void  skip_comment(void);
  412. int  nextc(void);
  413. int  keyword(void);
  414. void  copy_ident(void);
  415. void  copy_text(void);
  416. void  copy_union(void);
  417. int  hexval(int  c);
  418. struct  bucket *get_literal(void);
  419. int  is_reserved(char  *name);
  420. struct  bucket *get_name(void);
  421. int  get_number(void);
  422. char  *get_tag(void);
  423. void  declare_tokens(int  assoc);
  424. void  declare_types(void);
  425. void  declare_start(void);
  426. void  read_declarations(void);
  427. void  initialize_grammar(void);
  428. void  expand_items(void);
  429. void  expand_rules(void);
  430. void  advance_to_start(void);
  431. void  start_rule(struct  bucket *bp,int  s_lineno);
  432. void  end_rule(void);
  433. void  insert_empty_rule(void);
  434. void  add_symbol(void);
  435. void  copy_action(void);
  436. int  mark_symbol(void);
  437. void  read_grammar(void);
  438. void  free_tags(void);
  439. void  pack_names(void);
  440. void  check_symbols(void);
  441. void  pack_symbols(void);
  442. void  pack_grammar(void);
  443. void  print_grammar(void);
  444. void  reader(void);
  445. void  write_section(char  * *section);
  446. void  verbose(void);
  447. void  log_unused(void);
  448. void  log_conflicts(void);
  449. void  print_state(int  state);
  450. void  print_conflicts(int  state);
  451. void  print_core(int  state);
  452. void  print_nulls(int  state);
  453. void  print_actions(int  stateno);
  454. void  print_shifts(struct  action *p);
  455. void  print_reductions(struct  action *p,int  defred);
  456. void  print_gotos(int  stateno);
  457. int  hash(char  *name);
  458. struct  bucket *make_bucket(char  *name);
  459. struct  bucket *lookup(char  *name);
  460. void  create_symbol_table(void);
  461. void  free_symbol_table(void);
  462. void  free_symbols(void);
  463. void  transitive_closure(unsigned *R,int  n);
  464. void  reflexive_transitive_closure(unsigned  *R,int  n);
  465. void print_closure(int n);
  466. void print_EFF(void);
  467. void print_first_derives(void);
  468. void print_derives(void);
  469.