00001 /* 00002 * a small awk clone 00003 * 00004 * (C) 1989 Saeko Hirabauashi & Kouichi Hirabayashi 00005 * 00006 * Absolutely no warranty. Use this software with your own risk. 00007 * 00008 * Permission to use, copy, modify and distribute this software for any 00009 * purpose and without fee is hereby granted, provided that the above 00010 * copyright and disclaimer notice. 00011 * 00012 * This program was written to fit into 64K+64K memory of the Minix 1.2. 00013 */ 00014 00015 /* lexical/parser tokens and executable statements */ 00016 00017 #define FIRSTP 256 00018 #define ARG 256 00019 #define ARITH 257 00020 #define ARRAY 258 00021 #define ASSIGN 259 00022 #define CALL 260 00023 #define CAT 261 00024 #define COND 262 00025 #define DELETE 263 00026 #define DO 264 00027 #define ELEMENT 265 00028 #define FIELD 266 00029 #define FOR 267 00030 #define FORIN 268 00031 #define GETLINE 269 00032 #define IF 270 00033 #define IN 271 00034 #define JUMP 272 00035 #define MATHFUN 273 00036 #define NULPROC 274 00037 #define P1STAT 275 00038 #define P2STAT 276 00039 #define PRINT 277 00040 #define PRINT0 278 00041 #define STRFUN 279 00042 #define SUBST 280 00043 #define USRFUN 281 00044 #define WHILE 282 00045 #define LASTP 282 00046 /* lexical token */ 00047 00048 #define ADD 300 /* + */ 00049 #define ADDEQ 301 /* += */ 00050 #define AND 302 /* && */ 00051 #define BEGIN 303 /* BEGIN */ 00052 #define BINAND 304 /* & */ 00053 #define BINOR 305 /* | */ 00054 #define BREAK 306 /* break */ 00055 #define CLOSE 307 /* close */ 00056 #define CONTIN 308 /* continue */ 00057 #define DEC 309 /* -- */ 00058 #define DIV 310 /* / */ 00059 #define DIVEQ 311 /* /= */ 00060 #define ELSE 312 /* else */ 00061 #define END 313 /* END */ 00062 #define EOL 314 /* ; or '\n' */ 00063 #define EQ 315 /* == */ 00064 #define EXIT 316 /* exit */ 00065 #define FUNC 317 /* function */ 00066 #define GE 318 /* >= */ 00067 #define GT 319 /* > */ 00068 #define IDENT 320 /* identifier */ 00069 #define INC 321 /* ++ */ 00070 #define LE 322 /* <= */ 00071 #define LT 323 /* < */ 00072 #define MATCH 324 /* ~ */ 00073 #define MOD 325 /* % */ 00074 #define MODEQ 326 /* %= */ 00075 #define MULT 327 /* * */ 00076 #define MULTEQ 328 /* *= */ 00077 #define NE 329 /* != */ 00078 #define NEXT 330 /* next */ 00079 #define NOMATCH 331 /* !~ */ 00080 #define NOT 332 /* ! */ 00081 #define NUMBER 333 /* integer or floating number */ 00082 #define OR 334 /* || */ 00083 #define POWEQ 335 /* ^= */ 00084 #define POWER 336 /* ^ */ 00085 #define PRINTF 337 /* printf */ 00086 #define REGEXP 338 /* /REG/ */ 00087 #define RETURN 339 /* return */ 00088 #define SHIFTL 340 /* << */ 00089 #define SHIFTR 341 /* >> */ 00090 #define SPRINT 342 /* sprint */ 00091 #define SPRINTF 343 /* sprintf */ 00092 #define STRING 344 /* ".." */ 00093 #define SUB 345 /* - */ 00094 #define SUBEQ 346 /* -= */ 00095 #define SYSTEM 347 /* system */ 00096 #define UMINUS 348 /* - */ 00097 00098 /* tokens in parser */ 00099 00100 #define VALUE 400 /* value node */ 00101 #define INCDEC 401 /* ++, -- */ 00102 #define PRE 402 /* pre incre/decre */ 00103 #define POST 403 /* post incre/decre */ 00104 00105 /* redirect in print(f) statement */ 00106 00107 #define R_OUT 410 /* > */ 00108 #define R_APD 411 /* >> */ 00109 #define R_PIPE 412 /* | */ 00110 #define R_IN 413 /* < */ 00111 #define R_PIN 414 /* | getline */ 00112 #define R_POUT 415 /* print | */ 00113 00114 /* function */ 00115 00116 #define ATAN2 500 /* atan2 */ 00117 #define COS 501 /* cos */ 00118 #define EXP 502 /* exp */ 00119 #define INDEX 503 /* index */ 00120 #define INT 504 /* int */ 00121 #define LENGTH 505 /* length */ 00122 #define LOG 506 /* log */ 00123 #define RAND 507 /* rand */ 00124 #define RGSUB 508 /* gsub */ 00125 #define RMATCH 509 /* match */ 00126 #define RSUB 510 /* sub */ 00127 #define SIN 511 /* sin */ 00128 #define SPLIT 512 /* split */ 00129 #define SQRT 513 /* sqrt */ 00130 #define SRAND 514 /* srand */ 00131 #define SUBSTR 515 /* substr */ 00132 00133 /* print(f) options */ 00134 00135 #define FORMAT 1024 /* PRINTF, SPRINTF */ 00136 #define STROUT 2048 /* SPRINTF */ 00137 #define PRMASK 0x3ff /* ~(FORMAT|STROUT) */ 00138 00139 /* node - used in parsed tree */ 00140 00141 struct node { 00142 int n_type; /* node type */ 00143 struct node *n_next; /* pointer to next node */ 00144 struct node *n_arg[1]; /* argument (variable length) */ 00145 }; 00146 00147 typedef struct node NODE; 00148 00149 /* object cell */ 00150 00151 struct cell { 00152 int c_type; /* cell type */ 00153 char *c_sval; /* string value */ 00154 double c_fval; /* floating value */ 00155 }; 00156 00157 typedef struct cell CELL; 00158 00159 /* cell type */ 00160 00161 #define UDF 0 /* pass parameter */ 00162 #define VAR 1 /* variable */ 00163 #define NUM 2 /* number */ 00164 #define ARR 4 /* array */ 00165 #define STR 8 /* string */ 00166 #define REC 16 /* record */ 00167 #define FLD 32 /* filed */ 00168 #define PAT 64 /* pattern (compiled REGEXPR) */ 00169 #define BRK 128 /* break */ 00170 #define CNT 256 /* continue */ 00171 #define NXT 512 /* next */ 00172 #define EXT 1024 /* exit */ 00173 #define RTN 2048 /* return */ 00174 #define TMP 4096 /* temp cell */ 00175 #define POS 8192 /* argument position */ 00176 #define FUN 16384 /* function */ 00177 00178 /* symbol cell - linked to symbol table */ 00179 00180 struct symbol { 00181 char *s_name; 00182 CELL *s_val; 00183 struct symbol *s_next; 00184 }; 00185 00186 typedef struct symbol SYMBOL;
1.5.8