1 /* CCL - lexical analysis
5 * Revision 1.6 1995/04/17 09:31:48 adam
6 * Improved handling of qualifiers. Aliases or reserved words.
8 * Revision 1.5 1995/02/23 08:32:00 adam
11 * Revision 1.3 1995/02/15 17:42:16 adam
12 * Minor changes of the api of this module. FILE* argument added
15 * Revision 1.2 1995/02/14 19:55:13 adam
16 * Header files ccl.h/cclp.h are gone! They have been merged an
17 * moved to ../include/ccl.h.
18 * Node kind(s) in ccl_rpn_node have changed names.
20 * Revision 1.1 1995/02/13 12:35:21 adam
21 * First version of CCL. Qualifiers aren't handled yet.
32 const char *ccl_token_and = "and";
33 const char *ccl_token_or = "or";
34 const char *ccl_token_not = "not andnot";
35 const char *ccl_token_set = "set";
38 * token_cmp: Compare token with keyword(s)
39 * kw: Keyword list. Each keyword is separated by space.
41 * return: 1 if token string matches one of the keywords in list;
44 static int token_cmp (const char *kw, struct ccl_token *token)
48 while ((cp2 = strchr (cp1, ' ')))
50 if (token->len == cp2-cp1 &&
51 !memcmp (cp1, token->name, token->len))
55 return token->len == strlen(cp1)
56 && !memcmp (cp1, token->name, token->len);
60 * ccl_tokenize: tokenize CCL command string.
61 * return: CCL token list.
63 struct ccl_token *ccl_tokenize (const char *command)
65 const char *cp = command;
66 struct ccl_token *first = NULL;
67 struct ccl_token *last = NULL;
71 while (*cp && strchr (" \t\r\n", *cp))
78 first = last = malloc (sizeof (*first));
84 last->next = malloc (sizeof(*first));
86 last->next->prev = last;
95 last->kind = CCL_TOK_EOL;
98 last->kind = CCL_TOK_LP;
101 last->kind = CCL_TOK_RP;
104 last->kind = CCL_TOK_COMMA;
108 last->kind = CCL_TOK_PROX;
109 while (*cp == '%' || *cp == '!')
118 if (*cp == '=' || *cp == '<' || *cp == '>')
121 last->kind = CCL_TOK_REL;
124 else if (cp[-1] == '=')
125 last->kind = CCL_TOK_EQ;
127 last->kind = CCL_TOK_REL;
130 last->kind = CCL_TOK_MINUS;
133 last->kind = CCL_TOK_TERM;
136 while (*cp && *cp != '\"')
145 while (*cp && !strchr ("(),%!><=- \t\n\r", *cp))
150 if (token_cmp (ccl_token_and, last))
151 last->kind = CCL_TOK_AND;
152 else if (token_cmp (ccl_token_or, last))
153 last->kind = CCL_TOK_OR;
154 else if (token_cmp (ccl_token_not, last))
155 last->kind = CCL_TOK_NOT;
156 else if (token_cmp (ccl_token_set, last))
157 last->kind = CCL_TOK_SET;
159 last->kind = CCL_TOK_TERM;