xref: /illumos-gate/usr/src/cmd/oawk/token.c (revision 4774dff6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 #include "awk.h"
26 
27 struct tok
28 {	char *tnm;
29 	int yval;
30 } tok[]	= {
31 "FIRSTTOKEN", 257,
32 "FINAL", 258,
33 "FATAL", 259,
34 "LT", 260,
35 "LE", 261,
36 "GT", 262,
37 "GE", 263,
38 "EQ", 264,
39 "NE", 265,
40 "MATCH", 266,
41 "NOTMATCH", 267,
42 "APPEND", 268,
43 "ADD", 269,
44 "MINUS", 270,
45 "MULT", 271,
46 "DIVIDE", 272,
47 "MOD", 273,
48 "UMINUS", 274,
49 "ASSIGN", 275,
50 "ADDEQ", 276,
51 "SUBEQ", 277,
52 "MULTEQ", 278,
53 "DIVEQ", 279,
54 "MODEQ", 280,
55 "JUMP", 281,
56 "XBEGIN", 282,
57 "XEND", 283,
58 "NL", 284,
59 "PRINT", 285,
60 "PRINTF", 286,
61 "SPRINTF", 287,
62 "SPLIT", 288,
63 "IF", 289,
64 "ELSE", 290,
65 "WHILE", 291,
66 "FOR", 292,
67 "IN", 293,
68 "NEXT", 294,
69 "EXIT", 295,
70 "BREAK", 296,
71 "CONTINUE", 297,
72 "PROGRAM", 298,
73 "PASTAT", 299,
74 "PASTAT2", 300,
75 "ASGNOP", 301,
76 "BOR", 302,
77 "AND", 303,
78 "NOT", 304,
79 "NUMBER", 305,
80 "VAR", 306,
81 "ARRAY", 307,
82 "FNCN", 308,
83 "SUBSTR", 309,
84 "LSUBSTR", 310,
85 "INDEX", 311,
86 "GETLINE", 312,
87 "RELOP", 313,
88 "MATCHOP", 314,
89 "OR", 315,
90 "STRING", 316,
91 "DOT", 317,
92 "CCL", 318,
93 "NCCL", 319,
94 "CHAR", 320,
95 "CAT", 321,
96 "STAR", 322,
97 "PLUS", 323,
98 "QUEST", 324,
99 "POSTINCR", 325,
100 "PREINCR", 326,
101 "POSTDECR", 327,
102 "PREDECR", 328,
103 "INCR", 329,
104 "DECR", 330,
105 "FIELD", 331,
106 "INDIRECT", 332,
107 "JUMPTRUE", 333,
108 "JUMPFALSE", 334,
109 "PUSH", 335,
110 "GETREC", 336,
111 "NEWSTAT", 337,
112 "IN_INIT", 338,
113 "IN_EXIT", 339,
114 "LASTTOKEN", 340,
115 };
116 void
ptoken(int n)117 ptoken(int n)
118 {
119 	if (n < 128) printf("lex: %c\n", n);
120 	else	if (n <= 256) printf("lex:? %o\n", n);
121 	else	if (n < LASTTOKEN) printf("lex: %s\n", tok[n-257].tnm);
122 	else	printf("lex:? %o\n", n);
123 }
124 
125 char *
tokname(int n)126 tokname(int n)
127 {
128 	if (n <= 256 || n >= LASTTOKEN)
129 		n = 257;
130 	return (tok[n-257].tnm);
131 }
132