home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / MacPerl Source ƒ / Perl5 / x2p / a2p.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-05  |  6.0 KB  |  333 lines  |  [TEXT/MPS ]

  1. /* $RCSfile: a2p.h,v $$Revision: 4.1 $$Date: 92/08/07 18:29:09 $
  2.  *
  3.  *    Copyright (c) 1991, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  * $Log:    a2p.h,v $
  9.  */
  10.  
  11. #define VOIDUSED 1
  12. #include <compat.h>
  13. #include "::config.h"
  14.  
  15. #ifndef HAS_BCOPY
  16. #   define bcopy(s1,s2,l) memcpy(s2,s1,l)
  17. #endif
  18. #ifndef HAS_BZERO
  19. #   define bzero(s,l) memset(s,0,l)
  20. #endif
  21.  
  22. #include "handy.h"
  23. #define Nullop 0
  24.  
  25. #define OPROG        1
  26. #define OJUNK        2
  27. #define OHUNKS        3
  28. #define ORANGE        4
  29. #define OPAT        5
  30. #define OHUNK        6
  31. #define OPPAREN        7
  32. #define OPANDAND    8
  33. #define OPOROR        9
  34. #define OPNOT        10
  35. #define OCPAREN        11
  36. #define OCANDAND    12
  37. #define OCOROR        13
  38. #define OCNOT        14
  39. #define ORELOP        15
  40. #define ORPAREN        16
  41. #define OMATCHOP    17
  42. #define OMPAREN        18
  43. #define OCONCAT        19
  44. #define OASSIGN        20
  45. #define OADD        21
  46. #define OSUBTRACT    22
  47. #define OMULT        23
  48. #define ODIV        24
  49. #define OMOD        25
  50. #define OPOSTINCR    26
  51. #define OPOSTDECR    27
  52. #define OPREINCR    28
  53. #define OPREDECR    29
  54. #define OUMINUS        30
  55. #define OUPLUS        31
  56. #define OPAREN        32
  57. #define OGETLINE    33
  58. #define OSPRINTF    34
  59. #define OSUBSTR        35
  60. #define OSTRING        36
  61. #define OSPLIT        37
  62. #define OSNEWLINE    38
  63. #define OINDEX        39
  64. #define ONUM        40
  65. #define OSTR        41
  66. #define OVAR        42
  67. #define OFLD        43
  68. #define ONEWLINE    44
  69. #define OCOMMENT    45
  70. #define OCOMMA        46
  71. #define OSEMICOLON    47
  72. #define OSCOMMENT    48
  73. #define OSTATES        49
  74. #define OSTATE        50
  75. #define OPRINT        51
  76. #define OPRINTF        52
  77. #define OBREAK        53
  78. #define ONEXT        54
  79. #define OEXIT        55
  80. #define OCONTINUE    56
  81. #define OREDIR        57
  82. #define OIF        58
  83. #define OWHILE        59
  84. #define OFOR        60
  85. #define OFORIN        61
  86. #define OVFLD        62
  87. #define OBLOCK        63
  88. #define OREGEX        64
  89. #define OLENGTH        65
  90. #define OLOG        66
  91. #define OEXP        67
  92. #define OSQRT        68
  93. #define OINT        69
  94. #define ODO        70
  95. #define OPOW        71
  96. #define OSUB        72
  97. #define OGSUB        73
  98. #define OMATCH        74
  99. #define OUSERFUN    75
  100. #define OUSERDEF    76
  101. #define OCLOSE        77
  102. #define OATAN2        78
  103. #define OSIN        79
  104. #define OCOS        80
  105. #define ORAND        81
  106. #define OSRAND        82
  107. #define ODELETE        83
  108. #define OSYSTEM        84
  109. #define OCOND        85
  110. #define ORETURN        86
  111. #define ODEFINED    87
  112. #define OSTAR        88
  113.  
  114. #ifdef DOINIT
  115. char *opname[] = {
  116.     "0",
  117.     "PROG",
  118.     "JUNK",
  119.     "HUNKS",
  120.     "RANGE",
  121.     "PAT",
  122.     "HUNK",
  123.     "PPAREN",
  124.     "PANDAND",
  125.     "POROR",
  126.     "PNOT",
  127.     "CPAREN",
  128.     "CANDAND",
  129.     "COROR",
  130.     "CNOT",
  131.     "RELOP",
  132.     "RPAREN",
  133.     "MATCHOP",
  134.     "MPAREN",
  135.     "CONCAT",
  136.     "ASSIGN",
  137.     "ADD",
  138.     "SUBTRACT",
  139.     "MULT",
  140.     "DIV",
  141.     "MOD",
  142.     "POSTINCR",
  143.     "POSTDECR",
  144.     "PREINCR",
  145.     "PREDECR",
  146.     "UMINUS",
  147.     "UPLUS",
  148.     "PAREN",
  149.     "GETLINE",
  150.     "SPRINTF",
  151.     "SUBSTR",
  152.     "STRING",
  153.     "SPLIT",
  154.     "SNEWLINE",
  155.     "INDEX",
  156.     "NUM",
  157.     "STR",
  158.     "VAR",
  159.     "FLD",
  160.     "NEWLINE",
  161.     "COMMENT",
  162.     "COMMA",
  163.     "SEMICOLON",
  164.     "SCOMMENT",
  165.     "STATES",
  166.     "STATE",
  167.     "PRINT",
  168.     "PRINTF",
  169.     "BREAK",
  170.     "NEXT",
  171.     "EXIT",
  172.     "CONTINUE",
  173.     "REDIR",
  174.     "IF",
  175.     "WHILE",
  176.     "FOR",
  177.     "FORIN",
  178.     "VFLD",
  179.     "BLOCK",
  180.     "REGEX",
  181.     "LENGTH",
  182.     "LOG",
  183.     "EXP",
  184.     "SQRT",
  185.     "INT",
  186.     "DO",
  187.     "POW",
  188.     "SUB",
  189.     "GSUB",
  190.     "MATCH",
  191.     "USERFUN",
  192.     "USERDEF",
  193.     "CLOSE",
  194.     "ATAN2",
  195.     "SIN",
  196.     "COS",
  197.     "RAND",
  198.     "SRAND",
  199.     "DELETE",
  200.     "SYSTEM",
  201.     "COND",
  202.     "RETURN",
  203.     "DEFINED",
  204.     "STAR",
  205.     "89"
  206. };
  207. #else
  208. extern char *opname[];
  209. #endif
  210.  
  211. EXT int mop INIT(1);
  212.  
  213. union u_ops {
  214.     int ival;
  215.     char *cval;
  216. };
  217. #if defined(iAPX286) || defined(M_I286) || defined(I80286)     /* 80286 hack */
  218. #define OPSMAX (64000/sizeof(union u_ops))    /* approx. max segment size */
  219. #else
  220. #define OPSMAX 50000
  221. #endif                             /* 80286 hack */
  222. EXT union u_ops ops[OPSMAX];
  223.  
  224. #include <stdio.h>
  225. #include <ctype.h>
  226.  
  227. typedef struct string STR;
  228. typedef struct htbl HASH;
  229.  
  230. #include "str.h"
  231. #include "hash.h"
  232.  
  233. /* A string is TRUE if not "" or "0". */
  234. #define True(val) (tmps = (val), (*tmps && !(*tmps == '0' && !tmps[1])))
  235. EXT char *Yes INIT("1");
  236. EXT char *No INIT("");
  237.  
  238. #define str_true(str) (Str = (str), (Str->str_pok ? True(Str->str_ptr) : (Str->str_nok ? (Str->str_nval != 0.0) : 0 )))
  239.  
  240. #define str_peek(str) (Str = (str), (Str->str_pok ? Str->str_ptr : (Str->str_nok ? (sprintf(buf,"num(%g)",Str->str_nval),buf) : "" )))
  241. #define str_get(str) (Str = (str), (Str->str_pok ? Str->str_ptr : str_2ptr(Str)))
  242. #define str_gnum(str) (Str = (str), (Str->str_nok ? Str->str_nval : str_2num(Str)))
  243. EXT STR *Str;
  244.  
  245. #define GROWSTR(pp,lp,len) if (*(lp) < (len)) growstr(pp,lp,len)
  246.  
  247. STR *str_new();
  248.  
  249. char *scanpat();
  250. char *scannum();
  251.  
  252. void str_free();
  253.  
  254. EXT int line INIT(0);
  255.  
  256. EXT FILE *rsfp;
  257. EXT char buf[2048];
  258. EXT char *bufptr INIT(buf);
  259.  
  260. EXT STR *linestr INIT(Nullstr);
  261.  
  262. EXT char tokenbuf[2048];
  263. EXT int expectterm INIT(TRUE);
  264.  
  265. #ifdef DEBUGGING
  266. EXT int debug INIT(0);
  267. EXT int dlevel INIT(0);
  268. #define YYDEBUG 1
  269. extern int yydebug;
  270. #endif
  271.  
  272. EXT STR *freestrroot INIT(Nullstr);
  273.  
  274. EXT STR str_no;
  275. EXT STR str_yes;
  276.  
  277. EXT bool do_split INIT(FALSE);
  278. EXT bool split_to_array INIT(FALSE);
  279. EXT bool set_array_base INIT(FALSE);
  280. EXT bool saw_RS INIT(FALSE);
  281. EXT bool saw_OFS INIT(FALSE);
  282. EXT bool saw_ORS INIT(FALSE);
  283. EXT bool saw_line_op INIT(FALSE);
  284. EXT bool in_begin INIT(TRUE);
  285. EXT bool do_opens INIT(FALSE);
  286. EXT bool do_fancy_opens INIT(FALSE);
  287. EXT bool lval_field INIT(FALSE);
  288. EXT bool do_chop INIT(FALSE);
  289. EXT bool need_entire INIT(FALSE);
  290. EXT bool absmaxfld INIT(FALSE);
  291. EXT bool saw_altinput INIT(FALSE);
  292.  
  293. EXT bool nomemok INIT(FALSE);
  294.  
  295. EXT char const_FS INIT(0);
  296. EXT char *namelist INIT(Nullch);
  297. EXT char fswitch INIT(0);
  298.  
  299. EXT int saw_FS INIT(0);
  300. EXT int maxfld INIT(0);
  301. EXT int arymax INIT(0);
  302. EXT char *nameary[100];
  303.  
  304. EXT STR *opens;
  305.  
  306. EXT HASH *symtab;
  307. EXT HASH *curarghash;
  308.  
  309. #define P_MIN        0
  310. #define P_LISTOP    5
  311. #define P_COMMA        10
  312. #define P_ASSIGN    15
  313. #define P_COND        20
  314. #define P_DOTDOT    25
  315. #define P_OROR        30
  316. #define P_ANDAND    35
  317. #define P_OR        40
  318. #define P_AND        45
  319. #define P_EQ        50
  320. #define P_REL        55
  321. #define P_UNI        60
  322. #define P_FILETEST    65
  323. #define P_SHIFT        70
  324. #define P_ADD        75
  325. #define P_MUL        80
  326. #define P_MATCH        85
  327. #define P_UNARY        90
  328. #define P_POW        95
  329. #define P_AUTO        100
  330. #define P_MAX        999
  331.  
  332. EXT int an;
  333.