xref: /onnv-gate/usr/src/cmd/oawk/token.c (revision 731:eed80a95c4f9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
230Sstevel@tonic-gate /*	  All Rights Reserved  	*/
240Sstevel@tonic-gate 
250Sstevel@tonic-gate 
26*731Srobbin #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include "awk.h"
290Sstevel@tonic-gate 
300Sstevel@tonic-gate struct tok
310Sstevel@tonic-gate {	char *tnm;
320Sstevel@tonic-gate 	int yval;
330Sstevel@tonic-gate } tok[]	= {
340Sstevel@tonic-gate "FIRSTTOKEN", 257,
350Sstevel@tonic-gate "FINAL", 258,
360Sstevel@tonic-gate "FATAL", 259,
370Sstevel@tonic-gate "LT", 260,
380Sstevel@tonic-gate "LE", 261,
390Sstevel@tonic-gate "GT", 262,
400Sstevel@tonic-gate "GE", 263,
410Sstevel@tonic-gate "EQ", 264,
420Sstevel@tonic-gate "NE", 265,
430Sstevel@tonic-gate "MATCH", 266,
440Sstevel@tonic-gate "NOTMATCH", 267,
450Sstevel@tonic-gate "APPEND", 268,
460Sstevel@tonic-gate "ADD", 269,
470Sstevel@tonic-gate "MINUS", 270,
480Sstevel@tonic-gate "MULT", 271,
490Sstevel@tonic-gate "DIVIDE", 272,
500Sstevel@tonic-gate "MOD", 273,
510Sstevel@tonic-gate "UMINUS", 274,
520Sstevel@tonic-gate "ASSIGN", 275,
530Sstevel@tonic-gate "ADDEQ", 276,
540Sstevel@tonic-gate "SUBEQ", 277,
550Sstevel@tonic-gate "MULTEQ", 278,
560Sstevel@tonic-gate "DIVEQ", 279,
570Sstevel@tonic-gate "MODEQ", 280,
580Sstevel@tonic-gate "JUMP", 281,
590Sstevel@tonic-gate "XBEGIN", 282,
600Sstevel@tonic-gate "XEND", 283,
610Sstevel@tonic-gate "NL", 284,
620Sstevel@tonic-gate "PRINT", 285,
630Sstevel@tonic-gate "PRINTF", 286,
640Sstevel@tonic-gate "SPRINTF", 287,
650Sstevel@tonic-gate "SPLIT", 288,
660Sstevel@tonic-gate "IF", 289,
670Sstevel@tonic-gate "ELSE", 290,
680Sstevel@tonic-gate "WHILE", 291,
690Sstevel@tonic-gate "FOR", 292,
700Sstevel@tonic-gate "IN", 293,
710Sstevel@tonic-gate "NEXT", 294,
720Sstevel@tonic-gate "EXIT", 295,
730Sstevel@tonic-gate "BREAK", 296,
740Sstevel@tonic-gate "CONTINUE", 297,
750Sstevel@tonic-gate "PROGRAM", 298,
760Sstevel@tonic-gate "PASTAT", 299,
770Sstevel@tonic-gate "PASTAT2", 300,
780Sstevel@tonic-gate "ASGNOP", 301,
790Sstevel@tonic-gate "BOR", 302,
800Sstevel@tonic-gate "AND", 303,
810Sstevel@tonic-gate "NOT", 304,
820Sstevel@tonic-gate "NUMBER", 305,
830Sstevel@tonic-gate "VAR", 306,
840Sstevel@tonic-gate "ARRAY", 307,
850Sstevel@tonic-gate "FNCN", 308,
860Sstevel@tonic-gate "SUBSTR", 309,
870Sstevel@tonic-gate "LSUBSTR", 310,
880Sstevel@tonic-gate "INDEX", 311,
890Sstevel@tonic-gate "GETLINE", 312,
900Sstevel@tonic-gate "RELOP", 313,
910Sstevel@tonic-gate "MATCHOP", 314,
920Sstevel@tonic-gate "OR", 315,
930Sstevel@tonic-gate "STRING", 316,
940Sstevel@tonic-gate "DOT", 317,
950Sstevel@tonic-gate "CCL", 318,
960Sstevel@tonic-gate "NCCL", 319,
970Sstevel@tonic-gate "CHAR", 320,
980Sstevel@tonic-gate "CAT", 321,
990Sstevel@tonic-gate "STAR", 322,
1000Sstevel@tonic-gate "PLUS", 323,
1010Sstevel@tonic-gate "QUEST", 324,
1020Sstevel@tonic-gate "POSTINCR", 325,
1030Sstevel@tonic-gate "PREINCR", 326,
1040Sstevel@tonic-gate "POSTDECR", 327,
1050Sstevel@tonic-gate "PREDECR", 328,
1060Sstevel@tonic-gate "INCR", 329,
1070Sstevel@tonic-gate "DECR", 330,
1080Sstevel@tonic-gate "FIELD", 331,
1090Sstevel@tonic-gate "INDIRECT", 332,
1100Sstevel@tonic-gate "JUMPTRUE", 333,
1110Sstevel@tonic-gate "JUMPFALSE", 334,
1120Sstevel@tonic-gate "PUSH", 335,
1130Sstevel@tonic-gate "GETREC", 336,
1140Sstevel@tonic-gate "NEWSTAT", 337,
1150Sstevel@tonic-gate "IN_INIT", 338,
1160Sstevel@tonic-gate "IN_EXIT", 339,
1170Sstevel@tonic-gate "LASTTOKEN", 340,
1180Sstevel@tonic-gate };
119*731Srobbin void
ptoken(int n)120*731Srobbin ptoken(int n)
1210Sstevel@tonic-gate {
122*731Srobbin 	if (n < 128) printf("lex: %c\n", n);
123*731Srobbin 	else	if (n <= 256) printf("lex:? %o\n", n);
124*731Srobbin 	else	if (n < LASTTOKEN) printf("lex: %s\n", tok[n-257].tnm);
1250Sstevel@tonic-gate 	else	printf("lex:? %o\n", n);
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate 
128*731Srobbin char *
tokname(n)129*731Srobbin tokname(n)
1300Sstevel@tonic-gate {
131*731Srobbin 	if (n <= 256 || n >= LASTTOKEN)
1320Sstevel@tonic-gate 		n = 257;
1330Sstevel@tonic-gate 	return (tok[n-257].tnm);
1340Sstevel@tonic-gate }
135