home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Include / grammar.h < prev    next >
C/C++ Source or Header  |  1994-01-03  |  3KB  |  117 lines

  1. #ifndef Py_GRAMMAR_H
  2. #define Py_GRAMMAR_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7. /***********************************************************
  8. Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
  9. Amsterdam, The Netherlands.
  10.  
  11.                         All Rights Reserved
  12.  
  13. Permission to use, copy, modify, and distribute this software and its 
  14. documentation for any purpose and without fee is hereby granted, 
  15. provided that the above copyright notice appear in all copies and that
  16. both that copyright notice and this permission notice appear in 
  17. supporting documentation, and that the names of Stichting Mathematisch
  18. Centrum or CWI not be used in advertising or publicity pertaining to
  19. distribution of the software without specific, written prior permission.
  20.  
  21. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  22. THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  23. FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  24. FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  25. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  26. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  27. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  
  29. ******************************************************************/
  30.  
  31. /* Grammar interface */
  32.  
  33. #include "bitset.h" /* Sigh... */
  34.  
  35. /* A label of an arc */
  36.  
  37. typedef struct {
  38.     int    lb_type;
  39.     char    *lb_str;
  40. } label;
  41.  
  42. #define EMPTY 0        /* Label number 0 is by definition the empty label */
  43.  
  44. /* A list of labels */
  45.  
  46. typedef struct {
  47.     int    ll_nlabels;
  48.     label    *ll_label;
  49. } labellist;
  50.  
  51. /* An arc from one state to another */
  52.  
  53. typedef struct {
  54.     short        a_lbl;        /* Label of this arc */
  55.     short        a_arrow;    /* State where this arc goes to */
  56. } arc;
  57.  
  58. /* A state in a DFA */
  59.  
  60. typedef struct {
  61.     int         s_narcs;
  62.     arc        *s_arc;        /* Array of arcs */
  63.     
  64.     /* Optional accelerators */
  65.     int         s_lower;    /* Lowest label index */
  66.     int         s_upper;    /* Highest label index */
  67.     int        *s_accel;    /* Accelerator */
  68.     int         s_accept;    /* Nonzero for accepting state */
  69. } state;
  70.  
  71. /* A DFA */
  72.  
  73. typedef struct {
  74.     int         d_type;    /* Non-terminal this represents */
  75.     char        *d_name;    /* For printing */
  76.     int         d_initial;    /* Initial state */
  77.     int         d_nstates;
  78.     state        *d_state;    /* Array of states */
  79.     bitset         d_first;
  80. } dfa;
  81.  
  82. /* A grammar */
  83.  
  84. typedef struct {
  85.     int         g_ndfas;
  86.     dfa        *g_dfa;        /* Array of DFAs */
  87.     labellist     g_ll;
  88.     int         g_start;    /* Start symbol of the grammar */
  89.     int         g_accel;    /* Set if accelerators present */
  90. } grammar;
  91.  
  92. /* FUNCTIONS */
  93.  
  94. grammar *newgrammar PROTO((int start));
  95. dfa *adddfa PROTO((grammar *g, int type, char *name));
  96. int addstate PROTO((dfa *d));
  97. void addarc PROTO((dfa *d, int from, int to, int lbl));
  98. dfa *finddfa PROTO((grammar *g, int type));
  99. char *typename PROTO((grammar *g, int lbl));
  100.  
  101. int addlabel PROTO((labellist *ll, int type, char *str));
  102. int findlabel PROTO((labellist *ll, int type, char *str));
  103. char *labelrepr PROTO((label *lb));
  104. void translatelabels PROTO((grammar *g));
  105.  
  106. void addfirstsets PROTO((grammar *g));
  107.  
  108. void addaccelerators PROTO((grammar *g));
  109.  
  110. void printgrammar PROTO((grammar *g, FILE *fp));
  111. void printnonterminals PROTO((grammar *g, FILE *fp));
  112.  
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116. #endif /* !Py_GRAMMAR_H */
  117.