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/interfaces/ecpg/preproc/keywords.c,v 1.13 1999/04/26 05:28:47 meskes 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 "type.h"
  20. #include "preproc.h"
  21. #include "parser/keywords.h"
  22. #include "utils/elog.h"
  23. /*
  24.  * List of (keyword-name, keyword-token-value) pairs.
  25.  *
  26.  * !!WARNING!!: This list must be sorted, because binary
  27.  *  search is used to locate entries.
  28.  */
  29. static ScanKeyword ScanKeywords[] = {
  30. /* name, value */
  31. {"abort", ABORT_TRANS},
  32. {"absolute", ABSOLUTE},
  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. {"constraint", CONSTRAINT},
  65. {"copy", COPY},
  66. {"create", CREATE},
  67. {"createdb", CREATEDB},
  68. {"createuser", CREATEUSER},
  69. {"cross", CROSS},
  70. {"current_date", CURRENT_DATE},
  71. {"current_time", CURRENT_TIME},
  72. {"current_timestamp", CURRENT_TIMESTAMP},
  73. {"current_user", CURRENT_USER},
  74. {"cursor", CURSOR},
  75. {"cycle", CYCLE},
  76. {"database", DATABASE},
  77. {"day", DAY_P},
  78. {"decimal", DECIMAL},
  79. {"declare", DECLARE},
  80. {"default", DEFAULT},
  81. {"delete", DELETE},
  82. {"delimiters", DELIMITERS},
  83. {"desc", DESC},
  84. {"distinct", DISTINCT},
  85. {"do", DO},
  86. {"double", DOUBLE},
  87. {"drop", DROP},
  88. {"each", EACH},
  89. {"else", ELSE},
  90. {"encoding", ENCODING},
  91. {"end", END_TRANS},
  92. /***S*I***/
  93. {"except", EXCEPT},
  94. {"execute", EXECUTE},
  95. {"exists", EXISTS},
  96. {"explain", EXPLAIN},
  97. {"extend", EXTEND},
  98. {"extract", EXTRACT},
  99. {"false", FALSE_P},
  100. {"fetch", FETCH},
  101. {"float", FLOAT},
  102. {"for", FOR},
  103. {"foreign", FOREIGN},
  104. {"forward", FORWARD},
  105. {"from", FROM},
  106. {"full", FULL},
  107. {"function", FUNCTION},
  108. {"grant", GRANT},
  109. {"group", GROUP},
  110. {"handler", HANDLER},
  111. {"having", HAVING},
  112. {"hour", HOUR_P},
  113. {"in", IN},
  114. {"increment", INCREMENT},
  115. {"index", INDEX},
  116. {"inherits", INHERITS},
  117. {"inner", INNER_P},
  118. {"insensitive", INSENSITIVE},
  119. {"insert", INSERT},
  120. {"instead", INSTEAD},
  121. /***S*I***/
  122. {"intersect", INTERSECT},
  123. {"interval", INTERVAL},
  124. {"into", INTO},
  125. {"is", IS},
  126. {"isnull", ISNULL},
  127. {"isolation", ISOLATION},
  128. {"join", JOIN},
  129. {"key", KEY},
  130. {"lancompiler", LANCOMPILER},
  131. {"language", LANGUAGE},
  132. {"leading", LEADING},
  133. {"left", LEFT},
  134. {"level", LEVEL},
  135. {"like", LIKE},
  136. {"limit", LIMIT},
  137. {"listen", LISTEN},
  138. {"load", LOAD},
  139. {"local", LOCAL},
  140. {"location", LOCATION},
  141. {"lock", LOCK_P},
  142. {"match", MATCH},
  143. {"maxvalue", MAXVALUE},
  144. {"minute", MINUTE_P},
  145. {"minvalue", MINVALUE},
  146. {"month", MONTH_P},
  147. {"move", MOVE},
  148. {"names", NAMES},
  149. {"national", NATIONAL},
  150. {"natural", NATURAL},
  151. {"nchar", NCHAR},
  152. {"new", NEW},
  153. {"next", NEXT},
  154. {"no", NO},
  155. {"nocreatedb", NOCREATEDB},
  156. {"nocreateuser", NOCREATEUSER},
  157. {"none", NONE},
  158. {"not", NOT},
  159. {"nothing", NOTHING},
  160. {"notify", NOTIFY},
  161. {"notnull", NOTNULL},
  162. {"null", NULL_P},
  163. {"nullif", NULLIF},
  164. {"numeric", NUMERIC},
  165. {"of", OF},
  166. {"offset", OFFSET},
  167. {"oids", OIDS},
  168. {"old", CURRENT},
  169. {"on", ON},
  170. {"only", ONLY},
  171. {"operator", OPERATOR},
  172. {"option", OPTION},
  173. {"or", OR},
  174. {"order", ORDER},
  175. {"outer", OUTER_P},
  176. {"partial", PARTIAL},
  177. {"password", PASSWORD},
  178. {"position", POSITION},
  179. {"precision", PRECISION},
  180. {"primary", PRIMARY},
  181. {"prior", PRIOR},
  182. {"privileges", PRIVILEGES},
  183. {"procedural", PROCEDURAL},
  184. {"procedure", PROCEDURE},
  185. {"public", PUBLIC},
  186. {"read", READ},
  187. {"references", REFERENCES},
  188. {"relative", RELATIVE},
  189. {"rename", RENAME},
  190. {"reset", RESET},
  191. {"returns", RETURNS},
  192. {"revoke", REVOKE},
  193. {"right", RIGHT},
  194. {"rollback", ROLLBACK},
  195. {"row", ROW},
  196. {"rule", RULE},
  197. {"scroll", SCROLL},
  198. {"second", SECOND_P},
  199. {"select", SELECT},
  200. {"sequence", SEQUENCE},
  201. {"serial", SERIAL},
  202. {"set", SET},
  203. {"setof", SETOF},
  204. {"show", SHOW},
  205. {"start", START},
  206. {"statement", STATEMENT},
  207. {"stdin", STDIN},
  208. {"stdout", STDOUT},
  209. {"substring", SUBSTRING},
  210. {"table", TABLE},
  211. {"temp", TEMP},
  212. {"temporary", TEMPORARY},
  213. {"then", THEN},
  214. {"time", TIME},
  215. {"timestamp", TIMESTAMP},
  216. {"timezone_hour", TIMEZONE_HOUR},
  217. {"timezone_minute", TIMEZONE_MINUTE},
  218. {"to", TO},
  219. {"trailing", TRAILING},
  220. {"transaction", TRANSACTION},
  221. {"trigger", TRIGGER},
  222. {"trim", TRIM},
  223. {"true", TRUE_P},
  224. {"trusted", TRUSTED},
  225. {"type", TYPE_P},
  226. {"union", UNION},
  227. {"unique", UNIQUE},
  228. {"unlisten", UNLISTEN},
  229. {"until", UNTIL},
  230. {"update", UPDATE},
  231. {"user", USER},
  232. {"using", USING},
  233. {"vacuum", VACUUM},
  234. {"valid", VALID},
  235. {"values", VALUES},
  236. {"varchar", VARCHAR},
  237. {"varying", VARYING},
  238. {"verbose", VERBOSE},
  239. {"version", VERSION},
  240. {"view", VIEW},
  241. {"when", WHEN},
  242. {"where", WHERE},
  243. {"with", WITH},
  244. {"work", WORK},
  245. {"year", YEAR_P},
  246. {"zone", ZONE},
  247. };
  248. ScanKeyword *
  249. ScanKeywordLookup(char *text)
  250. {
  251. ScanKeyword *low = &ScanKeywords[0];
  252. ScanKeyword *high = endof(ScanKeywords) - 1;
  253. ScanKeyword *middle;
  254. int difference;
  255. while (low <= high)
  256. {
  257. middle = low + (high - low) / 2;
  258. difference = strcmp(middle->name, text);
  259. if (difference == 0)
  260. return middle;
  261. else if (difference < 0)
  262. low = middle + 1;
  263. else
  264. high = middle - 1;
  265. }
  266. return NULL;
  267. }