home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / dec92.zip / 1012105A < prev    next >
Text File  |  1992-05-26  |  3KB  |  102 lines

  1. //     LISTING 5. DFA.H
  2. // Definitions and structs for DFA_CLASS object
  3.  
  4. // User-defined constants here;
  5. //    these are the defaults        */
  6. #define LBR        '{'
  7. #define RBR        '}'
  8. #define GS        ':'
  9. #define FS        '\\'
  10. #define EOR        '\n'
  11. #define TAB        '\t'
  12. #define DOT     '.'
  13. #define WSPACE        ' '
  14. #define MAXBUFLEN    512
  15.  
  16. // Control modes for file operations
  17. #define READ_TEXT        "rt"
  18. #define READ_BINARY        "rb"
  19. #define WRITE_TEXT        "wt"
  20. #define WRITE_BINARY    "wb"
  21.  
  22. // DFA-specific constants are here,
  23. //    and following. Dangerous to edit these.
  24. #define GOOD    1
  25. #define BAD    0
  26. #define ERR    -1
  27. #define OK    0
  28. #define OUT    99
  29. #define YES    1
  30. #define NO    0
  31. #define EMPTY  ((char) '\0')
  32.  
  33. // Definition of state table
  34. // (a data table to the state machine)
  35. typedef struct dfa {
  36.     short (*target)(char *);   // validate token fcn
  37.     short good;                // passed dest state
  38.     short bad;                 // failed dest state
  39.     short (*goodfcn)(char *);  // target passed
  40.     short (*badfcn)(char *);   // target failed
  41. } DFATBL;
  42.  
  43. // Definition of the state machinery:
  44. typedef struct object {
  45. // public-overidable elements
  46.     DFATBL *tbl;     // ptr to the state table
  47.     FILE *infile;    // input file to be parsed
  48.     char *(*get_token)(struct object *); // tokenizer
  49.     char *delim;        // ptr to string of delimiters
  50. // Internal working variables
  51.     short (*movest)(struct object *, short);
  52.     short ndx;            // current index (substate)
  53.     short oflag;        // general work flag
  54.     char *wp;           // ptr into workbuf
  55.     int  cp;            // character holding area
  56.     char workbuf[MAXBUFLEN];// working area
  57. } DFA_CLASS;
  58.  
  59.  
  60. extern DFA_CLASS *o;
  61. extern short need_token;
  62. extern short linenbr;
  63. extern short StateMachine(DFA_CLASS *);
  64. extern void InitStateMachine(DFA_CLASS *,
  65.                 void *, char *, FILE *, char *);
  66.  
  67. // declarations for DFA_CLASS functions    */
  68. extern short block(char *);
  69. extern short errmsg(char *);
  70. extern char *get_token(DFA_CLASS *);
  71. extern short isEOF(char *);
  72. extern short isFS(char *);
  73. extern short isGS(char *);
  74. extern short isLBR(char *);
  75. extern short isRBR(char *);
  76. extern short move(DFA_CLASS *, short);
  77. extern void  mystrtok(char *, char *, char *);
  78. extern short skip(char *);
  79.  
  80. #define IGNORE(x)       (x);      // for portability
  81. #define CURRENT_STATE   (o->ndx)
  82. #define STATE_TBL       o->tbl
  83. #define GOODSTATE   (STATE_TBL[CURRENT_STATE].good)
  84. #define BADSTATE    (STATE_TBL[CURRENT_STATE].bad)
  85. #define GOODFCN(x)  \
  86.     ((*(STATE_TBL[CURRENT_STATE].goodfcn))(x))
  87. #define BADFCN(x)   \
  88.     ((*(STATE_TBL[CURRENT_STATE].badfcn))(x))
  89. #define TARGET(x)   \
  90.         ((*(STATE_TBL[CURRENT_STATE].target))(x))
  91. #define NEXT_STATE(x)   ((*o->movest)(o,x))
  92. #define GET_TOKEN       ((*o->get_token)(o))
  93. #define INFILE            (o->infile)
  94.  
  95. // Useful Macros
  96. #define PTRSUB(p,x)     ((long) p - (long) x)
  97. #define PTRADD(p,x)     ((long) p + (long) x)
  98. #define LASTBYTE(x)     (x[strlen(x)-1])
  99. #define DIMEN(x)    (sizeof(x)/sizeof(x[0]))
  100.  
  101.  
  102.