1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000, 2005 Free Software Foundation, Inc.
3 Written by John Darrington <john@darrington.wattle.id.au>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 This file is concerned with the definition of the PSPP syntax, NOT the
22 action of scanning/parsing code .
26 #include "identifier.h"
33 /* Table of keywords. */
34 const char *keywords[T_N_KEYWORDS + 1] =
37 "EQ", "GE", "GT", "LE", "LT", "NE",
38 "ALL", "BY", "TO", "WITH",
42 /* Recognizing identifiers. */
44 /* Returns true if C may be the first character in an
45 identifier in the current locale. */
50 return isalpha (c) || c == '@' || c == '#' || c == '$';
54 /* Returns true if C may be a character in an identifier other
60 return lex_is_id1 (c) || isdigit (c) || c == '.' || c == '_';
63 /* If string S begins with an identifier, returns the first
64 character following it. Otherwise, returns S unchanged. */
66 lex_skip_identifier (const char *s)
71 while (lex_is_idn (*s))
77 /* Comparing identifiers. */
79 /* Keywords match if one of the following is true: KW and TOK are
80 identical (except for differences in case), or TOK is at least 3
81 characters long and those characters are identical to KW. KW_LEN
82 is the length of KW, TOK_LEN is the length of TOK. */
84 lex_id_match_len (const char *kw, size_t kw_len,
85 const char *tok, size_t tok_len)
92 if (i == kw_len && i == tok_len)
94 else if (i == tok_len)
98 else if (toupper ((unsigned char) kw[i])
99 != toupper ((unsigned char) tok[i]))
106 /* Same as lex_id_match_len() minus the need to pass in the lengths. */
108 lex_id_match (const char *kw, const char *tok)
110 return lex_id_match_len (kw, strlen (kw), tok, strlen (tok));
115 /* Returns the proper token type, either T_ID or a reserved keyword
116 enum, for ID[], which must contain LEN characters. */
118 lex_id_to_token (const char *id, size_t len)
122 if (len < 2 || len > 4)
125 for (kwp = keywords; *kwp; kwp++)
126 if (!strcasecmp (*kwp, id))
127 return T_FIRST_KEYWORD + (kwp - keywords);