parser.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* $Id$ */
  2. #include <stdio.h>
  3. #include <system.h>
  4. /* type of arguments expected by each instruction */
  5. #define NOARG 1
  6. #define CST 2
  7. #define CSTOPT 3
  8. #define LAB 4
  9. #define DEFILB 5
  10. #define PNAM 6
  11. #define EXT 7
  12. #define IDF_TYPE struct id_info
  13. struct id_info {
  14. struct idf *nextidf; /* chain all opcodes together */
  15. int used; /* is this op used? */
  16. int startpatt; /* does it start a pattern? */
  17. int opcode; /* opcode of operator */
  18. int argfmt; /* how to access pattern argument */
  19. #define id_nextidf id_user.nextidf
  20. #define id_used id_user.used
  21. #define id_startpatt id_user.startpatt
  22. #define id_opcode id_user.opcode
  23. #define id_argfmt id_user.argfmt
  24. };
  25. #include <idf_pkg.spec>
  26. struct exp_node {
  27. int node_type;
  28. union {
  29. struct {
  30. struct exp_node *left;
  31. struct exp_node *right;
  32. } interior;
  33. int val;
  34. } node_args;
  35. #define exp_left node_args.interior.left
  36. #define exp_right node_args.interior.right
  37. #define leaf_val node_args.val
  38. };
  39. struct mnem_elem {
  40. struct idf *op_code;
  41. struct exp_node *arg; /* optional arg expression if replacement */
  42. };
  43. struct mnem_list {
  44. struct mnem_list *next; /* cdr of list */
  45. struct mnem_elem *elem; /* car of list */
  46. };
  47. struct mnems {
  48. int m_len; /* number of mnem's in pattern */
  49. struct mnem_elem **m_elems; /* array of mnem's */
  50. };
  51. struct action {
  52. struct action *next; /* chain all actions for same state together */
  53. int linenum; /* line number in patterns */
  54. struct exp_node *test; /* test expression (if any) */
  55. struct mnems replacement; /* replacement pattern */
  56. };
  57. struct state {
  58. struct state *next; /* chain to next entry for this state */
  59. struct idf *op; /* transition on op to.. */
  60. int goto_state; /* state 'goto_state' */
  61. };
  62. #define MAXSTATES 2000
  63. #define MAXPATTERN 20
  64. /* Parser globals */
  65. extern struct state *states[MAXSTATES];
  66. extern struct action *actions[MAXSTATES];
  67. extern struct mnems patterns[MAXSTATES];
  68. extern int numpatterns; /* Number of patterns */
  69. extern int higheststate; /* Highest state yet allocated */
  70. extern struct idf *ops; /* Chained list of all ops */
  71. extern int maxpattern;
  72. extern int maxreplacement;
  73. extern int nerrors;
  74. extern FILE *ofile;
  75. /* Lexical analyser globals */
  76. extern struct idf *opval; /* opcode of returned OPCODE*/
  77. extern int lastintval; /* value of last integer seen */
  78. extern int linenum; /*line number of input file*/
  79. /* Functions not returning int */
  80. char *Malloc();
  81. struct exp_node *mknode();
  82. struct exp_node *mkleaf();
  83. struct exp_node *combinetests();
  84. struct mnem_list *addelem();
  85. struct mnem_elem **constructlist();