15 /* not quite reserved, but will fallback to WORD in the grammar */
16 static struct reserved rwords[] = {
17 { "case", TOKEN_Case }
18 ,{ "esac", TOKEN_Esac }
21 ,{ "then", TOKEN_Then }
22 ,{ "else", TOKEN_Else }
23 ,{ "elif", TOKEN_Elif }
26 ,{ "done", TOKEN_Done }
27 ,{ "while", TOKEN_While }
28 ,{ "until", TOKEN_Until }
31 ,{ "}", TOKEN_Rbrace }
32 ,{ "{", TOKEN_Lbrace }
36 static int is_name(char *word) {
38 if (isdigit(word[0])) {
41 for (i=0;word[i];i++) {
42 if (word[i] != '_' && !isalnum(word[i])) {
49 static int is_reserved(char *word) {
51 for (i=0;rwords[i].token;i++) {
52 fprintf(stderr, "checking rword %s ?= %s\n", word, rwords[i].word);
53 if (!strcmp(word, rwords[i].word)) {
54 fprintf(stderr, "matched\n");
55 return rwords[i].token;
63 struct token_state ts;
67 struct parser_state pstate;
71 parser = ParseAlloc(malloc);
73 ParseTrace(stderr, "par: ");
74 while(type = get_token(&ts, &token)) {
76 if (type == EOF) break;
77 if (token.type == TOKEN_WORD) {
78 rtype = is_reserved(token.text);
79 if (!rtype && is_name(token.text) && 0) {
86 token.rtype = token.type;
89 fprintf(stderr, "feeding type %d\n", token.rtype);
91 Parse(parser, token.rtype, &token, &pstate);
93 Parse(parser, 0, &token, &pstate);
98 ParseFree(parser, free );