1 /* CCL - lexical analysis
5 * Revision 1.7 1995/04/19 12:11:24 adam
8 * Revision 1.6 1995/04/17 09:31:48 adam
9 * Improved handling of qualifiers. Aliases or reserved words.
11 * Revision 1.5 1995/02/23 08:32:00 adam
14 * Revision 1.3 1995/02/15 17:42:16 adam
15 * Minor changes of the api of this module. FILE* argument added
18 * Revision 1.2 1995/02/14 19:55:13 adam
19 * Header files ccl.h/cclp.h are gone! They have been merged an
20 * moved to ../include/ccl.h.
21 * Node kind(s) in ccl_rpn_node have changed names.
23 * Revision 1.1 1995/02/13 12:35:21 adam
24 * First version of CCL. Qualifiers aren't handled yet.
35 const char *ccl_token_and = "and";
36 const char *ccl_token_or = "or";
37 const char *ccl_token_not = "not andnot";
38 const char *ccl_token_set = "set";
41 * token_cmp: Compare token with keyword(s)
42 * kw: Keyword list. Each keyword is separated by space.
44 * return: 1 if token string matches one of the keywords in list;
47 static int token_cmp (const char *kw, struct ccl_token *token)
53 while ((cp2 = strchr (cp1, ' ')))
55 if (token->len == cp2-cp1 &&
56 !memcmp (cp1, token->name, token->len))
60 return token->len == strlen(cp1)
61 && !memcmp (cp1, token->name, token->len);
65 * ccl_tokenize: tokenize CCL command string.
66 * return: CCL token list.
68 struct ccl_token *ccl_tokenize (const char *command)
70 const char *cp = command;
71 struct ccl_token *first = NULL;
72 struct ccl_token *last = NULL;
76 while (*cp && strchr (" \t\r\n", *cp))
83 first = last = malloc (sizeof (*first));
89 last->next = malloc (sizeof(*first));
91 last->next->prev = last;
100 last->kind = CCL_TOK_EOL;
103 last->kind = CCL_TOK_LP;
106 last->kind = CCL_TOK_RP;
109 last->kind = CCL_TOK_COMMA;
113 last->kind = CCL_TOK_PROX;
114 while (*cp == '%' || *cp == '!')
123 if (*cp == '=' || *cp == '<' || *cp == '>')
126 last->kind = CCL_TOK_REL;
129 else if (cp[-1] == '=')
130 last->kind = CCL_TOK_EQ;
132 last->kind = CCL_TOK_REL;
135 last->kind = CCL_TOK_MINUS;
138 last->kind = CCL_TOK_TERM;
141 while (*cp && *cp != '\"')
150 while (*cp && !strchr ("(),%!><=- \t\n\r", *cp))
155 if (token_cmp (ccl_token_and, last))
156 last->kind = CCL_TOK_AND;
157 else if (token_cmp (ccl_token_or, last))
158 last->kind = CCL_TOK_OR;
159 else if (token_cmp (ccl_token_not, last))
160 last->kind = CCL_TOK_NOT;
161 else if (token_cmp (ccl_token_set, last))
162 last->kind = CCL_TOK_SET;
164 last->kind = CCL_TOK_TERM;