grammar.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. const 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. const 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. const 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_nstates;
  39. state *d_state; /* Array of states */
  40. bitset d_first;
  41. } dfa;
  42. /* A grammar */
  43. typedef struct {
  44. int g_ndfas;
  45. const dfa *g_dfa; /* Array of DFAs */
  46. const labellist g_ll;
  47. int g_start; /* Start symbol of the grammar */
  48. int g_accel; /* Set if accelerators present */
  49. } grammar;
  50. /* FUNCTIONS */
  51. const dfa *PyGrammar_FindDFA(grammar *g, int type);
  52. const char *PyGrammar_LabelRepr(label *lb);
  53. void PyGrammar_AddAccelerators(grammar *g);
  54. void PyGrammar_RemoveAccelerators(grammar *);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif /* !Py_GRAMMAR_H */