-
Notifications
You must be signed in to change notification settings - Fork 0
/
table_kw.c
78 lines (69 loc) · 1.96 KB
/
table_kw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/********************************************
table_kw.c
copyright 1991,2014-2016 Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
Mawk is distributed without warranty under the terms of
the GNU General Public License, version 3, 2007.
If you import elements of this code into another product,
you agree to not name that product mawk.
********************************************/
/* table_kw.c */
#include "mawk.h"
#include "table.h"
#include "parse.h"
#include "init.h"
const static struct kw {
const char * text;
short kw;
} keywords[] = {
{ "BEGIN" , BEGIN },
{ "break" , BREAK },
{ "continue" , CONTINUE },
{ "do" , DO },
{ "delete" , DELETE },
{ "else" , ELSE },
{ "exit" , EXIT },
{ "END" , END },
{ "for" , FOR },
{ "function" , FUNCTION },
{ "getline" , GETLINE },
{ "gsub" , GSUB },
{ "if" , IF },
{ "in" , IN },
{ "length" , LENGTH },
{ "match" , MATCH_FUNC },
{ "next" , NEXT },
{ "nextfile" , NEXTFILE },
{ "print" , PRINT },
{ "printf" , PRINTF },
{ "return" , RETURN },
{ "split" , SPLIT },
{ "sprintf" , SPRINTF },
{ "sub" , SUB },
{ "while" , WHILE },
{ 0, 0 }
};
/* put keywords in the symbol table */
void
kw_init( void )
{
register const struct kw * p = keywords;
register SYMTAB * q;
while ( p->text ) {
q = insert( p->text );
q->type = ST_KEYWORD;
q->stval.kw = p++->kw;
}
}
/* find a keyword to emit an error message */
const char *
find_kw_str( int kw_token )
{
const struct kw * p;
for ( p = keywords; p->text; p++ )
if ( p->kw == kw_token )
return p->text;
/* search failed */
return (char *)0;
}