1 /* CCL - lexical analysis
5 * Revision 1.2 1995/02/14 19:55:13 adam
6 * Header files ccl.h/cclp.h are gone! They have been merged an
7 * moved to ../include/ccl.h.
8 * Node kind(s) in ccl_rpn_node have changed names.
10 * Revision 1.1 1995/02/13 12:35:21 adam
11 * First version of CCL. Qualifiers aren't handled yet.
22 static int strin (const char *s, const char *cset)
32 char *ccl_token_and = "and";
33 char *ccl_token_or = "or";
34 char *ccl_token_not = "not";
35 char *ccl_token_set = "set";
37 struct ccl_token *ccl_tokenize (const char *command)
39 const char *cp = command;
40 struct ccl_token *first = NULL;
41 struct ccl_token *last = NULL;
45 while (*cp && strin (cp, " \t\r\n"))
52 first = last = malloc (sizeof (*first));
58 last->next = malloc (sizeof(*first));
60 last->next->prev = last;
69 last->kind = CCL_TOK_EOL;
72 last->kind = CCL_TOK_LP;
75 last->kind = CCL_TOK_RP;
78 last->kind = CCL_TOK_COMMA;
82 last->kind = CCL_TOK_PROX;
83 while (*cp == '%' || *cp == '!')
92 if (*cp == '=' || *cp == '<' || *cp == '>')
95 last->kind = CCL_TOK_REL;
98 else if (cp[-1] == '=')
99 last->kind = CCL_TOK_EQ;
101 last->kind = CCL_TOK_REL;
104 last->kind = CCL_TOK_MINUS;
107 last->kind = CCL_TOK_TERM;
110 while (*cp && *cp != '\"')
119 while (*cp && !strin (cp, "(),%!><=- \t\n\r"))
124 if (strlen (ccl_token_and)==last->len &&
125 !memcmp (ccl_token_and, last->name, last->len))
126 last->kind = CCL_TOK_AND;
127 else if (strlen (ccl_token_or)==last->len &&
128 !memcmp (ccl_token_or, last->name, last->len))
129 last->kind = CCL_TOK_OR;
130 else if (strlen (ccl_token_not)==last->len &&
131 !memcmp (ccl_token_not, last->name, last->len))
132 last->kind = CCL_TOK_NOT;
133 else if (strlen (ccl_token_set)==last->len &&
134 !memcmp (ccl_token_set, last->name, last->len))
135 last->kind = CCL_TOK_SET;
137 last->kind = CCL_TOK_TERM;