PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/SharedLibs/Sources/managedesent-61618/Pixie/SqlParser.cs

http://github.com/ravendb/ravendb
C# | 354 lines | 324 code | 19 blank | 11 comment | 10 complexity | bdabe62690d4a8bb9cd6cc077b6e9720 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause
  1. // This code was generated by the Gardens Point Parser Generator
  2. // Copyright (c) Wayne Kelly, QUT 2005-2008
  3. // (see accompanying GPPGcopyright.rtf)
  4. // GPPG version 1.3.1.136 (2008-11-11)
  5. // Machine: TITAN
  6. // DateTime: 1/25/2009 9:29:05 PM
  7. // UserName: Laurion
  8. // Input file <SqlParser.y>
  9. // options: no-lines gplex
  10. using System.Collections.Generic;
  11. using gppg;
  12. namespace Microsoft.Isam.Esent.Sql.Parsing
  13. {
  14. internal enum Tokens {error=48,
  15. EOF=49,NAME=50,STRING=51,INTEGER=52,REAL_NUMBER=53,OR=54,
  16. AND=55,NOT=56,COMPARISON=57,UMINUS=58,ATTACH=59,CREATE=60,
  17. DATABASE=61,DETACH=62,INDEX=63,TABLE=64,BEGIN=65,COMMIT=66,
  18. END=67,TRANSACTION=68,ROLLBACK=69,TO=70,SAVEPOINT=71,RELEASE=72,
  19. BOOL=73,BYTE=74,SHORT=75,INT=76,LONG=77,TEXT=78,
  20. BINARY=79,DATETIME=80,GUID=81,INSERT=82,INTO=83,VALUES=84};
  21. internal partial struct ValueType
  22. {
  23. internal string name;
  24. internal string stringValue;
  25. internal long intValue;
  26. internal double realValue;
  27. internal object value;
  28. internal ColumnType coltyp;
  29. internal ColumnDefinition columndef;
  30. internal List<ColumnDefinition> columndefs;
  31. internal List<string> columnNames;
  32. internal List<object> columnValues;
  33. }
  34. // Abstract base class for GPLEX scanners
  35. internal abstract class ScanBase : IScanner<ValueType,LexLocation> {
  36. private LexLocation __yylloc = new LexLocation();
  37. public override LexLocation yylloc { get { return __yylloc; } set { __yylloc = value; } }
  38. protected virtual bool yywrap() { return true; }
  39. }
  40. internal partial class Parser: ShiftReduceParser<ValueType, LexLocation>
  41. {
  42. private Dictionary<int, string> aliasses = null;
  43. protected override void Initialize()
  44. {
  45. this.errToken = (int)Tokens.error;
  46. this.eofToken = (int)Tokens.EOF;
  47. states=new State[83];
  48. AddState(0,new State(new int[]{60,4,59,30,62,34,65,38,66,42,67,44,69,47,71,55,72,58,82,62,49,82},new int[]{-1,1,-3,3,-4,29,-5,33,-6,36,-7,37,-8,41,-9,46,-10,54,-11,57,-12,61,-13,81}));
  49. AddState(1,new State(new int[]{49,2}));
  50. AddState(2,new State(-1));
  51. AddState(3,new State(-2));
  52. AddState(4,new State(new int[]{61,5,64,8}));
  53. AddState(5,new State(new int[]{51,7},new int[]{-14,6}));
  54. AddState(6,new State(-14));
  55. AddState(7,new State(-51));
  56. AddState(8,new State(new int[]{50,28},new int[]{-15,9}));
  57. AddState(9,new State(new int[]{40,10}));
  58. AddState(10,new State(new int[]{50,26},new int[]{-16,11,-17,27,-18,15}));
  59. AddState(11,new State(new int[]{41,12,44,13}));
  60. AddState(12,new State(-17));
  61. AddState(13,new State(new int[]{50,26},new int[]{-17,14,-18,15}));
  62. AddState(14,new State(-19));
  63. AddState(15,new State(new int[]{73,17,74,18,75,19,76,20,77,21,78,22,79,23,80,24,81,25},new int[]{-19,16}));
  64. AddState(16,new State(-20));
  65. AddState(17,new State(-21));
  66. AddState(18,new State(-22));
  67. AddState(19,new State(-23));
  68. AddState(20,new State(-24));
  69. AddState(21,new State(-25));
  70. AddState(22,new State(-26));
  71. AddState(23,new State(-27));
  72. AddState(24,new State(-28));
  73. AddState(25,new State(-29));
  74. AddState(26,new State(-50));
  75. AddState(27,new State(-18));
  76. AddState(28,new State(-49));
  77. AddState(29,new State(-3));
  78. AddState(30,new State(new int[]{61,31}));
  79. AddState(31,new State(new int[]{51,7},new int[]{-14,32}));
  80. AddState(32,new State(-15));
  81. AddState(33,new State(-4));
  82. AddState(34,new State(new int[]{61,35}));
  83. AddState(35,new State(-16));
  84. AddState(36,new State(-5));
  85. AddState(37,new State(-6));
  86. AddState(38,new State(new int[]{68,40,49,-31},new int[]{-20,39}));
  87. AddState(39,new State(-30));
  88. AddState(40,new State(-32));
  89. AddState(41,new State(-7));
  90. AddState(42,new State(new int[]{68,40,49,-31},new int[]{-20,43}));
  91. AddState(43,new State(-33));
  92. AddState(44,new State(new int[]{68,40,49,-31},new int[]{-20,45}));
  93. AddState(45,new State(-34));
  94. AddState(46,new State(-8));
  95. AddState(47,new State(new int[]{68,40,70,-31,49,-31},new int[]{-20,48}));
  96. AddState(48,new State(new int[]{70,49,49,-35}));
  97. AddState(49,new State(new int[]{71,53,50,-37},new int[]{-21,50}));
  98. AddState(50,new State(new int[]{50,52},new int[]{-22,51}));
  99. AddState(51,new State(-36));
  100. AddState(52,new State(-52));
  101. AddState(53,new State(-38));
  102. AddState(54,new State(-9));
  103. AddState(55,new State(new int[]{50,52},new int[]{-22,56}));
  104. AddState(56,new State(-39));
  105. AddState(57,new State(-10));
  106. AddState(58,new State(new int[]{71,53,50,-37},new int[]{-21,59}));
  107. AddState(59,new State(new int[]{50,52},new int[]{-22,60}));
  108. AddState(60,new State(-40));
  109. AddState(61,new State(-11));
  110. AddState(62,new State(new int[]{83,63}));
  111. AddState(63,new State(new int[]{50,28},new int[]{-15,64}));
  112. AddState(64,new State(new int[]{40,65}));
  113. AddState(65,new State(new int[]{50,26},new int[]{-23,66,-18,80}));
  114. AddState(66,new State(new int[]{41,67,44,78}));
  115. AddState(67,new State(new int[]{84,68}));
  116. AddState(68,new State(new int[]{40,69}));
  117. AddState(69,new State(new int[]{51,74,52,75,53,76},new int[]{-24,70,-25,77}));
  118. AddState(70,new State(new int[]{41,71,44,72}));
  119. AddState(71,new State(-41));
  120. AddState(72,new State(new int[]{51,74,52,75,53,76},new int[]{-25,73}));
  121. AddState(73,new State(-45));
  122. AddState(74,new State(-46));
  123. AddState(75,new State(-47));
  124. AddState(76,new State(-48));
  125. AddState(77,new State(-44));
  126. AddState(78,new State(new int[]{50,26},new int[]{-18,79}));
  127. AddState(79,new State(-43));
  128. AddState(80,new State(-42));
  129. AddState(81,new State(-12));
  130. AddState(82,new State(-13));
  131. rules=new Rule[53];
  132. rules[1]=new Rule(-2, new int[]{-1,49});
  133. rules[2]=new Rule(-1, new int[]{-3});
  134. rules[3]=new Rule(-1, new int[]{-4});
  135. rules[4]=new Rule(-1, new int[]{-5});
  136. rules[5]=new Rule(-1, new int[]{-6});
  137. rules[6]=new Rule(-1, new int[]{-7});
  138. rules[7]=new Rule(-1, new int[]{-8});
  139. rules[8]=new Rule(-1, new int[]{-9});
  140. rules[9]=new Rule(-1, new int[]{-10});
  141. rules[10]=new Rule(-1, new int[]{-11});
  142. rules[11]=new Rule(-1, new int[]{-12});
  143. rules[12]=new Rule(-1, new int[]{-13});
  144. rules[13]=new Rule(-13, new int[]{49});
  145. rules[14]=new Rule(-3, new int[]{60,61,-14});
  146. rules[15]=new Rule(-4, new int[]{59,61,-14});
  147. rules[16]=new Rule(-5, new int[]{62,61});
  148. rules[17]=new Rule(-6, new int[]{60,64,-15,40,-16,41});
  149. rules[18]=new Rule(-16, new int[]{-17});
  150. rules[19]=new Rule(-16, new int[]{-16,44,-17});
  151. rules[20]=new Rule(-17, new int[]{-18,-19});
  152. rules[21]=new Rule(-19, new int[]{73});
  153. rules[22]=new Rule(-19, new int[]{74});
  154. rules[23]=new Rule(-19, new int[]{75});
  155. rules[24]=new Rule(-19, new int[]{76});
  156. rules[25]=new Rule(-19, new int[]{77});
  157. rules[26]=new Rule(-19, new int[]{78});
  158. rules[27]=new Rule(-19, new int[]{79});
  159. rules[28]=new Rule(-19, new int[]{80});
  160. rules[29]=new Rule(-19, new int[]{81});
  161. rules[30]=new Rule(-7, new int[]{65,-20});
  162. rules[31]=new Rule(-20, new int[]{});
  163. rules[32]=new Rule(-20, new int[]{68});
  164. rules[33]=new Rule(-8, new int[]{66,-20});
  165. rules[34]=new Rule(-8, new int[]{67,-20});
  166. rules[35]=new Rule(-9, new int[]{69,-20});
  167. rules[36]=new Rule(-9, new int[]{69,-20,70,-21,-22});
  168. rules[37]=new Rule(-21, new int[]{});
  169. rules[38]=new Rule(-21, new int[]{71});
  170. rules[39]=new Rule(-10, new int[]{71,-22});
  171. rules[40]=new Rule(-11, new int[]{72,-21,-22});
  172. rules[41]=new Rule(-12, new int[]{82,83,-15,40,-23,41,84,40,-24,41});
  173. rules[42]=new Rule(-23, new int[]{-18});
  174. rules[43]=new Rule(-23, new int[]{-23,44,-18});
  175. rules[44]=new Rule(-24, new int[]{-25});
  176. rules[45]=new Rule(-24, new int[]{-24,44,-25});
  177. rules[46]=new Rule(-25, new int[]{51});
  178. rules[47]=new Rule(-25, new int[]{52});
  179. rules[48]=new Rule(-25, new int[]{53});
  180. rules[49]=new Rule(-15, new int[]{50});
  181. rules[50]=new Rule(-18, new int[]{50});
  182. rules[51]=new Rule(-14, new int[]{51});
  183. rules[52]=new Rule(-22, new int[]{50});
  184. nonTerminals = new string[] {"", "sql", "$accept", "createdb", "attachdb",
  185. "detachdb", "createtable", "begin_trx", "commit_trx", "rollback_trx", "create_savepoint",
  186. "release_savepoint", "insert", "blank", "database", "table", "columncreate_list",
  187. "columncreate", "column", "data_type", "opt_transaction", "opt_savepoint",
  188. "savepoint", "columnname_list", "value_list", "value", };
  189. }
  190. protected override void DoAction(int action)
  191. {
  192. switch (action)
  193. {
  194. case 14: // createdb -> CREATE, DATABASE, database
  195. { this.SqlImplementation.CreateDatabase(value_stack.array[value_stack.top-1].stringValue); }
  196. break;
  197. case 15: // attachdb -> ATTACH, DATABASE, database
  198. { this.SqlImplementation.AttachDatabase(value_stack.array[value_stack.top-1].stringValue); }
  199. break;
  200. case 16: // detachdb -> DETACH, DATABASE
  201. { this.SqlImplementation.DetachDatabase(); }
  202. break;
  203. case 17: // createtable -> CREATE, TABLE, table, '(', columncreate_list, ')'
  204. { this.SqlImplementation.CreateTable(value_stack.array[value_stack.top-4].name, value_stack.array[value_stack.top-2].columndefs); }
  205. break;
  206. case 18: // columncreate_list -> columncreate
  207. {
  208. yyval.columndefs = new List<ColumnDefinition>();
  209. yyval.columndefs.Add(value_stack.array[value_stack.top-1].columndef);
  210. }
  211. break;
  212. case 19: // columncreate_list -> columncreate_list, ',', columncreate
  213. {
  214. yyval.columndefs = new List<ColumnDefinition>();
  215. yyval.columndefs.AddRange(value_stack.array[value_stack.top-3].columndefs);
  216. yyval.columndefs.Add(value_stack.array[value_stack.top-1].columndef);
  217. }
  218. break;
  219. case 20: // columncreate -> column, data_type
  220. {
  221. yyval.columndef = new ColumnDefinition(value_stack.array[value_stack.top-2].name, value_stack.array[value_stack.top-1].coltyp);
  222. }
  223. break;
  224. case 21: // data_type -> BOOL
  225. { yyval.coltyp = ColumnType.Bool; }
  226. break;
  227. case 22: // data_type -> BYTE
  228. { yyval.coltyp = ColumnType.Byte; }
  229. break;
  230. case 23: // data_type -> SHORT
  231. { yyval.coltyp = ColumnType.Int16; }
  232. break;
  233. case 24: // data_type -> INT
  234. { yyval.coltyp = ColumnType.Int32; }
  235. break;
  236. case 25: // data_type -> LONG
  237. { yyval.coltyp = ColumnType.Int64; }
  238. break;
  239. case 26: // data_type -> TEXT
  240. { yyval.coltyp = ColumnType.Text; }
  241. break;
  242. case 27: // data_type -> BINARY
  243. { yyval.coltyp = ColumnType.Binary; }
  244. break;
  245. case 28: // data_type -> DATETIME
  246. { yyval.coltyp = ColumnType.DateTime; }
  247. break;
  248. case 29: // data_type -> GUID
  249. { yyval.coltyp = ColumnType.Guid; }
  250. break;
  251. case 30: // begin_trx -> BEGIN, opt_transaction
  252. { this.SqlImplementation.BeginTransaction(); }
  253. break;
  254. case 33: // commit_trx -> COMMIT, opt_transaction
  255. { this.SqlImplementation.CommitTransaction(); }
  256. break;
  257. case 34: // commit_trx -> END, opt_transaction
  258. { this.SqlImplementation.CommitTransaction(); }
  259. break;
  260. case 35: // rollback_trx -> ROLLBACK, opt_transaction
  261. { this.SqlImplementation.RollbackTransaction(); }
  262. break;
  263. case 36: // rollback_trx -> ROLLBACK, opt_transaction, TO, opt_savepoint, savepoint
  264. { this.SqlImplementation.RollbackToSavepoint(value_stack.array[value_stack.top-1].name); }
  265. break;
  266. case 39: // create_savepoint -> SAVEPOINT, savepoint
  267. { this.SqlImplementation.CreateSavepoint(value_stack.array[value_stack.top-1].name); }
  268. break;
  269. case 40: // release_savepoint -> RELEASE, opt_savepoint, savepoint
  270. { this.SqlImplementation.CommitSavepoint(value_stack.array[value_stack.top-1].name); }
  271. break;
  272. case 41: // insert -> INSERT, INTO, table, '(', columnname_list, ')', VALUES, '(',
  273. // value_list, ')'
  274. {
  275. string tablename = value_stack.array[value_stack.top-8].name;
  276. string[] columnNames = value_stack.array[value_stack.top-6].columnNames.ToArray();
  277. object[] columnValues = value_stack.array[value_stack.top-2].columnValues.ToArray();
  278. if (columnNames.Length != columnValues.Length)
  279. {
  280. throw new EsentSqlParseException("Different number of column names and column values");
  281. }
  282. KeyValuePair<string, object>[] dataToSet = new KeyValuePair<string, object>[columnNames.Length];
  283. for (int i = 0; i < columnNames.Length; ++i)
  284. {
  285. dataToSet[i] = new KeyValuePair<string, object>( columnNames[i], columnValues[i] );
  286. }
  287. this.SqlImplementation.InsertRecord(tablename, dataToSet);
  288. }
  289. break;
  290. case 42: // columnname_list -> column
  291. {
  292. yyval.columnNames = new List<string>();
  293. yyval.columnNames.Add(value_stack.array[value_stack.top-1].name);
  294. }
  295. break;
  296. case 43: // columnname_list -> columnname_list, ',', column
  297. {
  298. yyval.columnNames = value_stack.array[value_stack.top-3].columnNames;
  299. yyval.columnNames.Add(value_stack.array[value_stack.top-1].name);
  300. }
  301. break;
  302. case 44: // value_list -> value
  303. {
  304. yyval.columnValues = new List<object>();
  305. yyval.columnValues.Add(value_stack.array[value_stack.top-1].value);
  306. }
  307. break;
  308. case 45: // value_list -> value_list, ',', value
  309. {
  310. yyval.columnValues = value_stack.array[value_stack.top-3].columnValues;
  311. yyval.columnValues.Add(value_stack.array[value_stack.top-1].value);
  312. }
  313. break;
  314. case 46: // value -> STRING
  315. { yyval.value = value_stack.array[value_stack.top-1].stringValue; }
  316. break;
  317. case 47: // value -> INTEGER
  318. { yyval.value = value_stack.array[value_stack.top-1].intValue; }
  319. break;
  320. case 48: // value -> REAL_NUMBER
  321. { yyval.value = value_stack.array[value_stack.top-1].realValue; }
  322. break;
  323. }
  324. }
  325. protected override string TerminalToString(int terminal)
  326. {
  327. if (aliasses != null && aliasses.ContainsKey(terminal))
  328. return aliasses[terminal];
  329. else if (((Tokens)terminal).ToString() != terminal.ToString())
  330. return ((Tokens)terminal).ToString();
  331. else
  332. return CharToString((char)terminal);
  333. }
  334. }
  335. }