Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.0 KiB

  1. /* Grammar interface */
  2. #ifndef Py_GRAMMAR_H
  3. #define Py_GRAMMAR_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include "bitset.h" /* Sigh... */
  8. /* A label of an arc */
  9. typedef struct {
  10. int lb_type;
  11. char *lb_str;
  12. } label;
  13. #define EMPTY 0 /* Label number 0 is by definition the empty label */
  14. /* A list of labels */
  15. typedef struct {
  16. int ll_nlabels;
  17. label *ll_label;
  18. } labellist;
  19. /* An arc from one state to another */
  20. typedef struct {
  21. short a_lbl; /* Label of this arc */
  22. short a_arrow; /* State where this arc goes to */
  23. } arc;
  24. /* A state in a DFA */
  25. typedef struct {
  26. int s_narcs;
  27. arc *s_arc; /* Array of arcs */
  28. /* Optional accelerators */
  29. int s_lower; /* Lowest label index */
  30. int s_upper; /* Highest label index */
  31. int *s_accel; /* Accelerator */
  32. int s_accept; /* Nonzero for accepting state */
  33. } state;
  34. /* A DFA */
  35. typedef struct {
  36. int d_type; /* Non-terminal this represents */
  37. char *d_name; /* For printing */
  38. int d_initial; /* Initial state */
  39. int d_nstates;
  40. state *d_state; /* Array of states */
  41. bitset d_first;
  42. } dfa;
  43. /* A grammar */
  44. typedef struct {
  45. int g_ndfas;
  46. dfa *g_dfa; /* Array of DFAs */
  47. labellist g_ll;
  48. int g_start; /* Start symbol of the grammar */
  49. int g_accel; /* Set if accelerators present */
  50. } grammar;
  51. /* FUNCTIONS */
  52. grammar *newgrammar(int start);
  53. dfa *adddfa(grammar *g, int type, char *name);
  54. int addstate(dfa *d);
  55. void addarc(dfa *d, int from, int to, int lbl);
  56. dfa *PyGrammar_FindDFA(grammar *g, int type);
  57. int addlabel(labellist *ll, int type, char *str);
  58. int findlabel(labellist *ll, int type, char *str);
  59. char *PyGrammar_LabelRepr(label *lb);
  60. void translatelabels(grammar *g);
  61. void addfirstsets(grammar *g);
  62. void PyGrammar_AddAccelerators(grammar *g);
  63. void PyGrammar_RemoveAccelerators(grammar *);
  64. void printgrammar(grammar *g, FILE *fp);
  65. void printnonterminals(grammar *g, FILE *fp);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* !Py_GRAMMAR_H */