/*
** 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 */
  YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
  yyStackEntry *yymsp;            /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  DSGMASystemParserARG_FETCH;
  yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
  if( yyTraceFILE && yyruleno>=0 
      && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
    fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
	    yyRuleName[yyruleno]);
  }
#endif /* NDEBUG */

  /* Silence complaints from purify about yygotominor being uninitialized
  ** in some cases when it is copied into the stack after the following
  ** switch.  yygotominor is uninitialized when a rule reduces that does
  ** not set the value of its left-hand side nonterminal.  Leaving the
  ** value of the nonterminal uninitialized is utterly harmless as long
  ** as the value is never used.  So really the only thing this code
  ** accomplishes is to quieten purify.  
  **
  ** 2007-01-16:  The wireshark project (www.wireshark.org) reports that
  ** without this code, their parser segfaults.  I'm not sure what there
  ** parser is doing to make this happen.  This is the second bug report
  ** from wireshark this week.  Clearly they are stressing Lemon in ways
  ** that it has not been previously stressed...  (SQLite ticket #2172)
  */
  /*memset(&yygotominor, 0, sizeof(yygotominor));*/
  yygotominor = yyzerominor;


  switch( yyruleno ){
    /* Beginning here are the reduction cases.  A typical example
    ** follows:
    **   case 0:
    **  #line <lineno> <grammarfile>
    **     { ... }           // User supplied code
    **  #line <lineno> <thisfile>
    **     break;
    */
      case 3: /* expression ::= term */
      case 5: /* expression ::= expression PLUS term */ yytestcase(yyruleno==5);
{
        DSGMAParserAuxSetSign(*parser_aux, AUX_SIGN_POSITIVE);
        DSGMAParserAuxNewTerm(*parser_aux);
        *parser_aux = DSGMAParserAuxNextNode(*parser_aux);
}
        break;
      case 4: /* expression ::= MINUS term */
      case 6: /* expression ::= expression MINUS term */ yytestcase(yyruleno==6);
{
        DSGMAParserAuxSetSign(*parser_aux, AUX_SIGN_NEGATIVE);
        DSGMAParserAuxNewTerm(*parser_aux);
        *parser_aux = DSGMAParserAuxNextNode(*parser_aux);
}
        break;
      case 11: /* powerlaw ::= CONSTANT */
{
        DSGMAParserAuxAddConstantBase(*parser_aux, DSExpressionTokenDouble((struct expression_token *)yymsp[0].minor.yy0));
}
        break;
      case 12: /* powerlaw ::= ID */
{
        DSGMAParserAuxAddVariableExponentPair(*parser_aux,
                                              DSExpressionTokenString((struct expression_token *)yymsp[0].minor.yy0), 1.0);
}
        break;
      case 13: /* powerlaw ::= ID POWER CONSTANT */
{
        DSGMAParserAuxAddVariableExponentPair(*parser_aux,
        DSExpressionTokenString((struct expression_token *)yymsp[-2].minor.yy0),
        DSExpressionTokenDouble((struct expression_token *)yymsp[0].minor.yy0));
}
        break;
      case 14: /* powerlaw ::= ID POWER MINUS CONSTANT */
{
        DSGMAParserAuxAddVariableExponentPair(*parser_aux,
        DSExpressionTokenString((struct expression_token *)yymsp[-3].minor.yy0),
        -DSExpressionTokenDouble((struct expression_token *)yymsp[0].minor.yy0));
}
        break;
      default:
      /* (0) start ::= equation */ yytestcase(yyruleno==0);
      /* (1) equation ::= ID PRIME EQUALS expression */ yytestcase(yyruleno==1);
      /* (2) equation ::= CONSTANT EQUALS expression */ yytestcase(yyruleno==2);
      /* (7) term ::= powerlaw */ yytestcase(yyruleno==7);
      /* (8) term ::= PLUS powerlaw */ yytestcase(yyruleno==8);
      /* (9) term ::= term TIMES powerlaw */ yytestcase(yyruleno==9);
      /* (10) term ::= term DIVIDE powerlaw */ yytestcase(yyruleno==10);
        break;
  };
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yypParser->yyidx -= yysize;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  if( yyact < YYNSTATE ){
#ifdef NDEBUG
    /* If we are not debugging and the reduce action popped at least
    ** one element off the stack, then we can push the new element back
    ** onto the stack here, and skip the stack overflow test in yy_shift().
    ** That gives a significant speed improvement. */
    if( yysize ){
      yypParser->yyidx++;
      yymsp -= yysize-1;
      yymsp->stateno = (YYACTIONTYPE)yyact;
      yymsp->major = (YYCODETYPE)yygoto;
      yymsp->minor = yygotominor;
    }else
#endif
      {
	yy_shift(yypParser,yyact,yygoto,&yygotominor);
      }
  }else{
    assert( yyact == YYNSTATE + YYNRULE + 1 );
    yy_accept(yypParser);
  }
}
示例#2
0
文件: grammar.c 项目: claesjac/yogo
/*
** 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 */
  YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
  yyStackEntry *yymsp;            /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  yogoc_ParseARG_FETCH;
  yymsp = &yypParser->yystack[yypParser->yyidx];
#ifndef NDEBUG
  if( yyTraceFILE && yyruleno>=0 
        && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
    fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
      yyRuleName[yyruleno]);
  }
#endif /* NDEBUG */

  /* Silence complaints from purify about yygotominor being uninitialized
  ** in some cases when it is copied into the stack after the following
  ** switch.  yygotominor is uninitialized when a rule reduces that does
  ** not set the value of its left-hand side nonterminal.  Leaving the
  ** value of the nonterminal uninitialized is utterly harmless as long
  ** as the value is never used.  So really the only thing this code
  ** accomplishes is to quieten purify.  
  **
  ** 2007-01-16:  The wireshark project (www.wireshark.org) reports that
  ** without this code, their parser segfaults.  I'm not sure what there
  ** parser is doing to make this happen.  This is the second bug report
  ** from wireshark this week.  Clearly they are stressing Lemon in ways
  ** that it has not been previously stressed...  (SQLite ticket #2172)
  */
  /*memset(&yygotominor, 0, sizeof(yygotominor));*/
  yygotominor = yyzerominor;


  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows:
  **   case 0:
  **  #line <lineno> <grammarfile>
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
      case 8: /* package ::= PACKAGE PKGNAME SEMI */
      case 9: /* package ::= PACKAGE IDENTIFIER SEMI */ yytestcase(yyruleno==9);
#line 37 "lib/grammar.y"
{ yogoc_set_package(emit, yymsp[-1].minor.yy0->value); }
#line 714 "lib/grammar.c"
        break;
      case 10: /* named_sub ::= SUB IDENTIFIER block */
#line 41 "lib/grammar.y"
{ yogoc_set_sub(emit, yymsp[-1].minor.yy0->value); }
#line 719 "lib/grammar.c"
        break;
      case 11: /* anon_sub ::= SUB block */
#line 42 "lib/grammar.y"
{ yogoc_set_sub(emit, NULL); }
#line 724 "lib/grammar.c"
        break;
      case 12: /* block ::= OPEN_CURLY stmtlist CLOSE_CURLY */
#line 44 "lib/grammar.y"
{ fprintf(stderr, "Found block\n"); }
#line 729 "lib/grammar.c"
        break;
      case 13: /* do ::= DO block */
#line 47 "lib/grammar.y"
{ fprintf(stderr, "Found do\n"); }
#line 734 "lib/grammar.c"
        break;
      case 14: /* var_decl ::= MY type var SEMI */
#line 50 "lib/grammar.y"
{ fprintf(stderr, "Found my decl\n"); }
#line 739 "lib/grammar.c"
        break;
      default:
      /* (0) input ::= stmtlist */ yytestcase(yyruleno==0);
      /* (1) stmtlist ::= stmtlist stmt */ yytestcase(yyruleno==1);
      /* (2) stmtlist ::= */ yytestcase(yyruleno==2);
      /* (3) stmt ::= package */ yytestcase(yyruleno==3);
      /* (4) stmt ::= named_sub */ yytestcase(yyruleno==4);
      /* (5) stmt ::= anon_sub */ yytestcase(yyruleno==5);
      /* (6) stmt ::= var_decl */ yytestcase(yyruleno==6);
      /* (7) stmt ::= do */ yytestcase(yyruleno==7);
      /* (15) var ::= SCALAR_VAR */ yytestcase(yyruleno==15);
      /* (16) var ::= HASH_VAR */ yytestcase(yyruleno==16);
      /* (17) var ::= ARRAY_VAR */ yytestcase(yyruleno==17);
      /* (18) type ::= INTEGER */ yytestcase(yyruleno==18);
      /* (19) type ::= DOUBLE */ yytestcase(yyruleno==19);
      /* (20) type ::= STRING */ yytestcase(yyruleno==20);
      /* (21) type ::= HASH */ yytestcase(yyruleno==21);
      /* (22) type ::= ARRAY */ yytestcase(yyruleno==22);
      /* (23) type ::= ANY */ yytestcase(yyruleno==23);
      /* (24) type ::= OBJECT */ yytestcase(yyruleno==24);
      /* (25) type ::= */ yytestcase(yyruleno==25);
        break;
  };
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yypParser->yyidx -= yysize;
  yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  if( yyact < YYNSTATE ){
#ifdef NDEBUG
    /* If we are not debugging and the reduce action popped at least
    ** one element off the stack, then we can push the new element back
    ** onto the stack here, and skip the stack overflow test in yy_shift().
    ** That gives a significant speed improvement. */
    if( yysize ){
      yypParser->yyidx++;
      yymsp -= yysize-1;
      yymsp->stateno = (YYACTIONTYPE)yyact;
      yymsp->major = (YYCODETYPE)yygoto;
      yymsp->minor = yygotominor;
    }else
#endif
    {
      yy_shift(yypParser,yyact,yygoto,&yygotominor);
    }
  }else{
    assert( yyact == YYNSTATE + YYNRULE + 1 );
    yy_accept(yypParser);
  }
}