lburg.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef BURG_INCLUDED
  2. #define BURG_INCLUDED
  3. /* iburg.c: */
  4. extern void *alloc(int nbytes);
  5. typedef enum { TERM=1, NONTERM } Kind;
  6. typedef struct rule *Rule;
  7. typedef struct term *Term;
  8. struct term { /* terminals: */
  9. char *name; /* terminal name */
  10. Kind kind; /* TERM */
  11. int esn; /* external symbol number */
  12. int arity; /* operator arity */
  13. Term link; /* next terminal in esn order */
  14. Rule rules; /* rules whose pattern starts with term */
  15. };
  16. typedef struct nonterm *Nonterm;
  17. struct nonterm { /* nonterminals: */
  18. char *name; /* nonterminal name */
  19. Kind kind; /* NONTERM */
  20. int number; /* identifying number */
  21. int lhscount; /* # times nt appears in a rule lhs */
  22. int reached; /* 1 iff reached from start nonterminal */
  23. Rule rules; /* rules w/nonterminal on lhs */
  24. Rule chain; /* chain rules w/nonterminal on rhs */
  25. Nonterm link; /* next terminal in number order */
  26. };
  27. extern Nonterm nonterm(char *id);
  28. extern Term term(char *id, int esn);
  29. typedef struct tree *Tree;
  30. struct tree { /* tree patterns: */
  31. void *op; /* a terminal or nonterminal */
  32. Tree left, right; /* operands */
  33. int nterms; /* number of terminal nodes in this tree */
  34. };
  35. extern Tree tree(char *op, Tree left, Tree right);
  36. struct rule { /* rules: */
  37. Nonterm lhs; /* lefthand side nonterminal */
  38. Tree pattern; /* rule pattern */
  39. int ern; /* external rule number */
  40. int packed; /* packed external rule number */
  41. int cost; /* cost, if a constant */
  42. char *code; /* cost, if an expression */
  43. char *template; /* assembler template */
  44. Rule link; /* next rule in ern order */
  45. Rule next; /* next rule with same pattern root */
  46. Rule chain; /* next chain rule with same rhs */
  47. Rule decode; /* next rule with same lhs */
  48. Rule kids; /* next rule with same _kids pattern */
  49. };
  50. extern Rule rule(char *id, Tree pattern, char *template, char *code);
  51. /* gram.y: */
  52. void yyerror(char *fmt, ...);
  53. int yyparse(void);
  54. void yywarn(char *fmt, ...);
  55. extern int errcnt;
  56. extern FILE *infp;
  57. extern FILE *outfp;
  58. #endif