Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

673 lines
20 KiB

  1. /* Skeleton output parser for bison,
  2. Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  14. /* As a special exception, when this file is copied by Bison into a
  15. Bison output file, you may use that output file without restriction.
  16. This special exception was added by the Free Software Foundation
  17. in version 1.24 of Bison. */
  18. #pragma hdrstop
  19. #include <malloc.h>
  20. /* This is the parser code that is written into each bison parser
  21. when the %semantic_parser declaration is not specified in the grammar.
  22. It was written by Richard Stallman by simplifying the hairy parser
  23. used when %semantic_parser is specified. */
  24. /* Note: there must be only one dollar sign in this file.
  25. It is replaced by the list of actions, each action
  26. as one case of the switch. */
  27. #ifdef YYDEBUG
  28. # ifndef YYDBFLG
  29. # define YYDBFLG (yydebug)
  30. # endif
  31. # define yyprintf if (YYDBFLG) YYPRINT
  32. #else
  33. # define yyprintf
  34. #endif
  35. #ifndef YYPRINT
  36. #ifdef UNICODE
  37. # define YYPRINT wprintf
  38. #else
  39. # define YYPRINT printf
  40. #endif
  41. #endif
  42. #ifndef YYERROR_VERBOSE
  43. #define YYERROR_VERBOSE 1
  44. #endif
  45. #define YYEMPTY -2
  46. #define YYEOF 0
  47. #define YYACCEPT return(ResultFromScode(S_OK))
  48. #define YYABORT(sc) {EmptyValueStack(); return(ResultFromScode(sc));}
  49. #define YYERROR goto yyerrlab1
  50. /* Like YYERROR except do call yyerror.
  51. This remains here temporarily to ease the
  52. transition to the new meaning of YYERROR, for GCC.
  53. Once GCC version 2 has supplanted version 1, this can go. */
  54. #define YYFAIL goto yyerrlab
  55. #define YYRECOVERING() (!!yyerrstatus)
  56. #define YYTERROR 1
  57. #define YYERRCODE 256
  58. /* YYINITDEPTH indicates the initial size of the parser's stacks */
  59. #ifndef YYINITDEPTH
  60. #define YYINITDEPTH 200
  61. #endif
  62. /* YYMAXDEPTH is the maximum size the stacks can grow to
  63. (effective only if the built-in stack extension method is used). */
  64. #if YYMAXDEPTH == 0
  65. #undef YYMAXDEPTH
  66. #endif
  67. #ifndef YYMAXDEPTH
  68. #define YYMAXDEPTH 10000
  69. #endif
  70. //turn off warning about 'this' in base member initialization
  71. #pragma warning (disable : 4355)
  72. YYPARSER::YYPARSER(
  73. CImpIParserSession* pParserSession,
  74. CImpIParserTreeProperties* pParserTreeProperties
  75. ) : m_yylex(this)
  76. #pragma warning (default : 4355)
  77. {
  78. //Allocate yys, yyv if necessary
  79. ResetParser();
  80. m_pIPSession = pParserSession;
  81. m_pIPTProperties = pParserTreeProperties;
  82. }
  83. YYPARSER::~YYPARSER()
  84. {
  85. //Deallocate yys, yyv if allocated
  86. }
  87. void YYPARSER::ResetParser()
  88. {
  89. yystate = 0;
  90. yyerrstatus = 0;
  91. yynerrs = 0;
  92. /* Initialize stack pointers.
  93. Waste one element of value and location stack
  94. so that they stay on the same level as the state stack.
  95. The wasted elements are never initialized. */
  96. yyssp = yyss-1;
  97. yyvsp = yyvs;
  98. YYAPI_TOKENNAME = YYEMPTY; // Cause a token to be read.
  99. }
  100. #pragma warning(disable:102)
  101. HRESULT YYPARSER::Parse(YYPARSEPROTO)
  102. {
  103. yychar1 = 0; /* lookahead token as an internal (translated) token number */
  104. yyss = yyssa; /* refer to the stacks thru separate pointers */
  105. yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
  106. yystacksize = YYINITDEPTH;
  107. #ifdef YYDEBUG
  108. if (yydebug)
  109. Trace(TEXT("Starting parse\n"));
  110. #endif
  111. yystate = 0;
  112. yyerrstatus = 0;
  113. yynerrs = 0;
  114. YYAPI_TOKENNAME = YYEMPTY; /* Cause a token to be read. */
  115. /* Initialize stack pointers.
  116. Waste one element of value and location stack
  117. so that they stay on the same level as the state stack.
  118. The wasted elements are never initialized. */
  119. yyssp = yyss-1;
  120. yyvsp = yyvs;
  121. // Push a new state, which is found in yystate .
  122. // In all cases, when you get here, the value and location stacks
  123. // have just been pushed. so pushing a state here evens the stacks.
  124. yynewstate:
  125. *++yyssp = yystate;
  126. if (yyssp >= yyss + yystacksize - 1)
  127. {
  128. // Give user a chance to reallocate the stack
  129. // Use copies of these so that the &'s don't force the real ones into memory. */
  130. YYSTYPE *yyvs1 = yyvs;
  131. short *yyss1 = yyss;
  132. // Get the current used size of the three stacks, in elements. */
  133. int size = (int)(yyssp - yyss + 1);
  134. #ifdef yyoverflow
  135. // Each stack pointer address is followed by the size of
  136. // the data in use in that stack, in bytes.
  137. yyoverflow("parser stack overflow",
  138. &yyss1, size * sizeof (*yyssp),
  139. &yyvs1, size * sizeof (*yyvsp),
  140. &yystacksize);
  141. yyss = yyss1; yyvs = yyvs1;
  142. #else // no yyoverflow
  143. // Extend the stack our own way.
  144. if (yystacksize >= YYMAXDEPTH)
  145. {
  146. m_pIPTProperties->SetErrorHResult(E_FAIL, MONSQL_PARSE_STACK_OVERFLOW);
  147. return ResultFromScode(E_FAIL);
  148. }
  149. yystacksize *= 2;
  150. if (yystacksize > YYMAXDEPTH)
  151. yystacksize = YYMAXDEPTH;
  152. yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  153. memcpy ((TCHAR *)yyss, (TCHAR *)yyss1, size * sizeof (*yyssp));
  154. yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  155. memcpy ((TCHAR *)yyvs, (TCHAR *)yyvs1, size * sizeof (*yyvsp));
  156. #endif /* no yyoverflow */
  157. yyssp = yyss + size - 1;
  158. yyvsp = yyvs + size - 1;
  159. #ifdef YYDEBUG
  160. if (yydebug)
  161. Trace(TEXT("Stack size increased to %d\n"), yystacksize);
  162. #endif
  163. if (yyssp >= yyss + yystacksize - 1)
  164. YYABORT(E_FAIL);
  165. }
  166. #ifdef YYDEBUG
  167. if (yydebug)
  168. Trace(TEXT("Entering state %d\n"), yystate);
  169. #endif
  170. goto yybackup;
  171. yybackup:
  172. // Do appropriate processing given the current state.
  173. // Read a lookahead token if we need one and don't already have one.
  174. // First try to decide what to do without reference to lookahead token.
  175. yyn = yypact[yystate];
  176. if (yyn == YYFLAG)
  177. goto yydefault;
  178. // Not known => get a lookahead token if don't already have one.
  179. // YYAPI_TOKENNAME is either YYEMPTY or YYEOF or a valid token in external form.
  180. if (YYAPI_TOKENNAME == YYEMPTY)
  181. {
  182. #ifdef YYDEBUG
  183. if (yydebug)
  184. Trace(TEXT("Reading a token\n"));
  185. #endif
  186. YYAPI_VALUENAME = NULL;
  187. try
  188. {
  189. YYAPI_TOKENNAME = YYLEX(&YYAPI_VALUENAME);
  190. }
  191. catch (HRESULT hr)
  192. {
  193. switch(hr)
  194. {
  195. case E_OUTOFMEMORY:
  196. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_OUT_OF_MEMORY);
  197. YYABORT(E_OUTOFMEMORY);
  198. default:
  199. YYABORT(E_FAIL);
  200. }
  201. }
  202. }
  203. // Convert token to internal form (in yychar1) for indexing tables with
  204. if (YYAPI_TOKENNAME <= 0) /* This means end of input. */
  205. {
  206. yychar1 = 0;
  207. YYAPI_TOKENNAME = YYEOF; /* Don't call YYLEX any more */
  208. #ifdef YYDEBUG
  209. if (yydebug)
  210. Trace(TEXT("Now at end of input: state %2d\n"), yystate);
  211. #endif
  212. }
  213. else
  214. {
  215. yychar1 = YYTRANSLATE(YYAPI_TOKENNAME);
  216. #ifdef YYDEBUG
  217. if (yydebug)
  218. Trace(TEXT("Next token is %s (%d)\n"), yytname[yychar1], YYAPI_TOKENNAME);
  219. #endif
  220. }
  221. yyn += yychar1;
  222. if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  223. goto yydefault;
  224. yyn = yytable[yyn];
  225. // yyn is what to do for this token type in this state.
  226. // Negative => reduce, -yyn is rule number.
  227. // Positive => shift, yyn is new state.
  228. // New state is final state => don't bother to shift,
  229. // just return success.
  230. // 0, or most negative number => error. */
  231. if (yyn < 0)
  232. {
  233. if (yyn == YYFLAG)
  234. goto yyerrlab;
  235. yyn = -yyn;
  236. goto yyreduce;
  237. }
  238. else if (yyn == 0)
  239. goto yyerrlab;
  240. if (yyn == YYFINAL)
  241. YYACCEPT;
  242. // Shift the lookahead token.
  243. #ifdef YYDEBUG
  244. if (yydebug)
  245. Trace(TEXT("Shifting token %s (%d), "), yytname[yychar1], YYAPI_TOKENNAME);
  246. #endif
  247. // Discard the token being shifted unless it is eof.
  248. if (YYAPI_TOKENNAME != YYEOF)
  249. YYAPI_TOKENNAME = YYEMPTY;
  250. *++yyvsp = yylval;
  251. yylval = NULL;
  252. // count tokens shifted since error; after three, turn off error status.
  253. if (yyerrstatus)
  254. yyerrstatus--;
  255. yystate = (short)yyn;
  256. goto yynewstate;
  257. // Do the default action for the current state.
  258. yydefault:
  259. yyn = yydefact[yystate];
  260. if (yyn == 0)
  261. goto yyerrlab;
  262. // Do a reduction. yyn is the number of a rule to reduce with.
  263. yyreduce:
  264. yylen = yyr2[yyn];
  265. if (yylen > 0)
  266. yyval = yyvsp[1-yylen]; // implement default value of the action
  267. #ifdef YYDEBUG
  268. if (yydebug)
  269. {
  270. int i;
  271. Trace(TEXT("Reducing via rule %d (line %d), "), yyn, yyrline[yyn]);
  272. // Print the symbols being reduced, and their result.
  273. for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  274. Trace(TEXT("%s "), yytname[yyrhs[i]]);
  275. Trace(TEXT(" -> %s\n"), yytname[yyr1[yyn]]);
  276. }
  277. #endif
  278. $ /* the action file gets copied in in place of this dollarsign */
  279. #line 498 "bison.simple"
  280. yyvsp -= yylen;
  281. yyssp -= yylen;
  282. #ifdef YYDEBUG
  283. if (yydebug)
  284. {
  285. short *ssp1 = yyss - 1;
  286. Trace(TEXT("state stack now"));
  287. while (ssp1 != yyssp)
  288. Trace(TEXT(" %d"), *++ssp1);
  289. Trace(TEXT("\n"), *++ssp1);
  290. }
  291. #endif
  292. *++yyvsp = yyval;
  293. // Now "shift" the result of the reduction.
  294. // Determine what state that goes to,
  295. // based on the state we popped back to
  296. // and the rule number reduced by.
  297. yyn = yyr1[yyn];
  298. yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  299. if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  300. yystate = yytable[yystate];
  301. else
  302. yystate = yydefgoto[yyn - YYNTBASE];
  303. goto yynewstate;
  304. yyerrlab: // here on detecting error
  305. if (yylval)
  306. {
  307. DeleteDBQT(yylval);
  308. yylval = NULL;
  309. }
  310. if (!yyerrstatus) // If not already recovering from an error, report this error.
  311. {
  312. ++yynerrs;
  313. #ifdef YYERROR_VERBOSE
  314. yyn = yypact[yystate];
  315. if ( yyn > YYFLAG && yyn < YYLAST )
  316. {
  317. int size = 0;
  318. int x, count;
  319. count = 0;
  320. // Start X at -yyn if nec to avoid negative indexes in yycheck.
  321. for ( x = (yyn < 0 ? -yyn : 0);
  322. x < (sizeof(yytname) / sizeof(TCHAR *)) && ( (x + yyn) < sizeof(yycheck) / sizeof(short));
  323. x++ )
  324. {
  325. if ( yycheck[x + yyn] == x )
  326. {
  327. size += (wcslen(yytname[x]) + 3) * sizeof(TCHAR);
  328. count++;
  329. }
  330. }
  331. XPtrST<WCHAR> xMsg( new WCHAR[size] );
  332. wcscpy(xMsg.GetPointer(), L"");
  333. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  334. if ( wcslen((YY_CHAR*)m_yylex.YYText()) )
  335. m_pIPTProperties->SetErrorToken( (YY_CHAR*)m_yylex.YYText() );
  336. else
  337. m_pIPTProperties->SetErrorToken(L"<end of input>");
  338. if (count < 10)
  339. {
  340. count = 0;
  341. for ( x = (yyn < 0 ? -yyn : 0);
  342. x < (sizeof(yytname) / sizeof(TCHAR *)) && ( (x + yyn) < sizeof(yycheck) / sizeof(short));
  343. x++ )
  344. {
  345. if (yycheck[x + yyn] == x)
  346. {
  347. if (count > 0)
  348. wcscat( xMsg.GetPointer(), L", " );
  349. wcscat(xMsg.GetPointer(), yytname[x]);
  350. count++;
  351. }
  352. }
  353. m_pIPTProperties->SetErrorToken( xMsg.GetPointer() );
  354. }
  355. xMsg.Free();
  356. }
  357. else
  358. #endif /* YYERROR_VERBOSE */
  359. m_pIPTProperties->SetErrorHResult(DB_E_ERRORSINCOMMAND, MONSQL_PARSE_ERROR);
  360. }
  361. goto yyerrlab1;
  362. yyerrlab1: // here on error raised explicitly by an action
  363. if (yyerrstatus == 3)
  364. { // if just tried and failed to reuse lookahead token after an error, discard it.
  365. // return failure if at end of input
  366. if (YYAPI_TOKENNAME == YYEOF)
  367. YYABORT(DB_E_ERRORSINCOMMAND);
  368. #ifdef YYDEBUG
  369. if (yydebug)
  370. Trace(TEXT("Discarding token %s (%d).\n"), yytname[yychar1], YYAPI_TOKENNAME);
  371. #endif
  372. YYAPI_TOKENNAME = YYEMPTY;
  373. }
  374. // Else will try to reuse lookahead token after shifting the error token.
  375. yyerrstatus = 3; // Each real token shifted decrements this
  376. goto yyerrhandle;
  377. yyerrdefault: // current state does not do anything special for the error token.
  378. yyerrpop: // pop the current state because it cannot handle the error token
  379. if (yyssp == yyss)
  380. YYABORT(E_FAIL);
  381. if (NULL != *yyvsp)
  382. {
  383. DeleteDBQT(*yyvsp);
  384. }
  385. yyvsp--;
  386. yystate = *--yyssp;
  387. #ifdef YYDEBUG
  388. if (yydebug)
  389. {
  390. short *ssp1 = yyss - 1;
  391. Trace(TEXT("Error: state stack now"));
  392. while (ssp1 != yyssp)
  393. Trace(TEXT(" %d"), *++ssp1);
  394. Trace(TEXT("\n"));
  395. }
  396. #endif
  397. yyerrhandle:
  398. yyn = yypact[yystate];
  399. if (yyn == YYFLAG)
  400. goto yyerrdefault;
  401. yyn += YYTERROR;
  402. if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  403. goto yyerrdefault;
  404. yyn = yytable[yyn];
  405. if (yyn < 0)
  406. {
  407. if (yyn == YYFLAG)
  408. goto yyerrpop;
  409. yyn = -yyn;
  410. goto yyreduce;
  411. }
  412. else if (yyn == 0)
  413. goto yyerrpop;
  414. if (yyn == YYFINAL)
  415. YYACCEPT;
  416. #ifdef YYDEBUG
  417. if (yydebug)
  418. Trace(TEXT("Shifting error token, "));
  419. #endif
  420. *++yyvsp = yylval;
  421. yystate = (short)yyn;
  422. goto yynewstate;
  423. }
  424. #pragma warning(default:102)
  425. #ifdef YYDUMP
  426. void YYPARSER::DumpYYS()
  427. {
  428. short stackindex;
  429. yyprintf(TEXT("short yys[%d] {\n"), YYMAXDEPTH);
  430. for (stackindex = 0; stackindex < YYMAXDEPTH; stackindex++)
  431. {
  432. if (stackindex)
  433. yyprintf(TEXT(", %s"), stackindex % 10 ? TEXT("\0") : TEXT("\n"));
  434. yyprintf(TEXT("%6d"), yys[stackindex]);
  435. }
  436. yyprintf(TEXT("\n};\n"));
  437. }
  438. void YYPARSER::DumpYYV()
  439. {
  440. short valindex;
  441. yyprintf(TEXT("YYSTYPE yyv[%d] {\n"), YYMAXDEPTH);
  442. for (valindex = 0; valindex < YYMAXDEPTH; valindex++)
  443. {
  444. if (valindex)
  445. yyprintf(TEXT(", %s"), valindex % 5 ? TEXT("\0") : TEXT("\n"));
  446. yyprintf(TEXT("%#*x"), 3+sizeof(YYSTYPE), yyv[valindex]);
  447. }
  448. yyprintf(TEXT("\n};\n"));
  449. }
  450. #endif
  451. int YYPARSER::NoOfErrors()
  452. {
  453. return yynerrs;
  454. }
  455. int YYPARSER::ErrRecoveryState()
  456. {
  457. return yyerrflag;
  458. }
  459. void YYPARSER::ClearErrRecoveryState()
  460. {
  461. yyerrflag = 0;
  462. }
  463. YYAPI_TOKENTYPE YYPARSER::GetCurrentToken()
  464. {
  465. return YYAPI_TOKENNAME;
  466. }
  467. void YYPARSER::SetCurrentToken(YYAPI_TOKENTYPE newToken)
  468. {
  469. YYAPI_TOKENNAME = newToken;
  470. }
  471. void YYPARSER::Trace(TCHAR *message)
  472. {
  473. #ifdef YYDEBUG
  474. yyprintf(message);
  475. #endif
  476. }
  477. void YYPARSER::Trace(TCHAR *message, const TCHAR *tokname, short state /*= 0*/)
  478. {
  479. #ifdef YYDEBUG
  480. yyprintf(message, tokname, state);
  481. #endif
  482. }
  483. void YYPARSER::Trace(TCHAR *message, int state, short tostate /*= 0*/, short token /*= 0*/)
  484. {
  485. #ifdef YYDEBUG
  486. yyprintf(message, state, tostate, token);
  487. #endif
  488. }
  489. void YYPARSER::yySetBuffer(short iBuffer, YY_CHAR *szValue)
  490. {
  491. if (iBuffer >= 0 && iBuffer < maxYYBuffer)
  492. rgpszYYBuffer[iBuffer] = szValue;
  493. }
  494. YY_CHAR *YYPARSER::yyGetBuffer(short iBuffer)
  495. {
  496. if (iBuffer >= 0 && iBuffer < maxYYBuffer)
  497. return rgpszYYBuffer[iBuffer];
  498. else
  499. return (YY_CHAR *)NULL;
  500. }
  501. void YYPARSER::yyprimebuffer(YY_CHAR *pszBuffer)
  502. {
  503. m_yylex.yyprimebuffer(pszBuffer);
  504. }
  505. void YYPARSER::yyprimelexer(int eToken)
  506. {
  507. m_yylex.yyprimelexer(eToken);
  508. }
  509. void YYPARSER::EmptyValueStack()
  510. {
  511. if ((*yyvsp != yylval) && (NULL != yylval))
  512. DeleteDBQT(yylval);
  513. while (yyvsp != yyvsa)
  514. {
  515. if (NULL != *yyvsp)
  516. DeleteDBQT(*yyvsp);
  517. yyvsp--;
  518. }
  519. //@TODO RE-ACTIVATE
  520. // note: This was only done to empty any scope arrays
  521. // m_pIPSession->SetScopeProperties(m_pICommand);
  522. if (m_pIPTProperties->GetContainsColumn())
  523. DeleteDBQT(m_pIPTProperties->GetContainsColumn());
  524. m_pIPTProperties->SetContainsColumn(NULL);
  525. }