-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_keyword.gperf
More file actions
51 lines (46 loc) · 1.24 KB
/
java_keyword.gperf
File metadata and controls
51 lines (46 loc) · 1.24 KB
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
%{
/* Command-line:
gperf -o -k 1-3,$ -L C -H keyword_hash -N JavaLangGetKeywordToken -t java_keyword.gperf > java_keyword.c
*/
#include <string.h>
#include <stdio.h>
#include "java_lang_parse.h"
%}
struct java_keyword { const char * name; int tokenType; };
%%
"public", K_PUBLIC
"private", K_PRIVATE
"protected", K_PROTECTED
"int", K_INT
"class", K_CLASS
"String", K_STRING
"static", K_STATIC
"new", K_NEW
"void", K_VOID
"return", K_RETURN
%%
/*
// Below is used for test your code before integrated your gperf file
// into the project. Un-comment the below lines, and use the command:
//
// $ gperf -o -k 1-3,$ -L C -H keyword_hash -N JavaLangGetKeywordToken -t java_keyword.gperf > java_keyword.c
// $ gcc -o javagperf java_keyword.c
// $ ./javagperf
int main (void)
{
char c[100];
puts("input a keyword :\n");
gets(c);
while (strlen(c) > 1) {
puts(c);
const struct java_keyword *key_token = JavaLangGetKeywordToken(c, strlen(c));
if (key_token == 0) {
printf("UnKnow!\n");
}
else {
printf("Type %s is: %d\n", (key_token->name),key_token->tokenType);
}
gets(c);
}
}
*/