keywords.c
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:6k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. /*-------------------------------------------------------------------------
  2.  *
  3.  * keywords.c
  4.  *   lexical token lookup for reserved words in postgres SQL
  5.  *
  6.  * Copyright (c) 1994, Regents of the University of California
  7.  *
  8.  *
  9.  * IDENTIFICATION
  10.  *   $Header: /usr/local/cvsroot/pgsql/src/backend/parser/keywords.c,v 1.57 1999/05/12 07:22:52 thomas Exp $
  11.  *
  12.  *-------------------------------------------------------------------------
  13.  */
  14. #include <ctype.h>
  15. #include <string.h>
  16. #include "postgres.h"
  17. #include "nodes/parsenodes.h"
  18. #include "nodes/pg_list.h"
  19. #include "parse.h"
  20. #include "parser/keywords.h"
  21. #include "utils/elog.h"
  22. /*
  23.  * List of (keyword-name, keyword-token-value) pairs.
  24.  *
  25.  * !!WARNING!!: This list must be sorted, because binary
  26.  *  search is used to locate entries.
  27.  */
  28. static ScanKeyword ScanKeywords[] = {
  29. /* name, value */
  30. {"abort", ABORT_TRANS},
  31. {"absolute", ABSOLUTE},
  32. {"access", ACCESS},
  33. {"action", ACTION},
  34. {"add", ADD},
  35. {"after", AFTER},
  36. {"aggregate", AGGREGATE},
  37. {"all", ALL},
  38. {"alter", ALTER},
  39. {"analyze", ANALYZE},
  40. {"and", AND},
  41. {"any", ANY},
  42. {"as", AS},
  43. {"asc", ASC},
  44. {"backward", BACKWARD},
  45. {"before", BEFORE},
  46. {"begin", BEGIN_TRANS},
  47. {"between", BETWEEN},
  48. {"binary", BINARY},
  49. {"both", BOTH},
  50. {"by", BY},
  51. {"cache", CACHE},
  52. {"cascade", CASCADE},
  53. {"case", CASE},
  54. {"cast", CAST},
  55. {"char", CHAR},
  56. {"character", CHARACTER},
  57. {"check", CHECK},
  58. {"close", CLOSE},
  59. {"cluster", CLUSTER},
  60. {"coalesce", COALESCE},
  61. {"collate", COLLATE},
  62. {"column", COLUMN},
  63. {"commit", COMMIT},
  64. {"committed", COMMITTED},
  65. {"constraint", CONSTRAINT},
  66. {"copy", COPY},
  67. {"create", CREATE},
  68. {"createdb", CREATEDB},
  69. {"createuser", CREATEUSER},
  70. {"cross", CROSS},
  71. {"current_date", CURRENT_DATE},
  72. {"current_time", CURRENT_TIME},
  73. {"current_timestamp", CURRENT_TIMESTAMP},
  74. {"current_user", CURRENT_USER},
  75. {"cursor", CURSOR},
  76. {"cycle", CYCLE},
  77. {"database", DATABASE},
  78. {"day", DAY_P},
  79. {"decimal", DECIMAL},
  80. {"declare", DECLARE},
  81. {"default", DEFAULT},
  82. {"delete", DELETE},
  83. {"delimiters", DELIMITERS},
  84. {"desc", DESC},
  85. {"distinct", DISTINCT},
  86. {"do", DO},
  87. {"double", DOUBLE},
  88. {"drop", DROP},
  89. {"each", EACH},
  90. {"else", ELSE},
  91. {"encoding", ENCODING},
  92. {"end", END_TRANS},
  93. /***S*I***/
  94. {"except", EXCEPT},
  95. {"exclusive", EXCLUSIVE},
  96. {"execute", EXECUTE},
  97. {"exists", EXISTS},
  98. {"explain", EXPLAIN},
  99. {"extend", EXTEND},
  100. {"extract", EXTRACT},
  101. {"false", FALSE_P},
  102. {"fetch", FETCH},
  103. {"float", FLOAT},
  104. {"for", FOR},
  105. {"foreign", FOREIGN},
  106. {"forward", FORWARD},
  107. {"from", FROM},
  108. {"full", FULL},
  109. {"function", FUNCTION},
  110. {"global", GLOBAL},
  111. {"grant", GRANT},
  112. {"group", GROUP},
  113. {"handler", HANDLER},
  114. {"having", HAVING},
  115. {"hour", HOUR_P},
  116. {"in", IN},
  117. {"increment", INCREMENT},
  118. {"index", INDEX},
  119. {"inherits", INHERITS},
  120. {"inner", INNER_P},
  121. {"insensitive", INSENSITIVE},
  122. {"insert", INSERT},
  123. {"instead", INSTEAD},
  124. /***S*I***/
  125. {"intersect", INTERSECT},
  126. {"interval", INTERVAL},
  127. {"into", INTO},
  128. {"is", IS},
  129. {"isnull", ISNULL},
  130. {"isolation", ISOLATION},
  131. {"join", JOIN},
  132. {"key", KEY},
  133. {"lancompiler", LANCOMPILER},
  134. {"language", LANGUAGE},
  135. {"leading", LEADING},
  136. {"left", LEFT},
  137. {"level", LEVEL},
  138. {"like", LIKE},
  139. {"limit", LIMIT},
  140. {"listen", LISTEN},
  141. {"load", LOAD},
  142. {"local", LOCAL},
  143. {"location", LOCATION},
  144. {"lock", LOCK_P},
  145. {"match", MATCH},
  146. {"maxvalue", MAXVALUE},
  147. {"minute", MINUTE_P},
  148. {"minvalue", MINVALUE},
  149. {"mode", MODE},
  150. {"month", MONTH_P},
  151. {"move", MOVE},
  152. {"names", NAMES},
  153. {"national", NATIONAL},
  154. {"natural", NATURAL},
  155. {"nchar", NCHAR},
  156. {"new", NEW},
  157. {"next", NEXT},
  158. {"no", NO},
  159. {"nocreatedb", NOCREATEDB},
  160. {"nocreateuser", NOCREATEUSER},
  161. {"none", NONE},
  162. {"not", NOT},
  163. {"nothing", NOTHING},
  164. {"notify", NOTIFY},
  165. {"notnull", NOTNULL},
  166. {"null", NULL_P},
  167. {"nullif", NULLIF},
  168. {"numeric", NUMERIC},
  169. {"of", OF},
  170. {"offset", OFFSET},
  171. {"oids", OIDS},
  172. {"old", CURRENT},
  173. {"on", ON},
  174. {"only", ONLY},
  175. {"operator", OPERATOR},
  176. {"option", OPTION},
  177. {"or", OR},
  178. {"order", ORDER},
  179. {"outer", OUTER_P},
  180. {"partial", PARTIAL},
  181. {"password", PASSWORD},
  182. {"position", POSITION},
  183. {"precision", PRECISION},
  184. {"primary", PRIMARY},
  185. {"prior", PRIOR},
  186. {"privileges", PRIVILEGES},
  187. {"procedural", PROCEDURAL},
  188. {"procedure", PROCEDURE},
  189. {"public", PUBLIC},
  190. {"read", READ},
  191. {"references", REFERENCES},
  192. {"relative", RELATIVE},
  193. {"rename", RENAME},
  194. {"reset", RESET},
  195. {"returns", RETURNS},
  196. {"revoke", REVOKE},
  197. {"right", RIGHT},
  198. {"rollback", ROLLBACK},
  199. {"row", ROW},
  200. {"rule", RULE},
  201. {"scroll", SCROLL},
  202. {"second", SECOND_P},
  203. {"select", SELECT},
  204. {"sequence", SEQUENCE},
  205. {"serial", SERIAL},
  206. {"serializable", SERIALIZABLE},
  207. {"set", SET},
  208. {"setof", SETOF},
  209. {"share", SHARE},
  210. {"show", SHOW},
  211. {"start", START},
  212. {"statement", STATEMENT},
  213. {"stdin", STDIN},
  214. {"stdout", STDOUT},
  215. {"substring", SUBSTRING},
  216. {"table", TABLE},
  217. {"temp", TEMP},
  218. {"temporary", TEMPORARY},
  219. {"then", THEN},
  220. {"time", TIME},
  221. {"timestamp", TIMESTAMP},
  222. {"timezone_hour", TIMEZONE_HOUR},
  223. {"timezone_minute", TIMEZONE_MINUTE},
  224. {"to", TO},
  225. {"trailing", TRAILING},
  226. {"transaction", TRANSACTION},
  227. {"trigger", TRIGGER},
  228. {"trim", TRIM},
  229. {"true", TRUE_P},
  230. {"trusted", TRUSTED},
  231. {"type", TYPE_P},
  232. {"union", UNION},
  233. {"unique", UNIQUE},
  234. {"unlisten", UNLISTEN},
  235. {"until", UNTIL},
  236. {"update", UPDATE},
  237. {"user", USER},
  238. {"using", USING},
  239. {"vacuum", VACUUM},
  240. {"valid", VALID},
  241. {"values", VALUES},
  242. {"varchar", VARCHAR},
  243. {"varying", VARYING},
  244. {"verbose", VERBOSE},
  245. {"version", VERSION},
  246. {"view", VIEW},
  247. {"when", WHEN},
  248. {"where", WHERE},
  249. {"with", WITH},
  250. {"work", WORK},
  251. {"year", YEAR_P},
  252. {"zone", ZONE},
  253. };
  254. ScanKeyword *
  255. ScanKeywordLookup(char *text)
  256. {
  257. ScanKeyword *low = &ScanKeywords[0];
  258. ScanKeyword *high = endof(ScanKeywords) - 1;
  259. ScanKeyword *middle;
  260. int difference;
  261. while (low <= high)
  262. {
  263. middle = low + (high - low) / 2;
  264. difference = strcmp(middle->name, text);
  265. if (difference == 0)
  266. return middle;
  267. else if (difference < 0)
  268. low = middle + 1;
  269. else
  270. high = middle - 1;
  271. }
  272. return NULL;
  273. }