home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l200 / 6.ddi / TRAN / COM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-21  |  8.6 KB  |  305 lines

  1. /*      COM - Common constants, types and declarations
  2.                 for BASTOC
  3.  
  4.     Copyright (c) 1983 by James F. Gimpel
  5.     Copyright (c) 1983, 1984, 1985 by JMI Software Consultants, Inc.
  6.  
  7.     Not included here are constants and declarations required
  8.     to build customizable tables defined in the administrative
  9.     module.  These are found in at.h
  10.  
  11.             Contents:
  12.  
  13.         1.  Manifest Constants and Macros
  14.             1.1  System Dependent Constants
  15.             1.2  Version (of Basic) Dependencies
  16.             1.3  Limits
  17.             1.4  Tokens
  18.                 1.4.1  Allocation types (at_)
  19.                 1.4.2  Symbol table ops
  20.             1.5  Buffered I/O constants
  21.             1.6  Miscellaneous constants
  22.             1.7  Macros
  23.             1.8  Unreachable code constants
  24.  
  25.         2.  Typedef's
  26.  
  27.         3.  Structure Declarations
  28.             3.1  attr
  29.             3.2  bnd_info
  30.             3.3  dim_info
  31.             3.4  lineinfo
  32.             3.5  scan_buf
  33.             3.6  sym
  34.             3.7 symtab
  35.             3.8 bfstruct
  36.  
  37. */
  38.  
  39. #include "at.h"
  40.  
  41. /*  1. Manifest Constants
  42. */
  43.  
  44. /*  1.3  Limits 
  45. */
  46.  
  47. #define MAXINC 6        /* Maximum include level */
  48. #define li_LEN  257     /* Line length (input line) */
  49. #define MAXWS   20      /* Maximum Write Stack      */
  50. #define MAXFNL  100     /* Maximum file name length  */
  51. #define SP_LEN 1000     /* Size of Semi-Permanent String Store blocks */
  52. #define tok_LEN li_LEN  /* Maximum token size */
  53. #define MAXFLDS 100     /* Maximum no. of fields in a FIELD stmt */
  54. #define MAXEBUF    2000    /* Maximum size for BASIC statement storage */
  55.  
  56. /*  1.4   Miscellaneous Tokens
  57. */
  58.  
  59. /*  1.4.1  Allocation types
  60.         one for each type of block allocated
  61. */
  62.  
  63. #define  at_SYMBOL  1   /* element of a symbol table */
  64. #define  at_SYMTAB  2   /* symbol table root         */
  65. #define  at_DIMINFO 3   /* one dimension of an array */
  66.  
  67. /*  1.4.2  Symbol Table Operations
  68. */
  69.  
  70. #define LOCATE  1   /* Locate Symbol in Table */
  71. #define INSTALL 2   /* Insert if not found    */
  72. #define INSERT  3   /* Insert only            */
  73. #define FINSTALL 4  /* Insert into function's local symbol table */
  74.  
  75. /*  1.5  Constants associated with buffered I/O
  76. */
  77.  
  78. #define sf_NULL     -1  /* Null Device */
  79. #define sf_IN       0   /* Standard INput */
  80. #define sf_OUT      1   /* Standard OUTput */
  81. #define sf_ERR      2   /* Standard ERRor */
  82. #define IN_SLOT     3   /* regular input slot */
  83. #define OUT_SLOT    4   /* regular output slot */
  84. #define DEF_SLOT    5   /* DEF output slot */
  85. #define SUB_SLOT    6   /* subroutine output slot */
  86. #define COM_SLOT    7   /* COMMON output slot */
  87. #define FUN_SLOT    8   /* main(){} output slot for pgm with FIELD stmts */
  88. #define INC_SLOTS   9   /* the first of the include slots */
  89.  
  90. #define NSLOTS INC_SLOTS + MAXINC
  91.  
  92. #define BBUFSIZE 256    /* Basic BUFfer SIZE */
  93.  
  94. /*  1.6  Miscellany
  95. */
  96.  
  97. #define EOS     -1      /* End of statement */
  98.  
  99.  
  100. /*  1.7  Macros
  101. */
  102.  
  103. #define isgrey(x) ((x)==' ' || (x)=='\t')
  104.  
  105. /*  1.8  Unreachable code constants
  106. */
  107.  
  108. #define dis_INCOM    001     /* In comment */
  109. #define dis_NW       002     /* Newline */
  110. #define dis_CHGPROC  004     /* Change procedure */
  111. #define dis_LABEL    010     /* Label (no indent) */
  112.  
  113. /*  2. Typedefs  --  Types not defined are here are defined
  114.                     in acom.h or appear with structures.
  115. */
  116.  
  117. typedef BITS TRBITS;    /* Trace Bits */
  118.  
  119. /*  3.  Structure declarations
  120. */
  121.  
  122. /*  3.1     attr
  123.  
  124.     An ATTRibute structure encapsulates the result of translation
  125. */
  126.  
  127. struct attr
  128.     {
  129.     STRING  a_str;
  130.     BITS    a_flags;
  131.     TOKEN   a_type;
  132.     };
  133. typedef struct attr ATTR;
  134.  
  135. #define a_CONST 01  /* Constant expression */
  136. #define a_NEG   02  /* Explicit Negative sign */
  137. #define a_ONE   04  /* The constant 1 (+ or -) */
  138. #define a_LHS  010  /* The result is a valid left-hand-side */
  139. #define a_FLD  020  /* a field was encountered */
  140. #define a_SLH  040  /* same primary as left hand side of assignment */
  141. #define a_MM  0100  /* expression equivalent to --var */
  142. #define a_PP  0200  /* expression equivalent to ++var */
  143. #define a_PA  0400  /* expression equivalent to x += y  */
  144. #define a_MA 01000  /* expression equivalent to x -= y  */
  145.  
  146. /*  
  147. #define a_VAR   0x0010 */  /* just a variable name (scalar or array) */
  148. /*
  149. #define a_ARR   0x0020 */  /* array element */
  150.  
  151.  
  152. /*  3.3     dim_info
  153.  
  154.     dim_info gives all the information for one dimension;
  155.     a two dimensional array requires two of these, etc.
  156. */
  157.  
  158. struct dim_info
  159.     {
  160.     struct dim_info  *dim_next;
  161.     COUNT  dim_int;  /* either a constant bound or an index
  162.                         to a multiplier variable  */
  163.     };
  164. typedef struct dim_info DIMINFO;
  165.  
  166. /*  3.4     lineinfo
  167.  
  168.     lineinfo is a structure containing the current line
  169.     together with the current position within it.
  170. */
  171.  
  172. struct lineinfo
  173.     {
  174.     STRING  li_ch;
  175.     STRING  li_ptr;
  176.     };
  177. typedef struct lineinfo LINEINFO;
  178.  
  179. /*  3.5     scan_buf
  180.  
  181.     This structure enables the scanner to save state
  182. */
  183.  
  184. struct scan_buf
  185.     {
  186.     STRING  sb_ptr;     /* pointer into current input line */
  187.     COUNT   sb_char;    /* current character */
  188.     };
  189. typedef struct scan_buf SCANBUF;
  190.  
  191. /*  3.6     sym
  192.  
  193.     One of these structures is allocated for each symbol.
  194. */
  195.  
  196. typedef struct sym
  197.     {
  198.     struct sym *sym_lson, *sym_rson;
  199.     BITS    sym_flags;
  200.     STRING  sym_name;
  201.     TOKEN   sym_type;   /* token of the form dt_... */
  202.     TINY    *sym_ptr;   /* a pointer to ancillary information */
  203.     COUNT   sym_int;    /* a handy, multi-purpose integer -- see below */
  204.     COUNT   sym_pre;    /* name prefix code for de-conflicting */
  205.     } *SYMBOL;
  206.  
  207. #define sym_pno sym_int /* procedure no. */
  208. #define sym_nd  sym_int /* No. of dimension */
  209. #define sym_level sym_type /* Label level no. */
  210.  
  211. #define sym_CNC 01      /* Created Name Conflict */
  212. #define sym_ARR 02      /* An Array */
  213. #define sym_DLBL 04     /* A defined (and referenced) label */
  214. #define sym_DEF 010     /* a DEFined function */
  215. #define sym_DUM 020     /* a dummy parameter of a DEFine stmt */
  216. #define sym_TOL 040     /* a GOTO label */
  217. #define sym_SUL 0100    /* a GOSUB label */
  218. #define sym_BFN 0200    /* a built-in function */
  219. #define sym_FIRST 0400  /* the first label */
  220. #define sym_DCL 01000   /* Declared type */
  221. #define sym_FLD 02000   /* An identifier of a FIELD stmt */
  222. #define sym_FVAR 04000  /* The function variable */
  223. #define sym_DARR 010000 /* Dynamic array, implies sym_ARR */
  224. #define sym_SUB 020000 /* subroutines inside a defined function */
  225. #define sym_COM 040000 /* this is a common variable */
  226.  
  227. typedef struct
  228.     {
  229.     struct symtab *fi_labels;   /* symbol table for labels in function */
  230.     struct symtab *fi_scalars;  /* symbol table for scalars in function */
  231.     TEXT *fi_trap;              /* trap list for function */
  232.     BOOL fi_onerrors;           /* ON ERROR GOTOs in function */
  233.     BOOL fi_ifends;             /* IF ENDS in function */
  234.     COUNT fi_tmps;              /* number of string temps in function */
  235.     } FUNCINFO;
  236.  
  237. /*  3.7 symtab
  238.  
  239.     One of these is allocated for each symbol table.
  240.     It is really a symbol table root.
  241. */
  242.  
  243. struct symtab
  244.     {
  245.     SYMBOL  st_head;    /* The head of the tree of symbols */
  246.     STRING  st_name;    /* The symbol name */
  247.     TOKEN   st_type;    /* an allocation type */
  248.     };
  249. typedef struct symtab SYMTAB;
  250.  
  251. #define ST_ARRAY    0   /* symbol table(s) for arrays */
  252. #define ST_SCALAR   1   /* symbol table(s) for scalars */
  253. #define ST_LABEL    2   /* symbol table(s) for labels */
  254. #define ST_FUNC     3   /* symbol table for functons */
  255. #define ST_SEARCH   4   /* ??? */
  256.  
  257. /*  3.8  bfstruct
  258.     One of these is allocated for each open file.
  259. */
  260.  
  261. struct bfstruct
  262.     {
  263.     FILE bf_fd;         /* file descriptor */
  264.     STRING bf_buf;      /* points to buffer */
  265.     STRING bf_bufptr;   /* current position within buffer */
  266.     COUNT bf_reclen;    /* record or buffer length */
  267.     COUNT bf_count;     /* chars. or pos. remaining in buffer */
  268.     BITS bf_flags;
  269.     TEXT  bf_char;      /* place to store an unget */
  270.     };
  271. typedef struct bfstruct BF;
  272.  
  273. /*  bf_flags    */
  274.  
  275. #define bf_ASSOC    01  /* slot is in use */
  276. #define bf_READ     02  /* open for reading */
  277. #define bf_WRITE    04  /* open for writing */
  278. #define bf_ERROR    010 /* an error has been detected */
  279. #define bf_CHAR     020 /* bf_char holds a character */
  280. #define bf_EOF      040 /* end-of-file has been pushed back */
  281.  
  282. /*  4. Diagnostic Trace Control
  283.  
  284. */
  285.  
  286.  
  287. #ifdef TRACE
  288. #define TRACE0(x,a) tr_form(x,a)
  289. #define TRACE1(x,a,b) tr_form(x,a,b)
  290. #define TRACE2(x,a,b,c) tr_form(x,a,b,c)
  291. #define TRACE3(x,a,b,c,d) tr_form(x,a,b,c,d)
  292. #define TRACE4(x,a,b,c,d,e) tr_form(x,a,b,c,d,e)
  293. #define TRACE5(x,a,b,c,d,e,f) tr_form(x,a,b,c,d,e,f)
  294. #define TRACE6(x,a,b,c,d,e,f,g) tr_form(x,a,b,c,d,e,f,g)
  295.  
  296. #else
  297. #define TRACE0(x,a)
  298. #define TRACE1(x,a,b)
  299. #define TRACE2(x,a,b,c)
  300. #define TRACE3(x,a,b,c,d)
  301. #define TRACE4(x,a,b,c,d,e)
  302. #define TRACE5(x,a,b,c,d,e,f)
  303. #define TRACE6(x,a,b,c,d,e,f,g)
  304. #endif
  305.