Git init
[external/mawk.git] / kw.c
1
2 /********************************************
3 kw.c
4 copyright 1991, Michael D. Brennan
5
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
8
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
12
13
14 /* $Log: kw.c,v $
15  * Revision 1.2  1993/07/17  13:22:59  mike
16  * indent and general code cleanup
17  *
18  * Revision 1.1.1.1  1993/07/03  18:58:15  mike
19  * move source to cvs
20  *
21  * Revision 5.1  1991/12/05  07:56:12  brennan
22  * 1.1 pre-release
23  *
24 */
25
26
27 /* kw.c */
28
29
30 #include "mawk.h"
31 #include "symtype.h"
32 #include "parse.h"
33 #include "init.h"
34
35
36 static struct kw
37 {
38    char *text ;
39    short kw ;
40 }
41 keywords[] =
42 {
43
44    {"print", PRINT},
45    {"printf", PRINTF},
46    {"do", DO},
47    {"while", WHILE},
48    {"for", FOR},
49    {"break", BREAK},
50    {"continue", CONTINUE},
51    {"if", IF},
52    {"else", ELSE},
53    {"in", IN},
54    {"delete", DELETE},
55    {"split", SPLIT},
56    {"match", MATCH_FUNC},
57    {"BEGIN", BEGIN},
58    {"END", END},
59    {"exit", EXIT},
60    {"next", NEXT},
61    {"return", RETURN},
62    {"getline", GETLINE},
63    {"sub", SUB},
64    {"gsub", GSUB},
65    {"function", FUNCTION},
66    {(char *) 0, 0}
67 } ;
68
69 /* put keywords in the symbol table */
70 void
71 kw_init()
72 {
73    register struct kw *p = keywords ;
74    register SYMTAB *q ;
75
76    while (p->text)
77    {
78       q = insert(p->text) ;
79       q->type = ST_KEYWORD ;
80       q->stval.kw = p++->kw ;
81    }
82 }
83
84 /* find a keyword to emit an error message */
85 char *
86 find_kw_str(kw_token)
87    int kw_token ;
88 {
89    struct kw *p ;
90
91    for (p = keywords; p->text; p++)
92       if (p->kw == kw_token)  return p->text ;
93    /* search failed */
94    return (char *) 0 ;
95 }