1 /* CCL - lexical analysis
5 * Revision 1.3 1995/02/15 17:42:16 adam
6 * Minor changes of the api of this module. FILE* argument added
9 * Revision 1.2 1995/02/14 19:55:13 adam
10 * Header files ccl.h/cclp.h are gone! They have been merged an
11 * moved to ../include/ccl.h.
12 * Node kind(s) in ccl_rpn_node have changed names.
14 * Revision 1.1 1995/02/13 12:35:21 adam
15 * First version of CCL. Qualifiers aren't handled yet.
26 static int strin (const char *s, const char *cset)
36 const char *ccl_token_and = "and";
37 const char *ccl_token_or = "or";
38 const char *ccl_token_not = "not";
39 const char *ccl_token_set = "set";
41 struct ccl_token *ccl_tokenize (const char *command)
43 const char *cp = command;
44 struct ccl_token *first = NULL;
45 struct ccl_token *last = NULL;
49 while (*cp && strin (cp, " \t\r\n"))
56 first = last = malloc (sizeof (*first));
62 last->next = malloc (sizeof(*first));
64 last->next->prev = last;
73 last->kind = CCL_TOK_EOL;
76 last->kind = CCL_TOK_LP;
79 last->kind = CCL_TOK_RP;
82 last->kind = CCL_TOK_COMMA;
86 last->kind = CCL_TOK_PROX;
87 while (*cp == '%' || *cp == '!')
96 if (*cp == '=' || *cp == '<' || *cp == '>')
99 last->kind = CCL_TOK_REL;
102 else if (cp[-1] == '=')
103 last->kind = CCL_TOK_EQ;
105 last->kind = CCL_TOK_REL;
108 last->kind = CCL_TOK_MINUS;
111 last->kind = CCL_TOK_TERM;
114 while (*cp && *cp != '\"')
123 while (*cp && !strin (cp, "(),%!><=- \t\n\r"))
128 if (strlen (ccl_token_and)==last->len &&
129 !memcmp (ccl_token_and, last->name, last->len))
130 last->kind = CCL_TOK_AND;
131 else if (strlen (ccl_token_or)==last->len &&
132 !memcmp (ccl_token_or, last->name, last->len))
133 last->kind = CCL_TOK_OR;
134 else if (strlen (ccl_token_not)==last->len &&
135 !memcmp (ccl_token_not, last->name, last->len))
136 last->kind = CCL_TOK_NOT;
137 else if (strlen (ccl_token_set)==last->len &&
138 !memcmp (ccl_token_set, last->name, last->len))
139 last->kind = CCL_TOK_SET;
141 last->kind = CCL_TOK_TERM;