예제 #1
0
/*
** Perform a shift action.
*/
static void yy_shift(
  yyParser *yypParser,          /* The parser to be shifted */
  int yyNewState,               /* The new state to shift in */
  int yyMajor,                  /* The major token to shift in */
  sqlite3Fts5ParserTOKENTYPE yyMinor        /* The minor token to shift in */
){
  yyStackEntry *yytos;
  yypParser->yyidx++;
#ifdef YYTRACKMAXSTACKDEPTH
  if( yypParser->yyidx>yypParser->yyidxMax ){
    yypParser->yyidxMax = yypParser->yyidx;
  }
#endif
#if YYSTACKDEPTH>0 
  if( yypParser->yyidx>=YYSTACKDEPTH ){
    yyStackOverflow(yypParser);
    return;
  }
#else
  if( yypParser->yyidx>=yypParser->yystksz ){
    yyGrowStack(yypParser);
    if( yypParser->yyidx>=yypParser->yystksz ){
      yyStackOverflow(yypParser);
      return;
    }
  }
#endif
  yytos = &yypParser->yystack[yypParser->yyidx];
  yytos->stateno = (YYACTIONTYPE)yyNewState;
  yytos->major = (YYCODETYPE)yyMajor;
  yytos->minor.yy0 = yyMinor;
  yyTraceShift(yypParser, yyNewState);
}
예제 #2
0
파일: grammar.c 프로젝트: eiger/earing
/* 
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
**
** Inputs:
** A pointer to the function used to allocate memory.
**
** Outputs:
** A pointer to a parser.  This pointer is used in subsequent calls
** to Parse and ParseFree.
*/
void *ParseAlloc(void *(*mallocProc)(size_t)){
  yyParser *pParser;
  pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
  if( pParser ){
    pParser->yyidx = -1;
#if YYSTACKDEPTH<=0
    yyGrowStack(pParser);
#endif
  }
  return pParser;
}
예제 #3
0
/*
** Perform a shift action.
*/
static void
yy_shift (yyParser * yypParser,	/* The parser to be shifted */
	  int yyNewState,	/* The new state to shift in */
	  int yyMajor,		/* The major token to shift in */
	  YYMINORTYPE * yypMinor	/* Pointer to the minor token to shift in */
    )
{
    yyStackEntry *yytos;
    yypParser->yyidx++;
#ifdef YYTRACKMAXSTACKDEPTH
    if (yypParser->yyidx > yypParser->yyidxMax)
      {
	  yypParser->yyidxMax = yypParser->yyidx;
      }
#endif
#if YYSTACKDEPTH>0
    if (yypParser->yyidx >= YYSTACKDEPTH)
      {
	  yyStackOverflow (yypParser, yypMinor);
	  return;
      }
#else
    if (yypParser->yyidx >= yypParser->yystksz)
      {
	  yyGrowStack (yypParser);
	  if (yypParser->yyidx >= yypParser->yystksz)
	    {
		yyStackOverflow (yypParser, yypMinor);
		return;
	    }
      }
#endif
    yytos = &yypParser->yystack[yypParser->yyidx];
    yytos->stateno = (YYACTIONTYPE) yyNewState;
    yytos->major = (YYCODETYPE) yyMajor;
    yytos->minor = *yypMinor;
#ifndef NDEBUG
    if (yyTraceFILE && yypParser->yyidx > 0)
      {
	  int i;
	  fprintf (yyTraceFILE, "%sShift %d\n", yyTracePrompt, yyNewState);
	  fprintf (yyTraceFILE, "%sStack:", yyTracePrompt);
	  for (i = 1; i <= yypParser->yyidx; i++)
	      fprintf (yyTraceFILE, " %s",
		       yyTokenName[yypParser->yystack[i].major]);
	  fprintf (yyTraceFILE, "\n");
      }
#endif
}
예제 #4
0
/* 
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
**
** Inputs:
** A pointer to the function used to allocate memory.
**
** Outputs:
** A pointer to a parser.  This pointer is used in subsequent calls
** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
*/
void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){
  yyParser *pParser;
  pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
  if( pParser ){
    pParser->yyidx = -1;
#ifdef YYTRACKMAXSTACKDEPTH
    pParser->yyidxMax = 0;
#endif
#if YYSTACKDEPTH<=0
    pParser->yystack = NULL;
    pParser->yystksz = 0;
    yyGrowStack(pParser);
#endif
  }
  return pParser;
}
예제 #5
0
/* 
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
**
** Inputs:
** A pointer to the function used to allocate memory.
**
** Outputs:
** A pointer to a parser.  This pointer is used in subsequent calls
** to Parse and ParseFree.
*/
void *ParseAlloc(void *(*mallocProc)(size_t)){
  yyParser *pParser;
  pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
  if( pParser ){
    pParser->yyidx = -1;
#ifdef YYTRACKMAXSTACKDEPTH
    pParser->yyidxMax = 0;
#endif
#if YYSTACKDEPTH<=0
    pParser->yystack = NULL;
    pParser->yystksz = 0;
    yyGrowStack(pParser);
#endif
  }
  return pParser;
}
예제 #6
0
void *DfilterAlloc(void *(*mallocProc)(gsize)) {
    yyParser *pParser;
    pParser = (yyParser*)(*mallocProc)( (gsize)sizeof(yyParser) );
#else
void *DfilterAlloc(void *(*mallocProc)(gulong)) {
    yyParser *pParser;
    pParser = (yyParser*)(*mallocProc)( (gulong)sizeof(yyParser) );
#endif
    if( pParser ) {
        pParser->yyidx = -1;
#ifdef YYTRACKMAXSTACKDEPTH
        pParser->yyidxMax = 0;
#endif
#if YYSTACKDEPTH<=0
        yyGrowStack(pParser);
#endif
    }
    return pParser;
}
예제 #7
0
/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
*/
static void yy_reduce(
  yyParser *yypParser,         /* The parser */
  int yyruleno                 /* Number of the rule by which to reduce */
){
  int yygoto;                     /* The next state */
  int yyact;                      /* The next action */
  yyStackEntry *yymsp;            /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  sqlite3Fts5ParserARG_FETCH;
  yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
  if( yyTraceFILE && yyruleno>=0 
        && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
    yysize = yyRuleInfo[yyruleno].nrhs;
    fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
      yyRuleName[yyruleno], yymsp[-yysize].stateno);
  }
#endif /* NDEBUG */

  /* Check that the stack is large enough to grow by a single entry
  ** if the RHS of the rule is empty.  This ensures that there is room
  ** enough on the stack to push the LHS value */
  if( yyRuleInfo[yyruleno].nrhs==0 ){
#ifdef YYTRACKMAXSTACKDEPTH
    if( yypParser->yyidx>yypParser->yyidxMax ){
      yypParser->yyidxMax = yypParser->yyidx;
    }
#endif
#if YYSTACKDEPTH>0 
    if( yypParser->yyidx>=YYSTACKDEPTH-1 ){
      yyStackOverflow(yypParser);
      return;
    }
#else
    if( yypParser->yyidx>=yypParser->yystksz-1 ){
      yyGrowStack(yypParser);
      if( yypParser->yyidx>=yypParser->yystksz-1 ){
        yyStackOverflow(yypParser);
        return;
      }
    }
#endif
  }

  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows:
  **   case 0:
  **  #line <lineno> <grammarfile>
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
/********** Begin reduce actions **********************************************/
        YYMINORTYPE yylhsminor;
      case 0: /* input ::= expr */
#line 82 "fts5parse.y"
{ sqlite3Fts5ParseFinished(pParse, yymsp[0].minor.yy18); }
#line 856 "fts5parse.c"
        break;
      case 1: /* expr ::= expr AND expr */
#line 92 "fts5parse.y"
{
  yylhsminor.yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, yymsp[-2].minor.yy18, yymsp[0].minor.yy18, 0);
}
#line 863 "fts5parse.c"
  yymsp[-2].minor.yy18 = yylhsminor.yy18;
        break;
      case 2: /* expr ::= expr OR expr */
#line 95 "fts5parse.y"
{
  yylhsminor.yy18 = sqlite3Fts5ParseNode(pParse, FTS5_OR, yymsp[-2].minor.yy18, yymsp[0].minor.yy18, 0);
}
#line 871 "fts5parse.c"
  yymsp[-2].minor.yy18 = yylhsminor.yy18;
        break;
      case 3: /* expr ::= expr NOT expr */
#line 98 "fts5parse.y"
{
  yylhsminor.yy18 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, yymsp[-2].minor.yy18, yymsp[0].minor.yy18, 0);
}
#line 879 "fts5parse.c"
  yymsp[-2].minor.yy18 = yylhsminor.yy18;
        break;
      case 4: /* expr ::= LP expr RP */
#line 102 "fts5parse.y"
{yymsp[-2].minor.yy18 = yymsp[-1].minor.yy18;}
#line 885 "fts5parse.c"
        break;
      case 5: /* expr ::= exprlist */
      case 6: /* exprlist ::= cnearset */ yytestcase(yyruleno==6);
#line 103 "fts5parse.y"
{yylhsminor.yy18 = yymsp[0].minor.yy18;}
#line 891 "fts5parse.c"
  yymsp[0].minor.yy18 = yylhsminor.yy18;
        break;
      case 7: /* exprlist ::= exprlist cnearset */
#line 106 "fts5parse.y"
{
  yylhsminor.yy18 = sqlite3Fts5ParseNode(pParse, FTS5_AND, yymsp[-1].minor.yy18, yymsp[0].minor.yy18, 0);
}
#line 899 "fts5parse.c"
  yymsp[-1].minor.yy18 = yylhsminor.yy18;
        break;
      case 8: /* cnearset ::= nearset */
#line 110 "fts5parse.y"
{ 
  yylhsminor.yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, yymsp[0].minor.yy26); 
}
#line 907 "fts5parse.c"
  yymsp[0].minor.yy18 = yylhsminor.yy18;
        break;
      case 9: /* cnearset ::= colset COLON nearset */
#line 113 "fts5parse.y"
{ 
  sqlite3Fts5ParseSetColset(pParse, yymsp[0].minor.yy26, yymsp[-2].minor.yy3);
  yylhsminor.yy18 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, yymsp[0].minor.yy26); 
}
#line 916 "fts5parse.c"
  yymsp[-2].minor.yy18 = yylhsminor.yy18;
        break;
      case 10: /* colset ::= LCP colsetlist RCP */
#line 123 "fts5parse.y"
{ yymsp[-2].minor.yy3 = yymsp[-1].minor.yy3; }
#line 922 "fts5parse.c"
        break;
      case 11: /* colset ::= STRING */
#line 124 "fts5parse.y"
{
  yylhsminor.yy3 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0);
}
#line 929 "fts5parse.c"
  yymsp[0].minor.yy3 = yylhsminor.yy3;
        break;
      case 12: /* colsetlist ::= colsetlist STRING */
#line 128 "fts5parse.y"
{ 
  yylhsminor.yy3 = sqlite3Fts5ParseColset(pParse, yymsp[-1].minor.yy3, &yymsp[0].minor.yy0); }
#line 936 "fts5parse.c"
  yymsp[-1].minor.yy3 = yylhsminor.yy3;
        break;
      case 13: /* colsetlist ::= STRING */
#line 130 "fts5parse.y"
{ 
  yylhsminor.yy3 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0); 
}
#line 944 "fts5parse.c"
  yymsp[0].minor.yy3 = yylhsminor.yy3;
        break;
      case 14: /* nearset ::= phrase */
#line 140 "fts5parse.y"
{ yylhsminor.yy26 = sqlite3Fts5ParseNearset(pParse, 0, yymsp[0].minor.yy11); }
#line 950 "fts5parse.c"
  yymsp[0].minor.yy26 = yylhsminor.yy26;
        break;
      case 15: /* nearset ::= STRING LP nearphrases neardist_opt RP */
#line 141 "fts5parse.y"
{
  sqlite3Fts5ParseNear(pParse, &yymsp[-4].minor.yy0);
  sqlite3Fts5ParseSetDistance(pParse, yymsp[-2].minor.yy26, &yymsp[-1].minor.yy0);
  yylhsminor.yy26 = yymsp[-2].minor.yy26;
}
#line 960 "fts5parse.c"
  yymsp[-4].minor.yy26 = yylhsminor.yy26;
        break;
      case 16: /* nearphrases ::= phrase */
#line 147 "fts5parse.y"
{ 
  yylhsminor.yy26 = sqlite3Fts5ParseNearset(pParse, 0, yymsp[0].minor.yy11); 
}
#line 968 "fts5parse.c"
  yymsp[0].minor.yy26 = yylhsminor.yy26;
        break;
      case 17: /* nearphrases ::= nearphrases phrase */
#line 150 "fts5parse.y"
{
  yylhsminor.yy26 = sqlite3Fts5ParseNearset(pParse, yymsp[-1].minor.yy26, yymsp[0].minor.yy11);
}
#line 976 "fts5parse.c"
  yymsp[-1].minor.yy26 = yylhsminor.yy26;
        break;
      case 18: /* neardist_opt ::= */
#line 157 "fts5parse.y"
{ yymsp[1].minor.yy0.p = 0; yymsp[1].minor.yy0.n = 0; }
#line 982 "fts5parse.c"
        break;
      case 19: /* neardist_opt ::= COMMA STRING */
#line 158 "fts5parse.y"
{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
#line 987 "fts5parse.c"
        break;
      case 20: /* phrase ::= phrase PLUS STRING star_opt */
#line 170 "fts5parse.y"
{ 
  yylhsminor.yy11 = sqlite3Fts5ParseTerm(pParse, yymsp[-3].minor.yy11, &yymsp[-1].minor.yy0, yymsp[0].minor.yy20);
}
#line 994 "fts5parse.c"
  yymsp[-3].minor.yy11 = yylhsminor.yy11;
        break;
      case 21: /* phrase ::= STRING star_opt */
#line 173 "fts5parse.y"
{ 
  yylhsminor.yy11 = sqlite3Fts5ParseTerm(pParse, 0, &yymsp[-1].minor.yy0, yymsp[0].minor.yy20);
}
#line 1002 "fts5parse.c"
  yymsp[-1].minor.yy11 = yylhsminor.yy11;
        break;
      case 22: /* star_opt ::= STAR */
#line 182 "fts5parse.y"
{ yymsp[0].minor.yy20 = 1; }
#line 1008 "fts5parse.c"
        break;
      case 23: /* star_opt ::= */
#line 183 "fts5parse.y"
{ yymsp[1].minor.yy20 = 0; }
#line 1013 "fts5parse.c"
        break;
      default:
        break;
/********** End reduce actions ************************************************/
  };
  assert( yyruleno>=0 && yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  if( yyact <= YY_MAX_SHIFTREDUCE ){
    if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
    yypParser->yyidx -= yysize - 1;
    yymsp -= yysize-1;
    yymsp->stateno = (YYACTIONTYPE)yyact;
    yymsp->major = (YYCODETYPE)yygoto;
    yyTraceShift(yypParser, yyact);
  }else{
    assert( yyact == YY_ACCEPT_ACTION );
    yypParser->yyidx -= yysize;
    yy_accept(yypParser);
  }
}
예제 #8
0
/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
*/
static void yy_reduce(
  yyParser *yypParser,         /* The parser */
  unsigned int yyruleno        /* Number of the rule by which to reduce */
){
  int yygoto;                     /* The next state */
  int yyact;                      /* The next action */
  yyStackEntry *yymsp;            /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  Parser_v0_1_ARG_FETCH;
  yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
  if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
    yysize = yyRuleInfo[yyruleno].nrhs;
    fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
      yyRuleName[yyruleno], yymsp[-yysize].stateno);
  }
#endif /* NDEBUG */

  /* Check that the stack is large enough to grow by a single entry
  ** if the RHS of the rule is empty.  This ensures that there is room
  ** enough on the stack to push the LHS value */
  if( yyRuleInfo[yyruleno].nrhs==0 ){
#ifdef YYTRACKMAXSTACKDEPTH
    if( yypParser->yyidx>yypParser->yyidxMax ){
      yypParser->yyidxMax = yypParser->yyidx;
    }
#endif
#if YYSTACKDEPTH>0 
    if( yypParser->yyidx>=YYSTACKDEPTH-1 ){
      yyStackOverflow(yypParser);
      return;
    }
#else
    if( yypParser->yyidx>=yypParser->yystksz-1 ){
      yyGrowStack(yypParser);
      if( yypParser->yyidx>=yypParser->yystksz-1 ){
        yyStackOverflow(yypParser);
        return;
      }
    }
#endif
  }

  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows:
  **   case 0:
  **  #line <lineno> <grammarfile>
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
/********** Begin reduce actions **********************************************/
        YYMINORTYPE yylhsminor;
      case 0: /* program ::= IDENTIFIER NUMBER types */
{ *arg = yymsp[0].minor.yy11; }
        break;
      case 1: /* types ::= types type */
{ yylhsminor.yy11 = yymsp[-1].minor.yy11; Add(yylhsminor.yy11, yymsp[0].minor.yy33); }
  yymsp[-1].minor.yy11 = yylhsminor.yy11;
        break;
      case 2: /* types ::= type */
{ yylhsminor.yy11 = CreateProgramNode(); Add(yylhsminor.yy11, yymsp[0].minor.yy33); }
  yymsp[0].minor.yy11 = yylhsminor.yy11;
        break;
      case 3: /* type ::= IDENTIFIER LBRACE values RBRACE SEMICOLON */
{ yylhsminor.yy33 = yymsp[-2].minor.yy33; SetIden(yylhsminor.yy33, yymsp[-4].minor.yy0); }
  yymsp[-4].minor.yy33 = yylhsminor.yy33;
        break;
      case 4: /* values ::= values value */
{ yylhsminor.yy33 = yymsp[-1].minor.yy33; Add(yylhsminor.yy33, yymsp[0].minor.yy30); }
  yymsp[-1].minor.yy33 = yylhsminor.yy33;
        break;
      case 5: /* values ::= value */
{ yylhsminor.yy33 = CreateTypeNode(); Add(yylhsminor.yy33, yymsp[0].minor.yy30); }
  yymsp[0].minor.yy33 = yylhsminor.yy33;
        break;
      case 6: /* value ::= IDENTIFIER COLON expression SEMICOLON */
{ yylhsminor.yy30 = CreateAssignNode(yymsp[-3].minor.yy0, yymsp[-1].minor.yy37); }
  yymsp[-3].minor.yy30 = yylhsminor.yy30;
        break;
      case 7: /* expression ::= number */
{ yylhsminor.yy37 = CreateExpressionNode(yymsp[0].minor.yy10); }
  yymsp[0].minor.yy37 = yylhsminor.yy37;
        break;
      case 8: /* expression ::= IDENTIFIER */
{ yylhsminor.yy37 = CreateExpressionNode(yymsp[0].minor.yy0); }
  yymsp[0].minor.yy37 = yylhsminor.yy37;
        break;
      case 9: /* expression ::= IDENTIFIER vector */
{ yylhsminor.yy37 = CreateColourNode(yymsp[-1].minor.yy0, yymsp[0].minor.yy6); }
  yymsp[-1].minor.yy37 = yylhsminor.yy37;
        break;
      case 10: /* expression ::= number IDENTIFIER */
{ yylhsminor.yy37 = CreateUnitValueNode(yymsp[-1].minor.yy10, yymsp[0].minor.yy0); }
  yymsp[-1].minor.yy37 = yylhsminor.yy37;
        break;
      case 11: /* expression ::= vector */
{ yylhsminor.yy37 = CreateVecExprNode(yymsp[0].minor.yy6); }
  yymsp[0].minor.yy37 = yylhsminor.yy37;
        break;
      case 12: /* vector ::= LESSER vector_vals GREATER */
{ yymsp[-2].minor.yy6 = yymsp[-1].minor.yy6; }
        break;
      case 13: /* vector_vals ::= vector_vals COMMA number */
{ yylhsminor.yy6 = yymsp[-2].minor.yy6; Add(yylhsminor.yy6, CreateExpressionNode(yymsp[0].minor.yy10)); }
  yymsp[-2].minor.yy6 = yylhsminor.yy6;
        break;
      case 14: /* vector_vals ::= number */
{ yylhsminor.yy6 = CreateVectorNode(); Add(yylhsminor.yy6, CreateExpressionNode(yymsp[0].minor.yy10)); }
  yymsp[0].minor.yy6 = yylhsminor.yy6;
        break;
      case 15: /* number ::= HEXVAL */
      case 16: /* number ::= NUMBER */ yytestcase(yyruleno==16);
{ yylhsminor.yy10 = yymsp[0].minor.yy0; }
  yymsp[0].minor.yy10 = yylhsminor.yy10;
        break;
      default:
        break;
/********** End reduce actions ************************************************/
  };
  assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  if( yyact <= YY_MAX_SHIFTREDUCE ){
    if( yyact>YY_MAX_SHIFT ) yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
    yypParser->yyidx -= yysize - 1;
    yymsp -= yysize-1;
    yymsp->stateno = (YYACTIONTYPE)yyact;
    yymsp->major = (YYCODETYPE)yygoto;
    yyTraceShift(yypParser, yyact);
  }else{
    assert( yyact == YY_ACCEPT_ACTION );
    yypParser->yyidx -= yysize;
    yy_accept(yypParser);
  }
}