home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / pgen_2 / pg_parse.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-04  |  2.5 KB  |  99 lines

  1. /*    PG_PARSE.H
  2.     Copyright (C) 1992    Keith L. Robertson    All Rights Reserved
  3.  
  4.     Declares the types and functions needed to compile
  5.     the parser and parsing tables (and the parsing table generator).
  6.     Also declare parse (), called by driver program to parse the input.
  7.  
  8.     Any user of this file must type-define LEX_INFO before #including it.
  9. */
  10. #ifndef PG_PARSE_H
  11. #define    PG_PARSE_H
  12.  
  13. #ifndef TYPES_H
  14.  #include <types.h>
  15. #endif
  16.  
  17. #if __cplusplus
  18. extern "C" {
  19. #endif
  20.  
  21.  
  22. /****  The point of all this... Call parse () to parse the input.  ****/
  23. VOID    parse ();
  24.  
  25.  
  26. /****  Used by the semantic actions.  ****/
  27. /* To access symbol attributes. */
  28. extern    LEX_INFO*    attr;
  29.  
  30. /* To advance the input stream to a particular token or set of tokens. */
  31. VOID    skip_to_token (USHORT tok);
  32. VOID    skip_to_bittok (USHORT* tokmap);
  33.  
  34.  
  35. /* ------------------------------------- */
  36.  
  37. typedef VOID    (*SEM_ACTION) ();
  38.  
  39. typedef    struct    {    /* Indexed by production number. */
  40.     UCHAR    nonterm;        /* Nonterminal leading the production */
  41.     SCHAR    size_m1;        /* rhs.count() - 1  */
  42.     SEM_ACTION    sem_action;        /* Semantic action. */
  43. }    PRODUCTION_INFO;
  44.  
  45.  
  46. /* ------------------------------------- */
  47.  
  48. typedef USHORT    ACTION;
  49. #define        action_part(act)    (act >> 14)
  50. #define        second_part(act)    (act & 0x3fff)
  51. #define        action_mix(act,sec)    ((act << 14) | sec)
  52.  
  53. #define        JUMP_ACTION    0
  54. #define        REDUCE_ACTION    1
  55. #define        SHIFT_ACTION    2
  56. #define        ACCEPT_ACTION    3
  57.  
  58. #define        error(sec)    action_mix(JUMP_ACTION,0)
  59. #define        jump(sec)    action_mix(JUMP_ACTION,sec)
  60. #define        reduce(sec)    action_mix(REDUCE_ACTION,sec)
  61. #define        no_change(sec)    action_mix(SHIFT_ACTION,0)
  62. #define        shift(sec)    action_mix(SHIFT_ACTION,sec)
  63. #define        accept(sec)    action_mix(ACCEPT_ACTION,0)
  64.  
  65.  
  66. typedef struct    {
  67.     USHORT    token;
  68.     ACTION    action;
  69. }    ACTION_ITEM;
  70.  
  71. #define        BM        0x4000        /* Lookup token by bitmap */
  72. #define        ERR_TK        0x4ffe
  73. #define        ANY_TK        0x4fff
  74. #define        BR        0x8000        /* BRanch */
  75. /* if (token & BR), branch to ACTION_ITEM (token^BR)
  76.             and on ANY_TK do the given action. */
  77.  
  78. /* Must preserve the order:  ERR_TK < ANY_TK < BR.
  79.    BR must have a bit set that will be clear in all other tokens,
  80.    and there must be room beneath for any item set, or state, number. 
  81. */
  82.  
  83.  
  84. /* ------------------------------------- */
  85.  
  86. typedef struct    {
  87.     USHORT    cur_state;
  88.     USHORT    nxt_state;
  89. }    GOTO_LIST_ITEM;
  90. #define        ANY_ST        0x7fff
  91. #define        BG        0x8000        /* Lookup cur_state by bitmap */
  92.  
  93.  
  94. #if __cplusplus
  95. }
  96. #endif
  97.  
  98. #endif    /* PG_PARSE_H */
  99.