コード例 #1
0
ファイル: load.c プロジェクト: earthGavinLee/hg556a_source
void
load_vars(const char *file)
{
  const Unit_t *curr_unit = NULL;

  int ret = 0;   /* to silence gcc 2.7.2.1 */
  char *varname;
  InitPvc_t *pvc;
  LaneDestList_t *ltmp;
  int read_flag = 1;

  assert(file != NULL);
  Debug_unit(&load_unit, "Loading variables from file %s", file);
  yyin = fopen(file, "r");
  if (!yyin) {
    Debug_unit(&load_unit, "Cannot open file %s: %s", file, strerror(errno));
    return;
  }
  g_buf_index = 0;
  do {
    if (read_flag)
      ret = yylex();
    else
      read_flag =1;
    switch(ret) {
    case END:
      Debug_unit(&load_unit, "EOF");
      break;
    case UNIT:
      Debug_unit(&load_unit, "Got unit %s", g_return.stringgi);
      curr_unit = find_unit(g_return.stringgi);
      if (curr_unit == NULL) {
	Debug_unit(&load_unit, "Unknown unit %s", g_return.stringgi);
      }
      Debug_unit(&load_unit, "Got unit %s", g_return.stringgi);
      mem_free(&load_unit,g_return.stringgi);
      break;
    case VARNAME:
      varname = g_return.stringgi;
      Debug_unit(&load_unit, "Got variable name %s", varname);
      ret = yylex();
      switch(ret) {
      case STRING:
	Debug_unit(&load_unit, "Variable is string: %s", g_return.stringgi);
	set_var_str(curr_unit, varname, g_return.stringgi);
	break;
      case BOOLEAN:
	Debug_unit(&load_unit, "Variable is boolean: %s", 
		   g_return.bool==BL_TRUE?"True":"False");
	set_var_bool(curr_unit, varname, g_return.bool);
	break;
      case INTEGER:
	Debug_unit(&load_unit, "Variable is integer: %d", g_return.intti);
	set_var_int(curr_unit, varname, g_return.intti);
	break;
      case ATMADDRESS:
	Debug_unit(&load_unit, "Variable is atmaddress ");
	dump_atmaddr(g_return.atmaddress);
	set_var_addr(curr_unit, varname, g_return.atmaddress);
	break;
      case LANEDEST:
	Debug_unit(&load_unit, "Invalid variable value for %s", varname);
	mem_free(&load_unit, g_return.destaddr);
	break;
      case UNIT:
	Debug_unit(&load_unit, "Invalid variable value for %s", varname);
	mem_free(&load_unit, g_return.stringgi);
	break;
      case VCC:
	Debug_unit(&load_unit, "Variable is vcc");
	pvc = (InitPvc_t *)mem_alloc(curr_unit, sizeof(InitPvc_t));
	pvc->pvc = (LaneVcc_t *)mem_alloc(curr_unit, sizeof(LaneVcc_t));
	pvc->pvc->port = g_return.vcc.port;
	pvc->pvc->vpi = g_return.vcc.vpi;
	pvc->pvc->vci = g_return.vcc.vci;
	pvc->address = NULL;
	pvc->lecid = 0;
	pvc->destinations = NULL;
	ret = yylex();
	if (ret != ATMADDRESS) {
	  Debug_unit(&load_unit, "Invalid atm_address for pvc %d,%d,%d",
		     pvc->pvc->port, pvc->pvc->vpi, pvc->pvc->vci);
	  switch(ret) {
	  case UNIT:
	  case STRING:
	  case VARNAME:
	    mem_free(&load_unit, g_return.stringgi);
	    break;
	  case LANEDEST:
	    mem_free(&load_unit, g_return.destaddr);
	    break;
	  }
	} else {
	  pvc->address = g_return.atmaddress;
	}
	ret = yylex();
	if (ret != INTEGER) {
	  Debug_unit(&load_unit, "Invalid lecid for pvc %d,%d,%d\n",
		     pvc->pvc->port,pvc->pvc->vpi,pvc->pvc->vci);
	  switch(ret) {
	  case UNIT:
	  case STRING:
	  case VARNAME:
	    mem_free(&load_unit, g_return.stringgi);
	    break;
	  case LANEDEST:
	    mem_free(&load_unit, g_return.destaddr);
	    break;
	  case ATMADDRESS:
	    mem_free(&load_unit, g_return.atmaddress);
	    break;
	  }
	} else {
	  pvc->lecid = g_return.intti;
	}
	while((ret=yylex())==LANEDEST) {
	  ltmp=(LaneDestList_t *)mem_alloc(&load_unit, sizeof(LaneDestList_t));
	  ltmp->addr = g_return.destaddr;
	  ltmp->next = pvc->destinations;
	  pvc->destinations = ltmp;
	}
	read_flag=0;
	set_var_vcc(curr_unit, varname, pvc);
	break;	
      default:
	Debug_unit(&load_unit, "Invalid variable value for %s", varname);
	break;
      }
      break;
    case STRING:
      Debug_unit(&load_unit,"Invalid string placement %s",g_return.stringgi);
      mem_free(&load_unit, g_return.stringgi);
      break;
    case ATMADDRESS:
      Debug_unit(&load_unit, "Invalid atm address placement");
      mem_free(&load_unit, g_return.atmaddress);
      break;
    case LANEDEST:
      Debug_unit(&load_unit, "Invalid lane destination placement");
      mem_free(&load_unit, g_return.destaddr);
      break;
    case INTEGER:
      Debug_unit(&load_unit, "Invalid integer placement");
      break;
    default:
      Debug_unit(&load_unit, "Invalid input");
      break;
    }
  } while (ret != END);
  if (fclose(yyin) != 0) {
    Debug_unit(&load_unit, "Cannot close file %s: %s", file, strerror(errno));
  }
}
コード例 #2
0
ファイル: stablex.c プロジェクト: ombt/ombt
main()
{
	while (yylex() != 0);
}
コード例 #3
0
ファイル: css.c プロジェクト: rockdaboot/mget
void mget_css_parse_buffer(
	const char *buf,
	void(*callback_uri)(void *user_ctx, const char *url, size_t len, size_t pos),
	void(*callback_encoding)(void *user_ctx, const char *url, size_t len),
	void *user_ctx)
{
	int token;
	size_t length, pos = 0;
	char *text;
	yyscan_t scanner;

	// let flex operate on buf as a 0 terminated string
	// we could give buflen to this function and use yy_scan_bytes or yy_scan_buffer
	yylex_init(&scanner);
	yy_scan_string(buf, scanner);

	while ((token = yylex(scanner)) != CSSEOF) {
		if (token == IMPORT_SYM) {
			// e.g. @import "http:example.com/index.html"
			pos += yyget_leng(scanner);

			// skip whitespace before URI/STRING
			while ((token = yylex(scanner)) == S)
				pos += yyget_leng(scanner);

			// now token should be STRING or URI
			if (token == STRING)
				token = URI;
		}

		if (token == URI && callback_uri) {
			// e.g. url(http:example.com/index.html)
			text = yyget_text(scanner);
			length = yyget_leng(scanner);

			if (*text == '\'' || *text == '\"') {
				// a string - remove the quotes
				callback_uri(user_ctx, text + 1, length - 2, pos + 1);
			} else {
				// extract URI from url(...)
				if (!strncasecmp(text, "url(", 4)) {
					char *otext = text;

					// remove trailing ) and any spaces before
					for (length--; isspace(text[length - 1]); length--);

					// remove leading url( and any spaces after
					for (length -= 4, text += 4; isspace(*text); text++, length--);

					// remove quotes
					if (*text == '\'' || *text == '\"') {
						text++;
						length -= 2;
					}

					callback_uri(user_ctx, text, length, pos + (text - otext));
				}
			}
		} else if (token == CHARSET_SYM && callback_encoding) {
			// e.g. @charset "UTF-8"
			pos += yyget_leng(scanner);

			// skip whitespace before charset name
			while ((token = yylex(scanner)) == S)
				pos += yyget_leng(scanner);

			// now token should be STRING
			if (token == STRING) {
				text = yyget_text(scanner);
				length = yyget_leng(scanner);

				if (*text == '\'' || *text == '\"') {
					// a string - remove the quotes
					callback_encoding(user_ctx, text + 1, length - 2);
				} else {
					// a string without quotes
					callback_encoding(user_ctx, text, length);
				}
			} else {
				error_printf(_("Unknown token after @charset: %d\n"), token);
			}
		}
		pos += yyget_leng(scanner);
	}

	yylex_destroy(scanner);
}
コード例 #4
0
ファイル: yyparse.c プロジェクト: dank101/2BSD
/*
 * This routine parses the input stream, and
 * returns if it accepts, or if an unrecoverable syntax
 * error is encountered.
 */
yyparse()
{
	register int *ps, n, *p;
	int paniced, *panicps, idfail;

	yystate = 0;
	yychar = yylex();
	OY.Yychar = -1;
	yyshifts = 3;
	paniced = 0;
	ps = &yys[0]-1;
	yypv = &yyv[0]-1;
#ifdef PXP
	yypw = &yyw[0]-1;
#endif

stack:
	/*
	 * Push new state and value.
	 */
	if (yypv >= &yyv[MAXDEPTH-1]) {
		yerror("Parse stack overflow");
		pexit(DIED);
	}
	*++ps = yystate;
	*++yypv = yyval;
#ifdef PXP
	yypw++;
#endif
newstate:
	/*
	 * Locate parsing actions for the
	 * new parser state.
	 */
	p = &yyact[ yypact[yystate+1] ]; 
actn:
	/*
	 * Search the parse actions table
	 * for something useful to do.
	 * While n is non-positive, it is the negation
	 * of the token we are testing for.
	 */
#ifdef PI
	if ((n = *p++) <= 0) {
		if (yychar < 0)
			yychar = yylex();
		do
			if ((n =+ yychar) != 0)
				p++;
		while ((n = *p++) <= 0);
	}
#else
	while ((n = *p++) <= 0)
		if ((n =+ yychar) != 0)
			p++;
#endif
	switch (n >> 12) {

		/*
		 * Shift.
		 */
		case 2:
#ifdef PXP
			yypw[1].Wseqid = yyseqid;
			yypw[1].Wcol = yycol;
#endif
			OYcopy();
			yystate = n & 07777;
			yyval = yylval;
#ifdef PI
			yychar = -1;
#else
			yychar = yylex();
#endif
			yyshifts++;
			yytshifts++;
			goto stack;

		/*
		 * Reduce.
		 */
		case 3:
			n =& 07777;
			N = yyr2[n];
			if (N == 1 && OY.Yychar == YID && !yyEactr(n, yypv[0])) {
				idfail = 1;
				goto errin;
			}
			OY.Yychar = -1;
			ps =- N;
			yypv =- N;
#ifdef PXP
			yypw =- N;
#endif
			yyval = yypv[1];
			yyactr(n);
			/*
			 * Use goto table to find next state.
			 */
			p = &yygo[yypgo[yyr1[n]]];
			while (*p != *ps && *p >= 0)
				p =+ 2;
			yystate = p[1];
			goto stack;

		/*
		 * Accept.
		 */
		case 4:
			return;

		/*
		 * Error.
		 */
		case 1:
			idfail = 0;
errin:
			if ((paniced || yyshifts != 0) && yyrecover(ps, idfail)) {
				paniced = 0;
				ps = Ps;
				yystate = *ps;
				goto newstate;
			}
			/*
			 * Find a state where 'error' is a
			 * legal shift action.
			 */
			if (paniced && yyshifts <= 0 && ps >= panicps) {
				yypv =- (ps - panicps) + 1;
#ifdef PXP
				yypw =- (ps - panicps) + 1;
#endif
				ps = panicps - 1;
			}
			while (ps >= yys) {
				for (p = &yyact[ yypact[*ps+1] ] ; *p <= 0; p=+ 2)
					if (*p == -256) {
						panicps = ps;
						yystate= p[1] & 07777;
						yyOshifts = yyshifts;
						yyshifts = 0;
						paniced = 1;
						goto stack;
					}
				--ps;
				--yypv;
#ifdef PXP
				--yypw;
#endif
#ifdef PI
				if (OY.Yychar != YID)
					syneflg++;
#endif
				OY.Yychar = -1;
			}
			if (yychar == YEOF)
				yyunexeof();
			if (yystate == 1)
				yyexeof();
			yerror("Unrecoverable syntax error - QUIT");
			return;
	}
	panic("yyparse");
}
コード例 #5
0
ファイル: parse_q.c プロジェクト: jeromekelleher/gqt
//{{{ int parse_q(char *q_text, struct gqt_query *q_props)
int parse_q(char *q_text, struct gqt_query *q_props)
{
    int ntoken, vtoken;

    int state = START_OF_EXP;

    q_props->variant_op = -1;
    q_props->op_condition = -1;
    q_props->condition_value = -1;

    memset(q_props->genotype_condition,0,4*sizeof(int));

    char *in = (char *) malloc(100*sizeof(char));
    if (!in)
        err(EX_OSERR, "malloc error");
    strcpy(in, q_text);
    YY_BUFFER_STATE buffer = yy_scan_string(in);

    ntoken = yylex();

    while (ntoken) {
        switch (ntoken) {
            case p_maf:
            case p_count:
            case p_pct:
                if (set_op(ntoken, q_props, &state))
                    return 1;
                int last_ntoken = ntoken;
                ntoken = yylex();
                if (ntoken != p_r_paren) {
                    fprintf(stderr, "SYNTAX ERROR: '(' expected after '%s' ",
                            names[last_ntoken]);
                    return 1;
                }
                state |= OP_SET_START;
                break;
            case p_het:
            case p_homo_ref:
            case p_homo_alt:
            case p_unknown:
                if (set_gt(ntoken, q_props, &state))
                    return 1;
                state |= GT_SET_START;
                break;
            case p_r_paren:
                fprintf(stderr, "SYNTAX ERROR: "
                            "Opperation (count,pct,maf) expected "
                            "prior to '%s' ",
                            names[ntoken]);
                    return 1;
            case p_l_paren:



                if ( ((q_props->variant_op == p_count) ||
                      (q_props->variant_op == p_pct))  &&
                     (state != (OP_SET_START | GT_SET_START) ) ) {
                    fprintf(stderr, "SYNTAX ERROR: "
                            "Opperation (count,pct) and "
                            "genotype (HOM_REF,HET,HOM_ALT,UNKNONW) expected "
                            "prior to '%s' ",
                            names[ntoken]);
                    return 1;
                } else if ( (q_props->variant_op == p_maf) &&
                            (state != OP_SET_START ) ) {
                    fprintf(stderr, "SYNTAX ERROR: "
                            "Opperation (maf) does not expect "
                            "genotype (HOM_REF,HET,HOM_ALT,UNKNONW) "
                            "prior to '%s' ",
                            names[ntoken]);
                    return 1;
                }

                state |= OP_SET_END;
                state |= GT_SET_END;
                break;
            case p_equal:
            case p_not_equal:
            case p_less_than:
            case p_greater_than:
            case p_less_than_equal:
            case p_greater_than_equal:
                if (set_op_cond(ntoken, q_props, &state))
                    return 1;
                break;
            case p_number:
                if (set_cond_value(yytext, q_props, &state))
                    return 1;
                break;
            default:
                printf("Syntax error in line\n");
        }

        ntoken = yylex();
    }
    yy_delete_buffer(buffer);

    if (((state & OP_SET_START) == OP_SET_START) &&
        ((state & OP_SET_END) != OP_SET_END)) {
        fprintf(stderr, "SYNTAX ERROR: Missing ')' ");
        return 1;
    }

    if (((state & COND_SET) == COND_SET) &&
        ((state & COND_VALUE_SET) != COND_VALUE_SET)) {
        fprintf(stderr, "SYNTAX ERROR: Missing condition value "
                "(after ==, <, etc.) ");
        return 1;
    }


    /*
    printf("%d\n", q0.variant_op);
    int i;
    for (i = 0; i < 4; ++i)
        printf("%d", q0.genotype_condition[i]);
    printf("\n");
    printf("%d\n", q0.op_condition);
    printf("%f\n", q0.condition_value);
    */

    //free(in);
    return 0;
}
コード例 #6
0
ファイル: main.c プロジェクト: HunterZ/larn
/*
 * parse()
 *
 * get and execute a command
 */
static void parse(void)
{
	int i, j, k, flag;

    while   (1)
        {
        k = yylex();
        switch(k)   /*  get the token from the input and switch on it   */
            {
            case 'h':   moveplayer(4);  return;     /*  west        */
            case 'H':   run(4);         return;     /*  west        */
            case 'l':   moveplayer(2);  return;     /*  east        */
            case 'L':   run(2);         return;     /*  east        */
            case 'j':   moveplayer(1);  return;     /*  south       */
            case 'J':   run(1);         return;     /*  south       */
            case 'k':   moveplayer(3);  return;     /*  north       */
            case 'K':   run(3);         return;     /*  north       */
            case 'u':   moveplayer(5);  return;     /*  northeast   */
            case 'U':   run(5);         return;     /*  northeast   */
            case 'y':   moveplayer(6);  return;     /*  northwest   */
            case 'Y':   run(6);         return;     /*  northwest   */
            case 'n':   moveplayer(7);  return;     /*  southeast   */
            case 'N':   run(7);         return;     /*  southeast   */
            case 'b':   moveplayer(8);  return;     /*  southwest   */
            case 'B':   run(8);         return;     /*  southwest   */

            case '.':                               /*  stay here       */
                if (yrepcount) 
                    viewflag=1;
                return;

            case 'c':
                yrepcount=0;
                cast();
                return;     /*  cast a spell    */

            case 'd':
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    dropobj();
                return; /*  to drop an object   */

            case 'e':
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    if (!floor_consume( OCOOKIE, "eat" ))
                        consume( OCOOKIE, "eat", showeat );
                return; /*  to eat a fortune cookie */

            case 'g':   
                yrepcount = 0 ;
                cursors();
                lprintf("\nThe stuff you are carrying presently weighs %d pounds",(long)packweight());
                break ;

            case 'i':       /* inventory */
                yrepcount=0;
                nomove=1;
                showstr(FALSE);
                return;

            case 'p':           /* pray at an altar */
                yrepcount = 0;
                    pray_at_altar();
                return;

            case 'q':           /* quaff a potion */
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    if (!floor_consume( OPOTION, "quaff"))
                        consume( OPOTION, "quaff", showquaff );
                return;

            case 'r':
                yrepcount=0;
                if (c[BLINDCOUNT])
                    {
                    cursors();
                    lprcat("\nYou can't read anything when you're blind!");
                    }
                else if (c[TIMESTOP]==0)
                    if (!floor_consume( OSCROLL, "read" ))
                        if (!floor_consume( OBOOK, "read" ))
                            consume( OSCROLL, "read", showread );
                return;     /*  to read a scroll    */

            case 's':
                yrepcount = 0 ;
                    sit_on_throne();
                return ;

            case 't':                       /* Tidy up at fountain */
                yrepcount = 0 ;
                    wash_fountain() ;
                return ;

            case 'v':
                yrepcount=0;
                nomove = 1;
                cursors();
                lprintf("\nLarn, Version %d.%d.%d, Diff=%d",(long)VERSION,(long)SUBVERSION,(long)PATCHLEVEL,(long)c[HARDGAME]);
                if (wizard)
                    lprcat(" Wizard");
                if (cheat) 
                    lprcat(" Cheater");
                return;

            case 'w':                       /*  wield a weapon */
                yrepcount=0;
                wield();
                return;

            case 'A':
                yrepcount = 0;
                    desecrate_altar();
                return;

            case 'C':                       /* Close something */
                yrepcount = 0 ;
                    close_something();
                return;

            case 'D':                       /* Drink at fountain */
                yrepcount = 0 ;
                    drink_fountain() ;
                return ;

            case 'E':               /* Enter a building */
                yrepcount = 0 ;
                    enter() ;
                break ;

            case 'I':              /*  list spells and scrolls */
                yrepcount=0;
                seemagic(0);
                nomove=1;
                return;

            case 'O':               /* Open something */
                yrepcount = 0 ;
                    open_something();
                return;

            case 'P':
                cursors();
                yrepcount = 0;
                nomove = 1;
                if (outstanding_taxes>0)
                    lprintf("\nYou presently owe %d gp in taxes.",(long)outstanding_taxes);
                else
                    lprcat("\nYou do not owe any taxes.");
                return;

            case 'Q':    /*  quit        */
                yrepcount=0;
                quit();
                nomove=1;
                return;

            case 'R' :          /* remove gems from a throne */
                yrepcount = 0 ;
                    remove_gems( );
                return ;

            case 'S':
                /* And do the save.
                 */
                cursors();
                lprintf("\nSaving to `%s' . . . ", savefilename);
                lflush();
                save_mode = 1;
                savegame(savefilename);
                clear();
                lflush();
                wizard=1;
                died(-257); /* doesn't return */
                break;


            case 'T':   yrepcount=0;    cursors();  if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else
                                        if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); }
                        else lprcat("\nYou aren't wearing anything");
                        return;

            case 'W':
                yrepcount=0;
                wear();
                return; /*  wear armor  */

            case 'Z':
                yrepcount=0;
                if (c[LEVEL]>9) 
                    { 
                    oteleport(1);
                    return; 
                    }
                cursors(); 
                lprcat("\nAs yet, you don't have enough experience to use teleportation");
                return; /*  teleport yourself   */

            case ' ':   yrepcount=0;    nomove=1;  return;

            case 'L'-64:  yrepcount=0;  drawscreen();  nomove=1; return;    /*  look        */

#if WIZID
#ifdef EXTRA
            case 'A'-64:    yrepcount=0;    nomove=1; if (wizard) { diag(); return; }  /*   create diagnostic file */
                        return;
#endif
#endif
	    
	    case '<':                       /* Go up stairs or vol shaft */
                yrepcount = 0;
                    up_stairs();
                return ;

            case '>':                       /* Go down stairs or vol shaft*/
                yrepcount = 0 ;
                    down_stairs();
                return ;

            case '?':                       /* give the help screen */
                yrepcount=0;
                help();
                nomove=1;
                return; 

        case ',':                       /* pick up an item */
            yrepcount = 0 ;
            /* pickup, don't identify or prompt for action */
            lookforobject( FALSE, TRUE, FALSE );
        return;

            case ':':                       /* look at object */
                yrepcount = 0 ;
            /* identify, don't pick up or prompt for action */
                    lookforobject( TRUE, FALSE, FALSE );
                nomove = 1;  /* assumes look takes no time */
                return;

        case '/':        /* identify object/monster */
            specify_object();
            nomove = 1 ;
            yrepcount = 0 ;
            return;

        case '^':                       /* identify traps */
                flag = yrepcount = 0;
                cursors();
                lprc('\n');
                for (j=playery-1; j<playery+2; j++)
                    {
                    if (j < 0)
                        j=0;
                    if (j >= MAXY)
                        break;
                    for (i=playerx-1; i<playerx+2; i++)
                        {
                        if (i < 0) 
                            i=0;
                        if (i >= MAXX) 
                            break;
                        switch(item[i][j])
                            {
                            case OTRAPDOOR:     case ODARTRAP:
                            case OTRAPARROW:    case OTELEPORTER:
                            case OPIT:
                                lprcat("\nIts ");
                                lprcat(objectname[item[i][j]]);
                                flag++;
                            };
                        }
                    }
                if (flag==0) 
                    lprcat("\nNo traps are visible");
                return;

#if WIZID
            case '_':   /*  this is the fudge player password for wizard mode*/
                        yrepcount=0;    cursors(); nomove=1;

                        if (getpassword()==0)
                            {
                            scbr(); /* system("stty -echo cbreak"); */ return;
                            }
                        wizard=1;  scbr(); /* system("stty -echo cbreak"); */
                        for (i=0; i<6; i++)  c[i]=70;  iven[0]=iven[1]=0;
                        take(OPROTRING,50);   take(OLANCE,25);  c[WIELD]=1;
                        c[LANCEDEATH]=1;   c[WEAR] = c[SHIELD] = -1;
                        raiseexperience(6000000L);  c[AWARENESS] += 25000;
                        {
                        int i,j;
                        for (i=0; i<MAXY; i++)
                            for (j=0; j<MAXX; j++)  know[j][i]=KNOWALL;
                        for (i=0; i<SPNUM; i++) spelknow[i]=1;
                        for (i=0; i<MAXSCROLL; i++)  scrollname[i][0]=' ';
                        for (i=0; i<MAXPOTION; i++)  potionname[i][0]=' ';
                        }
                        for (i=0; i<MAXSCROLL; i++)
                          if (strlen(scrollname[i])>2) /* no null items */
                            { item[i][0]=OSCROLL; iarg[i][0]=i; }
                        for (i=MAXX-1; i>MAXX-1-MAXPOTION; i--)
                          if (strlen(potionname[i-MAXX+MAXPOTION])>2) /* no null items */
                            { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; }
                        for (i=1; i<MAXY; i++)
                            { item[0][i]=i; iarg[0][i]=0; }
                        for (i=MAXY; i<MAXY+MAXX; i++)
                            { item[i-MAXY][MAXY-1]=i; iarg[i-MAXY][MAXY-1]=0; }
            for (i=MAXX+MAXY; i<MAXOBJECT; i++)
                {
                item[MAXX-1][i-MAXX-MAXY]=i;
                iarg[MAXX-1][i-MAXX-MAXY]=0;
                }
                        c[GOLD]+=250000;    drawscreen();   return;
#endif

            };
        }
}
コード例 #7
0
int main(int argc, char** argv){
   if(argc!=2)
	yyerror("Uso correto: ./pseudosintatico nome_arq_entrada");
   yyin=fopen(argv[1], "r");
   if(!yyin){
	yyerror("arquivo não pode ser aberto\n");
 	exit(1);
   }
   while(1){
	tok=yylex();
	switch(tok){
        case IDENTIFICADOR:
	     printf("Encontrei o identificador %s na linha %d \n", yytext,numLinha);
             break;	
	case '[':
	     printf("Encontrei um [ na linha %d \n", numLinha);
             break;
	case INTCONST:
	     printf("Encontrei um número inteiro: %s na linha %d \n", yytext, numLinha);
	     break;
	case ']':
             printf("Encontrei um ] na linha %d\n", numLinha );
             break;
	case '(':
	     printf("Encontrei um ( na linha %d \n", numLinha);
             break;
	case ')':
	     printf("Encontrei um ) na linha %d \n", numLinha);
             break;
        case LE:
	     printf("Encontrei um  %s na linha %d\n", yytext, numLinha);
             break;
	case PROGRAMA:
	     printf("Encontrei a palavra reservada %s na linha %d \n", yytext, numLinha);
             break;
	case LEIA:
	     printf("Encontrei a palavra reservada %s na linha %d \n", yytext, numLinha);
             break;
	case ENQUANTO:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case TYPE_CAR:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case TYPE_INT:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case RETURN:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case ESCREVA:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case NOVALINHA:
             printf("Encontrei uma quebra de linha na linha %d\n", numLinha);
             break;
	case SE:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case ENTAO:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case SENAO:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case EXECUTE:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case CONST_STRING:
             printf("Encontrei a cadeia de caracteres \"%s\" na linha %d\n", yytext, numLinha);
             break;
	case ASSIGN:
             printf("Encontrei um = na linha %d\n", numLinha);
             break;
	case '{':
             printf("Encontrei um { na linha %d\n", numLinha);
             break;
	case '}':
             printf("Encontrei um } na linha %d\n", numLinha);
             break;
	case '+':
             printf("Encontrei um + na linha %d\n", numLinha);
             break;
	case '-':
             printf("Encontrei um - na linha %d\n", numLinha);
             break;
	case '*':
             printf("Encontrei um * na linha %d\n", numLinha);
             break;
	case '/':
             printf("Encontrei um / na linha %d\n", numLinha);
             break;
	case GE:
             printf("Encontrei um >= na linha %d\n", numLinha);
             break;
	case EQ:
             printf("Encontrei um == na linha %d\n", numLinha);
             break;
	case DIFF:
             printf("Encontrei um != na linha %d\n", numLinha);
             break;
	case OR:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case AND:
             printf("Encontrei a palavra reservada %s na linha %d\n", yytext, numLinha);
             break;
	case EOF: exit(1);
	}
   }

}
コード例 #8
0
ファイル: parser.c プロジェクト: spicyjack/Atari-8bit
 /*=========================================================================*/
int yyparse() {
  int yystate;
  int yyn;
  short *yyssp;
  int  *yyvsp;
  int yyerrstatus;
  int yychar1 = 0;

  short	yyssa[200];
  int  yyvsa[200];

  short *yyss = yyssa;
  int  *yyvs = yyvsa;
  int yystacksize = 200 ;

  int  yyval = 0;  /* remove annoying warning */
  int yylen;

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = -2 ;
  yyssp = yyss - 1;
  yyvsp = yyvs;

 yynewstate:

  *++yyssp = yystate;

  if (yyssp>=yyss+yystacksize-1) {
    error("Parser stack overflow",1);
  }

  yyn = yypact[yystate];
  if (yyn == -32768 )
    goto yydefault;

  if (yychar == -2 ) {
    yychar = yylex() ;
  }

  if (yychar <= 0) {
    yychar1 = 0;
    yychar = 0 ;
  } else {
    yychar1 = ((unsigned)( yychar ) <= 257 ? yytranslate[ yychar ] : 27) ;
  }

  yyn += yychar1;
  if (yyn < 0 || yyn > 107  || yycheck[yyn] != yychar1)
    goto yydefault;

  yyn = yytable[yyn];

  if (yyn < 0) {
    if (yyn == -32768 )
      goto yyerrlab;
    yyn = -yyn;
    goto yyreduce;
  }
  else if (yyn == 0)
    goto yyerrlab;

  if (yyn == 46 )
    return(0) ;

  if (yychar != 0 )
    yychar = -2 ;

  *++yyvsp = yylval;

  if (yyerrstatus) yyerrstatus--;

  yystate = yyn;
  goto yynewstate;


 yydefault:

  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;


 yyreduce:
  yylen = yyr2[yyn];
  if (yylen > 0)
    yyval = yyvsp[1-yylen];

  switch (yyn) {
  case 1:
    rval=yyvsp[0];
    break;
  case 2:
    yyval=nums[vnum++];
    break;
  case 3:
    yyval=!yyvsp[0];
    break;
  case 4:
    yyval=(yyvsp[0])&0xff;
    break;
  case 5:
    yyval=((yyvsp[0])>>8)&0xff;
    break;
  case 6:
    yyval=-(yyvsp[0]);
    break;
  case 7:
    yyval=yyvsp[-2]|yyvsp[0];
    break;
  case 8:
    yyval=yyvsp[-2]&yyvsp[0];
    break;
  case 9:
    yyval=yyvsp[-2]^yyvsp[0];
    break;
  case 10:
    yyval=yyvsp[-2]+yyvsp[0];
    break;
  case 11:
    yyval=yyvsp[-2]-yyvsp[0];
    break;
  case 12:
    yyval=yyvsp[-2]*yyvsp[0];
    break;
  case 13:
    yyval=yyvsp[-2]/yyvsp[0];
    break;
  case 14:
    yyval=(yyvsp[-2]<yyvsp[0]);
    break;
  case 15:
    yyval=(yyvsp[-2]>yyvsp[0]);
    break;
  case 16:
    yyval=(yyvsp[-2]<=yyvsp[0]);
    break;
  case 17:
    yyval=(yyvsp[-2]>=yyvsp[0]);
    break;
  case 18:
    yyval=(yyvsp[-2]==yyvsp[0]);
    break;
  case 19:
    yyval=(yyvsp[-2]!=yyvsp[0]);
    break;
  case 20:
    yyval=(yyvsp[-2]&&yyvsp[0]);
    break;
  case 21:
    yyval=(yyvsp[-2]||yyvsp[0]);
    break;
  case 22:
    yyval=yyvsp[-1];
    break;
  }

  yyvsp -= yylen;
  yyssp -= yylen;
  *++yyvsp = yyval;

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - 25 ] + *yyssp;
  if (yystate >= 0 && yystate <= 107  && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - 25 ];

  goto yynewstate;

 yyerrlab:
  if (!yyerrstatus) {
    ++yynerrs;
    error("Error parsing expression",1);
  }

  if (yyerrstatus == 3) {
    if (yychar == 0 )
      return(1) ;
    yychar = -2 ;
  }

  yyerrstatus = 3;

  goto yyerrhandle;

 yyerrdefault:
 yyerrpop:
  if (yyssp == yyss)
    return 1;

  yyvsp--;
  yystate = *--yyssp;

 yyerrhandle:
  yyn = yypact[yystate];
  if (yyn == -32768 )
    goto yyerrdefault;

  yyn+=1;
  if (yyn < 0 || yyn > 107  || yycheck[yyn] != 1 )
    goto yyerrdefault;

  yyn = yytable[yyn];
  if (yyn < 0) {
    if (yyn == -32768 )
      goto yyerrpop;
    yyn = -yyn;
    goto yyreduce;
  } else if (yyn == 0)
    goto yyerrpop;

  if (yyn == 46 )
    return(0) ;

  *++yyvsp = yylval;
  yystate = yyn;
  goto yynewstate;
}
コード例 #9
0
ファイル: rsg_generator.c プロジェクト: Abhishekh-TEL/pdroid
int main(int argc, char **argv)
{
    if (argc != 3) {
        fprintf(stderr, "usage: %s commandFile outFile\n", argv[0]);
        return 1;
    }
    const char* rsgFile = argv[1];
    const char* outFile = argv[2];
    FILE* input = fopen(rsgFile, "r");

    char choice = fgetc(input);
    fclose(input);

    if (choice < '0' || choice > '3') {
        fprintf(stderr, "Uknown command: \'%c\'\n", choice);
        return -2;
    }

    yylex();
    // printf("# of lines = %d\n", num_lines);

    FILE *f = fopen(outFile, "w");

    printFileHeader(f);
    switch(choice) {
        case '0': // rsgApiStructs.h
        {
            fprintf(f, "\n");
            fprintf(f, "#include \"rsContext.h\"\n");
            fprintf(f, "\n");
            fprintf(f, "namespace android {\n");
            fprintf(f, "namespace renderscript {\n");
            printStructures(f);
            printFuncDecls(f, "rsi_", 1);
            printPlaybackFuncs(f, "rsp_");
            fprintf(f, "\n\ntypedef void (*RsPlaybackFunc)(Context *, const void *);\n");
            fprintf(f, "extern RsPlaybackFunc gPlaybackFuncs[];\n");

            fprintf(f, "}\n");
            fprintf(f, "}\n");
        }
        break;

        case '1': // rsgApiFuncDecl.h
        {
            printFuncDecls(f, "rs", 0);
        }
        break;

        case '2': // rsgApi.cpp
        {
            printApiCpp(f);
        }
        break;

        case '3': // rsgApiReplay.cpp
        {
            printFileHeader(f);
            printPlaybackCpp(f);
        }
        break;
    }
    fclose(f);
    return 0;
}
コード例 #10
0
ファイル: scanner.hpp プロジェクト: WhosTheMark/emerald
   int yylex(yy::Parser::semantic_type *lval, yy::Parser::location_type *loc) {

      yylval = lval;
      yylloc = loc;
      return yylex();
   }
コード例 #11
0
ファイル: main.c プロジェクト: ajinkya93/netbsd-src
/*
	parse()

	get and execute a command
 */
static void
parse(void)
{
	int    i, j, k, flag;
	while (1) {
		k = yylex();
		switch (k) {	/* get the token from the input and switch on
				 * it	 */
		case 'h':
			moveplayer(4);
			return;	/* west		 */
		case 'H':
			run(4);
			return;	/* west		 */
		case 'l':
			moveplayer(2);
			return;	/* east		 */
		case 'L':
			run(2);
			return;	/* east		 */
		case 'j':
			moveplayer(1);
			return;	/* south		 */
		case 'J':
			run(1);
			return;	/* south		 */
		case 'k':
			moveplayer(3);
			return;	/* north		 */
		case 'K':
			run(3);
			return;	/* north		 */
		case 'u':
			moveplayer(5);
			return;	/* northeast	 */
		case 'U':
			run(5);
			return;	/* northeast	 */
		case 'y':
			moveplayer(6);
			return;	/* northwest	 */
		case 'Y':
			run(6);
			return;	/* northwest	 */
		case 'n':
			moveplayer(7);
			return;	/* southeast	 */
		case 'N':
			run(7);
			return;	/* southeast	 */
		case 'b':
			moveplayer(8);
			return;	/* southwest	 */
		case 'B':
			run(8);
			return;	/* southwest	 */

		case '.':
			if (yrepcount)
				viewflag = 1;
			return;	/* stay here		 */

		case 'w':
			yrepcount = 0;
			wield();
			return;	/* wield a weapon */

		case 'W':
			yrepcount = 0;
			wear();
			return;	/* wear armor	 */

		case 'r':
			yrepcount = 0;
			if (c[BLINDCOUNT]) {
				cursors();
				lprcat("\nYou can't read anything when you're blind!");
			} else if (c[TIMESTOP] == 0)
				readscr();
			return;	/* to read a scroll	 */

		case 'q':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				quaff();
			return;	/* quaff a potion		 */

		case 'd':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				dropobj();
			return;	/* to drop an object	 */

		case 'c':
			yrepcount = 0;
			cast();
			return;	/* cast a spell	 */

		case 'i':
			yrepcount = 0;
			nomove = 1;
			showstr();
			return;	/* status		 */

		case 'e':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				eatcookie();
			return;	/* to eat a fortune cookie */

		case 'D':
			yrepcount = 0;
			seemagic(0);
			nomove = 1;
			return;	/* list spells and scrolls */

		case '?':
			yrepcount = 0;
			help();
			nomove = 1;
			return;	/* give the help screen */

		case 'S':
			clear();
			lprcat("Saving . . .");
			lflush();
			savegame(savefilename);
			wizard = 1;
			died(-257);	/* save the game - doesn't return	 */

		case 'Z':
			yrepcount = 0;
			if (c[LEVEL] > 9) {
				oteleport(1);
				return;
			}
			cursors();
			lprcat("\nAs yet, you don't have enough experience to use teleportation");
			return;	/* teleport yourself	 */

		case '^':	/* identify traps */
			flag = yrepcount = 0;
			cursors();
			lprc('\n');
			for (j = playery - 1; j < playery + 2; j++) {
				if (j < 0)
					j = 0;
				if (j >= MAXY)
					break;
				for (i = playerx - 1; i < playerx + 2; i++) {
					if (i < 0)
						i = 0;
					if (i >= MAXX)
						break;
					switch (item[i][j]) {
					case OTRAPDOOR:
					case ODARTRAP:
					case OTRAPARROW:
					case OTELEPORTER:
						lprcat("\nIt's ");
						lprcat(objectname[item[i][j]]);
						flag++;
					};
				}
			}
			if (flag == 0)
				lprcat("\nNo traps are visible");
			return;

#if WIZID
		case '_':	/* this is the fudge player password for
				 * wizard mode */
			yrepcount = 0;
			cursors();
			nomove = 1;
			if (userid != wisid) {
				lprcat("Sorry, you are not empowered to be a wizard.\n");
				scbr();	/* system("stty -echo cbreak"); */
				lflush();
				return;
			}
			if (getpassword() == 0) {
				scbr();	/* system("stty -echo cbreak"); */
				return;
			}
			wizard = 1;
			scbr();	/* system("stty -echo cbreak"); */
			for (i = 0; i < 6; i++)
				c[i] = 70;
			iven[0] = iven[1] = 0;
			take(OPROTRING, 50);
			take(OLANCE, 25);
			c[WIELD] = 1;
			c[LANCEDEATH] = 1;
			c[WEAR] = c[SHIELD] = -1;
			raiseexperience(6000000L);
			c[AWARENESS] += 25000;
			{
				int    i, j;
				for (i = 0; i < MAXY; i++)
					for (j = 0; j < MAXX; j++)
						know[j][i] = 1;
				for (i = 0; i < SPNUM; i++)
					spelknow[i] = 1;
				for (i = 0; i < MAXSCROLL; i++)
					scrollname[i] = scrollhide[i];
				for (i = 0; i < MAXPOTION; i++)
					potionname[i] = potionhide[i];
			}
			for (i = 0; i < MAXSCROLL; i++)
				if (strlen(scrollname[i]) > 2) {	/* no null items */
					item[i][0] = OSCROLL;
					iarg[i][0] = i;
				}
			for (i = MAXX - 1; i > MAXX - 1 - MAXPOTION; i--)
				if (strlen(potionname[i - MAXX + MAXPOTION]) > 2) {	/* no null items */
					item[i][0] = OPOTION;
					iarg[i][0] = i - MAXX + MAXPOTION;
				}
			for (i = 1; i < MAXY; i++) {
				item[0][i] = i;
				iarg[0][i] = 0;
			}
			for (i = MAXY; i < MAXY + MAXX; i++) {
				item[i - MAXY][MAXY - 1] = i;
				iarg[i - MAXY][MAXY - 1] = 0;
			}
			for (i = MAXX + MAXY; i < MAXX + MAXY + MAXY; i++) {
				item[MAXX - 1][i - MAXX - MAXY] = i;
				iarg[MAXX - 1][i - MAXX - MAXY] = 0;
			}
			c[GOLD] += 25000;
			drawscreen();
			return;
#endif

		case 'T':
			yrepcount = 0;
			cursors();
			if (c[SHIELD] != -1) {
				c[SHIELD] = -1;
				lprcat("\nYour shield is off");
				bottomline();
			} else if (c[WEAR] != -1) {
				c[WEAR] = -1;
				lprcat("\nYour armor is off");
				bottomline();
			} else
				lprcat("\nYou aren't wearing anything");
			return;

		case 'g':
			cursors();
			lprintf("\nThe stuff you are carrying presently weighs %ld pounds", (long) packweight());
		case ' ':
			yrepcount = 0;
			nomove = 1;
			return;

		case 'v':
			yrepcount = 0;
			cursors();
			lprintf("\nCaverns of Larn, Version %ld.%ld, Diff=%ld",
				(long) VERSION, (long) SUBVERSION,
				(long) c[HARDGAME]);
			if (wizard)
				lprcat(" Wizard");
			nomove = 1;
			if (cheat)
				lprcat(" Cheater");
			lprcat(copyright);
			return;

		case 'Q':
			yrepcount = 0;
			quit();
			nomove = 1;
			return;	/* quit		 */

		case 'L' - 64:
			yrepcount = 0;
			drawscreen();
			nomove = 1;
			return;	/* look		 */

#if WIZID
#ifdef EXTRA
		case 'A':
			yrepcount = 0;
			nomove = 1;
			if (wizard) {
				diag();
				return;
			}	/* create diagnostic file */
			return;
#endif
#endif
		case 'P':
			cursors();
			if (outstanding_taxes > 0)
				lprintf("\nYou presently owe %ld gp in taxes.",
					(long) outstanding_taxes);
			else
				lprcat("\nYou do not owe any taxes.");
			return;
		};
	}
}
コード例 #12
0
ファイル: d3.c プロジェクト: 37dmk/AutoSpr
int	main(int argc, char *argv[]) {
	while (!feof(stdin)) {
		yylex();
	}
	return EXIT_SUCCESS;
}
コード例 #13
0
/*
* Main
*/
int main(int argc, char **argv)
{
  extern FILE *yyin;
  extern int yylex();

  FILE *cfp = NULL;
  FILE *hfp = NULL;


  if (argc != 4) {
      printf("Usage: co_msg2cmsg msg-file c_msg-file h_file\n");
      exit(2);
  }

  if (!(yyin = fopen(argv[1], "r"))) {
      printf("Can't open input file: %s\n", argv[1]);
      exit(2);
  }

  if (!(cfp = fopen(argv[2], "w"))) {
      printf("Can't open c_msg-output file: %s\n", argv[2]);
      fclose(yyin);
      exit(2);
  }

  if (!(hfp = fopen(argv[3], "w"))) {
      printf("Can't open h-output file: %s\n", argv[3]);
      fclose(yyin);
      fclose(cfp);
      exit(2);
  }


  LstIni(&lFacH);
  SyntaxError = 0;
  lineno = 1;
  yylex();

  if (!SyntaxError) {
    char fname[256];
    char *p;

#if defined OS_VMS || defined OS_ELN
    p = strpbrk(argv[2], "]>");
    if (!p)
      p = strchr(argv[2], ':');
    else {
      char *p2;
      while(p2 = strpbrk(p + 1, "]>"))
	p = p2;
    }
    if (p)
      for (i = 0; p[i+1]; i++)
	fname[i] = tolower(p[i+1]);
    else
      for (i = 0; argv[2][i]; i++)
	fname[i] = tolower(argv[2][i]);
    fname[i] = '\0';
#else
    if ((p = strrchr(argv[2], '/')))
      strcpy(fname, p+1);
    else
      strcpy(fname, argv[2]);
    
#endif

    if ((p = strchr(fname, '.')))
      *p = '\0';

    WriteFiles(fname, cfp, hfp);
  }

  fclose(yyin);
  fclose(cfp);
  fclose(hfp);

#if defined OS_VMS || defined OS_ELN
  exit(1);
#elif defined OS_LYNX || defined OS_LINUX
  exit(EXIT_SUCCESS);
#endif
}
コード例 #14
0
ファイル: fb_parser_for_eh.cpp プロジェクト: acplt/rte
int
yyparse()
{
    register int yystate;
    register int yyn;
    register short *yyssp;
    register YYSTYPE *yyvsp;
    int yyerrstatus;        
    int yychar1 = 0;                

    short        yyssa[200];        
    YYSTYPE yyvsa[200];        

    short *yyss = yyssa;                
    YYSTYPE *yyvs = yyvsa;        

    int yystacksize = 200;

    YYSTYPE yyval;                
    int yylen;

    yystate = 0;
    yyerrstatus = 0;
    yynerrs = 0;
    yychar = -2;                

    yyssp = yyss - 1;
    yyvsp = yyvs;

yynewstate:

    *++yyssp = yystate;

    if (yyssp >= yyss + yystacksize - 1)
    {

        YYSTYPE *yyvs1 = yyvs;
        short *yyss1 = yyss;
        int size = yyssp - yyss + 1;
        
        if (yystacksize >= 10000)
        {
            yyerror("parser stack overflow");
            return 2;
        }
        yystacksize *= 2;
        if (yystacksize > 10000)
            yystacksize = 10000;
        yyss = (short *) malloc (yystacksize * sizeof (*yyssp));
        __yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
        yyvs = (YYSTYPE *) malloc (yystacksize * sizeof (*yyvsp));
        __yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));

        yyssp = yyss + size - 1;
        yyvsp = yyvs + size - 1;

        if (yyssp >= yyss + yystacksize - 1)
            return(1);
    }

    goto yybackup;

yybackup:
    yyn = yypact[yystate];
    if (yyn == -32768)
        goto yydefault;

    if (yychar == -2)
    {
        yychar = yylex();
    }



    if (yychar <= 0)                
    {
        yychar1 = 0;
        yychar = 0;                
    }
    else
    {
        yychar1 = ((unsigned)(yychar) <= 290 ? yytranslate[yychar] : 74);
    }

    yyn += yychar1;
    if (yyn < 0 || yyn > 181 || yycheck[yyn] != yychar1)
        goto yydefault;

    yyn = yytable[yyn];

    if (yyn < 0)
    {
        if (yyn == -32768)
            goto yyerrlab;
        yyn = -yyn;
        goto yyreduce;
    }
    else if (yyn == 0)
        goto yyerrlab;

    if (yyn == 149)
        return(0);

    if (yychar != 0)
        yychar = -2;

    *++yyvsp = yylval;

    if (yyerrstatus) yyerrstatus--;

    yystate = yyn;
    goto yynewstate;


yydefault:

    yyn = yydefact[yystate];
    if (yyn == 0)
        goto yyerrlab;


yyreduce:
    yylen = yyr2[yyn];
    if (yylen > 0)
        yyval = yyvsp[1-yylen]; 

    switch (yyn) {

        case 1:
        {
            break;
        }
        case 2:
        {
            break;
        }
        case 3:
        {
            yyval.par = yyvsp[0].par;
            break;
        }
        case 4:
        {
            yyval.par = yyvsp[0].par;
            break;
        }
        case 5:
        {
            InstanceItems* pII;

            if (ppar->Instance) {

                pII = ppar->Instance;
                while(pII->next) {
                    pII=pII->next;
                }
                pII->next = yyvsp[0].instans;

            } else {

                ppar->Instance = yyvsp[0].instans;
            }
            yyval.par = ppar;
            break;}
        case 6:
        {
            LinksItems* pLI;

            if(ppar->Links) {

                pLI = ppar->Links;
                while(pLI->next) {
                    pLI=pLI->next;
                }
                pLI->next = yyvsp[0].link;
            } else {

                ppar->Links = yyvsp[0].link;
            }
            yyval.par = ppar;
            break;}
        case 7:
        {
            LinksItems* pLI;

            if(ppar->UnLinks) {

                pLI=ppar->UnLinks;
                while(pLI->next) {
                    pLI=pLI->next;
                }
                pLI->next = yyvsp[0].link;
            } else {
                ppar->UnLinks = yyvsp[0].link;
            }
            yyval.par = ppar;
            break;}
        case 8:
        {
            DelInstItems* pDI;

            if(ppar->DelInst) {
                pDI=ppar->DelInst;
                while(pDI->next) {
                    pDI=pDI->next;
                }
                pDI->next = yyvsp[0].delinstans;
            } else {
                ppar->DelInst = yyvsp[0].delinstans;
            }
            yyval.par = ppar;
            break;}
        case 9:
        {
            DelInstItems* pDI;
            if(ppar->NewLibs) {
                pDI=ppar->NewLibs;
                while(pDI->next) {
                    pDI=pDI->next;
                }
                pDI->next = yyvsp[0].delinstans;
            } else {
                ppar->NewLibs = yyvsp[0].delinstans;
            }
            yyval.par = ppar;
            break;}
        case 10:
        {
            DelInstItems* pDI;
            if(ppar->OldLibs) {
                pDI=ppar->OldLibs;
                while(pDI->next) {
                    pDI=pDI->next;
                }
                pDI->next = yyvsp[0].delinstans;
            } else {
                ppar->OldLibs = yyvsp[0].delinstans;
            }
            yyval.par = ppar;
            break;}
        case 11:
        {
            SetInstVarItems* pSI;
            if (ppar->Set_Inst_Var) {
                pSI=ppar->Set_Inst_Var;
                while(pSI->next) {
                    pSI=pSI->next;
                }
                pSI->next = yyvsp[0].setinstvar;
            } else {
                ppar->Set_Inst_Var = yyvsp[0].setinstvar;
            }
            yyval.par = ppar;
            break;}
        case 12:
        {
            yyval.instans = yyvsp[0].instans;
            break;}
        case 13:
        {
            InstanceItems *pInstList = yyvsp[-1].instans;

            while( pInstList->next) {
                pInstList = pInstList->next;
            }
            pInstList->next = yyvsp[0].instans;
            yyval.instans = yyvsp[-1].instans;
            break;}
        case 14:
        {
            Variables      *pVar;
            InstanceItems  *pinst = (InstanceItems*)malloc(sizeof(InstanceItems));

            if( (!yyvsp[-7].string) || (!yyvsp[-4].string) || (!pinst) ) {
                if(pinst) free(pinst);
                pVar = yyvsp[-2].variable;
                while(pVar) {
                    yyvsp[-2].variable = pVar->next;
                    if(pVar->value) {
                        VariableItem *pVal = pVar->value;
                        while(pVal) {
                            pVar->value = pVar->value->next;
                            free(pVal);
                            pVal = pVar->value;
                        }
                    }
                    free(pVar);
                    pVar = yyvsp[-2].variable;
                }
                yyerror("out of memory");
                return 1;
            }
            pinst->next = 0;
            pinst->Inst_name = yyvsp[-7].string;
            pinst->Class_name = yyvsp[-4].string;
            pinst->Inst_var = yyvsp[-2].variable;

            yyval.instans = pinst;
            break;}
        case 15:
        {
            yyval.link = yyvsp[0].link;
            break;}
        case 16:
        {
            LinksItems *pLinkList = yyvsp[-1].link;

            while ( pLinkList->next)
                pLinkList = pLinkList->next;
            pLinkList->next = yyvsp[0].link;
            yyval.link = yyvsp[-1].link;
            break;}
        case 17:
        {
            LinksItems*                 plink;
            Child*              pchild;

            plink = (LinksItems*)malloc(sizeof(LinksItems));
            if( (!plink) || (!yyvsp[-13].string) || (!yyvsp[-10].string) || (!yyvsp[-4].ch_path) ) {
                if(plink) free(plink);
                pchild = yyvsp[-4].ch_path;
                while(pchild) {
                    yyvsp[-4].ch_path = pchild->next;
                    free(pchild);
                    pchild = yyvsp[-4].ch_path;
                }
                yyerror("out of memory");
                return 1;
            }
            plink->next = 0;
            plink->parent_path = yyvsp[-13].string;
            plink->child_role = yyvsp[-10].string;
            plink->children = yyvsp[-4].ch_path;

            yyval.link = plink;
            break;}
        case 18:
        {
            yyval.link = yyvsp[0].link;
            break;}
        case 19:
        {
            LinksItems *pLinkList = yyvsp[-1].link;

            while ( pLinkList->next) {
                pLinkList = pLinkList->next;
            }
            pLinkList->next = yyvsp[0].link;
            yyval.link = yyvsp[-1].link;
            break;}
        case 20:
        {
            LinksItems*                 plink;
            Child*              pchild;

            plink = (LinksItems*)malloc(sizeof(LinksItems));
            if( (!plink) || (!yyvsp[-13].string) || (!yyvsp[-10].string) || (!yyvsp[-4].ch_path) ) {
                if(plink) free(plink);
                pchild = yyvsp[-4].ch_path;
                while(pchild) {
                    yyvsp[-4].ch_path = pchild->next;
                    free(pchild);
                    pchild = yyvsp[-4].ch_path;
                }
                yyerror("out of memory");
                return 1;
            }
            plink->next = 0;
            plink->parent_path = yyvsp[-13].string;
            plink->child_role = yyvsp[-10].string;
            plink->children = yyvsp[-4].ch_path;

            yyval.link=plink;
            break;}
        case 21:
        {
            yyval.ch_path = yyvsp[0].ch_path;
            break;}
        case 22:
        {
            Child* pchild;
            pchild = yyvsp[-2].ch_path;

            while(pchild->next) {
                pchild = pchild->next;
            }
            pchild->next = yyvsp[0].ch_path;
            yyval.ch_path = yyvsp[-2].ch_path;
            break;}
        case 23:
        {
            Child* pchild;
            if(!yyvsp[0].string) {
                yyerror("out of memory");
                return 1;
            }
            pchild = (Child*)malloc(sizeof(Child));
            if(!pchild) {
                yyerror("out of memory");
                return 1;
            }
            pchild->next = 0;
            pchild->child_path = yyvsp[0].string;
            yyval.ch_path = pchild;
            break;}
        case 24:
        {
            yyval.delinstans = yyvsp[0].delinstans;
            break;}
        case 25:
        {
            DelInstItems* pdelinst;
            pdelinst = yyvsp[-1].delinstans;
            while ( pdelinst->next) {
                pdelinst = pdelinst->next;
            }
            pdelinst->next = yyvsp[0].delinstans;
            yyval.delinstans = yyvsp[-1].delinstans;
            break;}
        case 26:
        {
            DelInstItems *pd = (DelInstItems*)malloc(sizeof(DelInstItems));
            if((!pd) || (!yyvsp[-2].string)) {
                if(pd) free(pd);
                yyerror("out of memory");
                return 1;
            }
            pd->next = 0;
            pd->Inst_name = yyvsp[-2].string;

            yyval.delinstans = pd;
            break;}
        case 27:
        {
            yyval.delinstans = yyvsp[0].delinstans;
            break;}
        case 28:
        {
            DelInstItems* pdelinst;
            pdelinst = yyvsp[-1].delinstans;

            while ( pdelinst->next) {
                pdelinst = pdelinst->next;
            }
            pdelinst->next = yyvsp[0].delinstans;
            yyval.delinstans = yyvsp[-1].delinstans;
            break;}
        case 29:
        {
            DelInstItems* pd = (DelInstItems*)malloc(sizeof(DelInstItems));
            if( (!pd) || (!yyvsp[-2].string) ) {
                if(pd) free(pd);
                yyerror("out of memory");
                return 1;
            }
            pd->next = 0;
            pd->Inst_name = yyvsp[-2].string;

            yyval.delinstans = pd;
            break;}
        case 30:
        {
            yyval.delinstans = yyvsp[0].delinstans;
            break;}
        case 31:
        {
            DelInstItems* pdelinst;
            pdelinst = yyvsp[-1].delinstans;

            while ( pdelinst->next) {
                pdelinst = pdelinst->next;
            }
            pdelinst->next = yyvsp[0].delinstans;
            yyval.delinstans = yyvsp[-1].delinstans;
            break;}
        case 32:
        {
            DelInstItems *pd = (DelInstItems*)malloc(sizeof(DelInstItems));
            if( (!pd) || (!yyvsp[-2].string) ) {
                if(pd) free(pd);
                yyerror("out of memory");
                return 1;
            }
            pd->next = 0;
            pd->Inst_name = yyvsp[-2].string;

            yyval.delinstans = pd;
            break;}
        case 33:
        {
            yyval.setinstvar = yyvsp[0].setinstvar;
            break;}
        case 34:
        {
            SetInstVarItems* psiv;
            psiv = yyvsp[-1].setinstvar;

            while ( psiv->next) {
                psiv = psiv->next;
            }
            psiv->next = yyvsp[0].setinstvar;
            yyval.setinstvar = yyvsp[-1].setinstvar;
            break;}
        case 35:
        {
            Variables       *pVar;
            SetInstVarItems *ps = (SetInstVarItems*)malloc(sizeof(SetInstVarItems));
            if( (!ps) || (!yyvsp[-4].string) ) {
                if(ps) free(ps);
                pVar = yyvsp[-2].variable;
                while(pVar) {
                    yyvsp[-2].variable = pVar->next;
                    if(pVar->value) {
                        VariableItem *pVal = pVar->value;
                        while(pVal) {
                            pVar->value = pVar->value->next;
                            free(pVal);
                            pVal = pVar->value;
                        }
                    }
                    free(pVar);
                    pVar = yyvsp[-2].variable;
                }
                yyerror("out of memory");
                return 1;
            }
            ps->next = 0;
            ps->Inst_name = yyvsp[-4].string;
            ps->Inst_var = yyvsp[-2].variable;

            yyval.setinstvar=ps;
            ps = 0;
            break;}
        case 36:
        {
            yyval.variable = 0;
            break;}
        case 37:
        {
            yyval.variable = yyvsp[-2].variable;
            break;}
        case 38:
        {
            yyval.variable = 0;
            break;}
        case 39:
        {
            yyval.variable = yyvsp[0].variable;
            break;}
        case 40:
        {
            yyval.variable = yyvsp[0].variable;
            break;}
        case 41:
        {
            Variables* pVarList = yyvsp[-1].variable;

            if(pVarList) {

                while ( pVarList->next)
                    pVarList = pVarList->next;
                pVarList->next = yyvsp[0].variable;
                yyval.variable=yyvsp[-1].variable;
            } else {

                yyval.variable = yyvsp[0].variable;
            }
            break;}
        case 42:
        {
            yyval.variable = yyvsp[0].variable;
            break;}
        case 43:
        {
            yyval.variable = yyvsp[0].variable;
            break;}
        case 44:
        {
            Variables*                 pvar;

            if(yyvsp[-5].pt) {

                pvar = (Variables*)malloc(sizeof(Variables));
                if( (!pvar) || (!yyvsp[-7].string) ) {
                    if(pvar) free(pvar);
                    free(yyvsp[-2].var_item);
                    yyerror("out of memory");
                    return 1;
                }
                pvar->next = 0;
                pvar->var_name = yyvsp[-7].string;
                pvar->len = 1;
                pvar->value = yyvsp[-2].var_item;
                pvar->port_typ = yyvsp[-5].pt;
                pvar->var_typ = yyvsp[-4].datatype;
                if(yyvsp[-1].string) {
                    pvar->state =  (int)((int) atol(yyvsp[-1].string));
                } else {
                    pvar->state = 0;
                }
                pvar->vector = 0;

                switch(yyvsp[-4].datatype) {        
                case ((KS_VAR_TYPE)0x02):
                    if(pvar->value->value_type != DT_BOOLIAN) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                case ((KS_VAR_TYPE)0x10):
                    if(pvar->value->value_type != DT_GANZZAHL) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                case ((KS_VAR_TYPE)0x11):
                    if(pvar->value->value_type != DT_GANZZAHL) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                case ((KS_VAR_TYPE)0x20):
                    if( (pvar->value->value_type != DT_FLIESSCOMMA) &&
                        (pvar->value->value_type != DT_GANZZAHL) ) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                case ((KS_VAR_TYPE)0x21):
                    if( (pvar->value->value_type != DT_FLIESSCOMMA) &&
                        (pvar->value->value_type != DT_GANZZAHL) ) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                case ((KS_VAR_TYPE)0x31):
                    if(pvar->value->value_type != DT_TIMESTRUCT) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                case ((KS_VAR_TYPE)0x32):
                    if(pvar->value->value_type != DT_FLIESSCOMMA) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                case ((KS_VAR_TYPE)0x30):
                    if(pvar->value->value_type != DT_ZEICHEN) {
                        yyerror("Bad variable type");
                        return 1;
                    }
                    break;
                default:
                    yyerror("Unknown variable type");
                    return 1;
                }

                pvar->value->value_type = (DataType)yyvsp[-4].datatype;

                yyval.variable = pvar;

            } else {

                free(yyvsp[-2].var_item);
                yyval.variable = 0;
            }
            break;}
        case 45:
        {
            yyval.string = 0;
            break;}
        case 46:
        {
            if(!yyvsp[0].string) {
                yyerror("out of memory");
                return 1;
            }
            yyval.string = yyvsp[0].string;
            break;}
        case 47:
        {
            Variables*                 pvar;
            VariableItem*         pvar_item;
            int             count;

            if(yyvsp[-4].pt) {

                pvar = (Variables*)malloc(sizeof(Variables));
                if(( !pvar) || (!yyvsp[-9].string) || (!yyvsp[-7].string) ) {
                    if(pvar) free(pvar);
                    pvar_item = yyvsp[-1].var_item;
                    while(pvar_item) {
                        yyvsp[-1].var_item = pvar_item->next;
                        free(pvar_item);
                        pvar_item = yyvsp[-1].var_item;
                    }
                    yyerror("out of memory");
                    return 1;
                }

                count = (int)((int) atol(yyvsp[-7].string));

                pvar->next = 0;
                pvar->var_name = yyvsp[-9].string;
                pvar->len = count;
                pvar->value = yyvsp[-1].var_item;
                pvar->port_typ = yyvsp[-4].pt;
                pvar->var_typ = yyvsp[-3].datatype;
                pvar->state = 0;
                pvar->vector = 1;


                if(pvar->value) {
                    count = 0;
                    pvar_item = pvar->value;

                    while(pvar_item) {
                        switch(pvar->var_typ) {        
                        case ((KS_VAR_TYPE)0x02):
                            if(pvar_item->value_type != DT_BOOLIAN) {
                                yyerror("Bad variable type");
                                return 1;
                            }
                            break;
                        case ((KS_VAR_TYPE)0x10):
                            if(pvar_item->value_type != DT_GANZZAHL) {
                                yyerror("Bad variable type");
                                return 1;
                            }
                            break;
                        case ((KS_VAR_TYPE)0x20):
                            if( (pvar_item->value_type != DT_FLIESSCOMMA) &&
                                (pvar->value->value_type != DT_GANZZAHL) ) {
                                yyerror("Bad variable type");
                                return 1;
                            }
                            break;
                        case ((KS_VAR_TYPE)0x21):
                            if( (pvar_item->value_type != DT_FLIESSCOMMA) &&
                                (pvar->value->value_type != DT_GANZZAHL) ) {
                                yyerror("Bad variable type");
                                return 1;
                            }
                            break;
                        case ((KS_VAR_TYPE)0x31):
                            if(pvar_item->value_type != DT_TIMESTRUCT) {
                                yyerror("Bad variable type");
                                return 1;
                            }
                            break;
                        case ((KS_VAR_TYPE)0x32):
                            if(pvar_item->value_type != DT_FLIESSCOMMA) {
                                yyerror("Bad variable type");
                                return 1;
                            }
                        break;
                        case ((KS_VAR_TYPE)0x30):
                            if(pvar_item->value_type != DT_ZEICHEN) {
                                yyerror("Bad variable type");
                                return 1;
                            }
                            break;
                        default:
                            yyerror("Unknown variable type");
                            return 1;
                        }
                        pvar_item->value_type = (DataType)yyvsp[-3].datatype;
                        pvar_item = pvar_item->next;
                        count++;
                    } 
                }   

                if(count > pvar->len) {
                    yyerror("Too many arguments for initialization.");
                    return 1;
                }
                if(count < pvar->len) {
                    yyerror("Too little arguments for initialization.");
                    return 1;
                }

                yyval.variable = pvar;

            } else {

                pvar_item = yyvsp[-1].var_item;
                while(pvar_item) {
                    yyvsp[-1].var_item = pvar_item->next;
                    free(pvar_item);
                    pvar_item = yyvsp[-1].var_item;
                }
                yyval.variable = 0;
            }
            break;}
        case 48:
        {
            yyval.pt = PARAM_PORT;
            break;}
        case 49:
        {
            yyval.pt = INPUT_PORT;
            break;}
        case 50:
        {
            yyval.pt = DUMMY_PORT;
            break;}
        case 51:
        {
            yyval.var_item = yyvsp[-1].var_item;
            break;}
        case 52:
        {
            yyval.var_item = 0;
            break;}
        case 53:
        {
            yyval.var_item = yyvsp[0].var_item;
            break;}
        case 54:
        { 
            VariableItem* pvar_item = yyvsp[-2].var_item;

            while(pvar_item->next) {
                pvar_item=pvar_item->next;
            }
            pvar_item->next = yyvsp[0].var_item;
            yyval.var_item = yyvsp[-2].var_item;
            break;}
        case 55:
        {
            VariableItem* pvar_item = (VariableItem*)malloc(sizeof(VariableItem));
            if( (!pvar_item) || (!yyvsp[0].string) ) {
                if(pvar_item) free(pvar_item);
                yyerror("out of memory");
                return 1;
            }
            pvar_item->next = 0;
            pvar_item->value_type = DT_FLIESSCOMMA;
            pvar_item->val = yyvsp[0].string;

            yyval.var_item = pvar_item;
            break;}
        case 56:
        {
            VariableItem* pvar_item = (VariableItem*)malloc(sizeof(VariableItem));
            if((!pvar_item) || (!yyvsp[0].string) ) {
                if(pvar_item) free(pvar_item);
                yyerror("out of memory");
                return 1;
            }
            pvar_item->next = 0;
            pvar_item->value_type = DT_GANZZAHL;
            pvar_item->val = yyvsp[0].string;

            yyval.var_item = pvar_item;
            break;}
        case 57:
        {
            VariableItem* pvar_item = (VariableItem*)malloc(sizeof(VariableItem));
            if((!pvar_item) || (!yyvsp[0].string) ) {
                if(pvar_item) free(pvar_item);
                yyerror("out of memory");
                return 1;
            }
            pvar_item->next = 0;
            pvar_item->value_type = DT_BOOLIAN;
            pvar_item->val = yyvsp[0].string;

            yyval.var_item = pvar_item;
            break;}
        case 58:
        {
            VariableItem* pvar_item = (VariableItem*)malloc(sizeof(VariableItem));
            if((!pvar_item) || (!yyvsp[0].string) ) {
                if(pvar_item) free(pvar_item);
                yyerror("out of memory");
                return 1;
            }
            pvar_item->next = 0;
            pvar_item->value_type = DT_ZEICHEN;

            pvar_item->val = yyvsp[0].string;
            yyval.var_item = pvar_item;
            break;}
        case 59:
        {
            VariableItem* pvar_item = (VariableItem*)malloc(sizeof(VariableItem));
            if((!pvar_item) || (!yyvsp[0].string) ) {
                if(pvar_item) free(pvar_item);
                yyerror("out of memory");
                return 1;
            }
            pvar_item->next = 0;
            pvar_item->value_type = DT_TIMESTRUCT;
            pvar_item->val = yyvsp[0].string;

            yyval.var_item = pvar_item;
            break;}
    }


    yyvsp -= yylen;
    yyssp -= yylen;

    *++yyvsp = yyval;
    
    yyn = yyr1[yyn];

    yystate = yypgoto[yyn - 44] + *yyssp;
    if (yystate >= 0 && yystate <= 181 && yycheck[yystate] == *yyssp)
        yystate = yytable[yystate];
    else
        yystate = yydefgoto[yyn - 44];

    goto yynewstate;

yyerrlab:   
    
    if (! yyerrstatus)
    {
        ++yynerrs;
        yyerror("parse error");
    }

    goto yyerrlab1;
yyerrlab1:   

    if (yyerrstatus == 3)
    {
        if (yychar == 0)
            return(1);
        yychar = -2;
    }

    yyerrstatus = 3;                
    goto yyerrhandle;

yyerrdefault:  

yyerrpop:   

    if (yyssp == yyss) return(1);
    yyvsp--;
    yystate = *--yyssp;
 
yyerrhandle:

    yyn = yypact[yystate];
    if (yyn == -32768)
        goto yyerrdefault;

    yyn += 1;
    if (yyn < 0 || yyn > 181 || yycheck[yyn] != 1)
        goto yyerrdefault;

    yyn = yytable[yyn];
    if (yyn < 0)
    {
        if (yyn == -32768)
            goto yyerrpop;
        yyn = -yyn;
        goto yyreduce;
    }
    else if (yyn == 0)
            goto yyerrpop;

    if (yyn == 149)
        return(0);

    *++yyvsp = yylval;

    yystate = yyn;
    goto yynewstate;
}
コード例 #15
0
/* Entry point for the assembler. code_ref is assumed to be attached
   to the gc. */
size_t asm_string(gc_type *gc, char *str, uint8_t **code_ref) {
    yyscan_t scanner = 0;
    op_type token = 0;
    buffer_type *buf = 0;
    hashtable_type *labels = 0;
    jump_type *jump_list = 0;
    size_t length = 0;
    
    
    gc_register_root(gc, &buf);
    gc_register_root(gc, &labels);
    gc_register_root(gc, (void **)&jump_list);

    /* create an output buffer */
    buffer_create(gc, &buf);
    hash_create_string(gc, &labels);

    yylex_init(&scanner);
    /* yyset_debug(1, scanner); */


    /* set the scanners input */
    yy_scan_string(str, scanner);

    /* match until there is nothing left to match */
    while((token = yylex(scanner)) != END_OF_FILE) {

        /* Handle individual tokens */
        switch((int)token) {
        case OP_LIT_FIXNUM:
            asm_lit_fixnum(buf, scanner);
            break;

        case OP_LIT_CHAR:
            asm_lit_char(buf, scanner);
            break;

        case STRING_START_TOKEN:
            EMIT(buf, OP_LIT_STRING, 1);
            asm_lit_string(buf, scanner);
            break;

        case SYMBOL_START_TOKEN:
            EMIT(buf, OP_LIT_SYMBOL, 1);
            asm_lit_string(buf, scanner);
            break;

        case OP_JMP:            
        case OP_JNF:
        case OP_CALL:
        case OP_PROC:
        case OP_CONTINUE:
            EMIT(buf, token, 1); /* emit the jump operation */
            asm_jump(gc, buf, scanner, &jump_list);
            break;                

        case LABEL_TOKEN:
            asm_label(gc, buf, labels, get_text(scanner));
            break;

            /* All otherwise not defined tokens are
               their opcode */
        default:
            EMIT(buf, token, 1);
            break;

        }
    }

    yylex_destroy(scanner);


    /* build a code_ref */
    length = buffer_size(buf);
    /* *code_ref = gc_alloc(gc, 0, length); */
    gc_alloc(gc, 0, length, (void **)code_ref);
    length = buffer_read(buf, *code_ref, length);

    /* replace jump address fields */
    rewrite_jumps(*code_ref, jump_list, labels);

    gc_unregister_root(gc, &buf);
    gc_unregister_root(gc, &labels);
    gc_unregister_root(gc, (void **)&jump_list);

    return length;
}
コード例 #16
0
int command_parse_set( void )
{
    /* commands could look like the following:
     * set ignorecase
     * set noignorecase
     * set focus=gdb
     * set tabstop=8
     */

    int rv = 1;
    int boolean = 1;
    const char * value = NULL;

    switch ( (rv = yylex()) ) {
    case EOL: {
        /* TODO: Print out all the variables that have been set. */
    } break;
    case IDENTIFIER: {
        const char *token = get_token();
        int length = strlen( token );
        struct ConfigVariable *variable = NULL;

        if ( length > 2 && token[0] == 'n' && token[1] == 'o' ) {
            value = token + 2;
            boolean = 0;
        } else {
            value = token;
        }

        if ( (variable = get_variable( value )) != NULL ) {
            rv = 0;
            if( boolean == 0 &&
                variable->type != CONFIG_TYPE_BOOL ) {
                /* this is an error, you cant' do:
                 * set notabstop 
                 */
                rv = 1;
            }

            switch( variable->type ) {
            case CONFIG_TYPE_BOOL:
                *(int*)(variable->data) = boolean;
                break;
            case CONFIG_TYPE_INT: {
                if( yylex() == '=' &&
                    yylex() == NUMBER ) {
                    int data = strtol( get_token(), NULL, 10 );
                    *(int*)(variable->data) = data;
                } else {
                    rv = 1;
                }
            } break;
            case CONFIG_TYPE_STRING: {
                if( yylex() == '=' &&
                   (rv = yylex(), rv == STRING || rv == IDENTIFIER) ) {
                    /* BAM! comma operator */
                    char * data = (char*)get_token();
                    if( rv == STRING ) {
                        /* get rid of quotes */
                        data = data + 1;
                        data[ strlen( data ) - 1 ] = '\0';
                    } 
                    if( variable->data ) 
                    { free( variable->data ); }
                    variable->data = strdup( data );
                } else {
                    rv = 1;
                }
            } break;
            case CONFIG_TYPE_FUNC_VOID: {
                int(*functor)( void ) = (int(*)(void))variable->data;
                if( functor )
                { rv = functor(); }
                else 
                { rv = 1; }
            } break;
            case CONFIG_TYPE_FUNC_BOOL: {
                int (*functor)( int ) = (int(*)(int))variable->data;
                    if( functor )
                    { rv = functor( boolean ); }
                    else
                    { rv = 1; }
            } break;
            case CONFIG_TYPE_FUNC_INT: {
                int (*functor)( int ) = (int(*)(int))variable->data;
                if( yylex() == '=' &&
                    yylex() == NUMBER ) {
                    int data = strtol( get_token(), NULL, 10 );
                    if( functor )
                    { rv = functor( data ); }
                    else
                    { rv = 1; }
                } else {
                    rv = 1;
                }
            } break;
            case CONFIG_TYPE_FUNC_STRING: {
                int (*functor)( const char* ) = (int(*)(const char*))variable->data;
                if( yylex() == '=' &&
                   (rv = yylex(), rv == STRING || rv == IDENTIFIER) ) {
                    /* BAM! comma operator */
                    char * data = (char*)get_token();
                    if( rv == STRING ) {
                        /* get rid of quotes */
                        data = data + 1;
                        data[ strlen( data ) - 1 ] = '\0';
                    } 
                    if( functor )
                    { rv = functor(data); }
                    else
                    { rv = 1; }
                } else 
                { rv = 1; }
            } break;
            default: 
                rv = 1;
                break;
            }
        }
    } break;
    default:
        break;
    }

    return rv;
}
コード例 #17
0
int yyparse( parser_control *pc )
{
  int yychar;
  YYSTYPE yylval;
  int yynerrs;
  int yystate;
  int yyn;
  int yyresult;
  int yyerrstatus;
  int yytoken = 0;
  yytype_int16 yyssa[20];
  yytype_int16 *yyss = yyssa;
  yytype_int16 *yyssp;
  YYSTYPE yyvsa[20];
  YYSTYPE *yyvs = yyvsa;
  YYSTYPE *yyvsp;
  unsigned int yystacksize = 20;
  YYSTYPE yyval;
  int yylen = 0;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = -2;
  yyssp = yyss;
  yyvsp = yyvs;
  while ( yyssp[0] = yystate, yyss[ yystacksize - 1 ] <= yyssp )
  {
    if ( yystate != 12 )
    {
      yyn = yypact[ yystate ];
      if ( yyn != -81 )
      {
        if ( yychar == -2 )
        {
          yychar = yylex( &yylval, pc );
        }
        if ( yychar < 1 )
        {
          yychar = yytoken = 0;
        }
        else
        {
          yytoken = yychar <= 276 ? yytranslate[ yychar ] : 2;
        }
        yyn += yytoken;
        if ( yyn >= 0 && yyn <= 96 && yytoken == yycheck[ yyn ] )
        {
          yyn = yytable[ yyn ];
          if ( yyn < 1 )
          {
            if ( yyn != 0 && yyn != -1 )
              yyn *= -1;
              yyval.intval = *(int*)(yyvsp + ( ( ( yylen * -32 ) + 32 ) - ( ( yylen * -4 ) + 4 ) ));
              yylen = yyr2[ yyn ];
              *(int*)(ebp_2147483632 - 128) = *(int*)(yyvsp + ( ( ( yylen * -32 ) + 32 ) - ( ( yylen * -4 ) + 4 ) ) + 4);
              *(int*)(ebp_2147483632 - 124) = *(int*)(yyvsp + ( ( ( yylen * -32 ) + 32 ) - ( ( yylen * -4 ) + 4 ) ) + 8);
              *(int*)(ebp_2147483632 - 120) = *(int*)(yyvsp + ( ( ( yylen * -32 ) + 32 ) - ( ( yylen * -4 ) + 4 ) ) + 12);
              *(int*)(ebp_2147483632 - 116) = *(int*)(yyvsp + ( ( ( yylen * -32 ) + 32 ) - ( ( yylen * -4 ) + 4 ) ) + 16);
              *(int*)(ebp_2147483632 - 112) = *(int*)(yyvsp + ( ( ( yylen * -32 ) + 32 ) - ( ( yylen * -4 ) + 4 ) ) + 20);
              *(int*)(ebp_2147483632 - 108) = *(int*)(yyvsp + ( ( ( yylen * -32 ) + 32 ) - ( ( yylen * -4 ) + 4 ) ) + 24);
              switch ( yyn )
              {
              case 4:
                pc->seconds.tv_sec = yyvsp->intval;
                pc->seconds.tv_nsec = yyvsp->relative_time.month/*error:'l'*/;
                pc->timespec_seen = 1;
                yyvsp->intval = yyval.intval;
                yyvsp = &yyvsp[ yylen * -1 ];
                yyssp = &yyssp[ yylen * -1 ];
                yylen = 0;
                yyvsp++;
                yyvsp->relative_time.month/*error:'l'*/ = *(int*)(ebp_2147483632 - 128);
                yyvsp->relative_time.day/*error:'l'*/ = *(int*)(ebp_2147483632 - 124);
                yyvsp->relative_time.hour/*error:'l'*/ = *(int*)(ebp_2147483632 - 120);
                yyvsp->relative_time.minutes/*error:'l'*/ = *(int*)(ebp_2147483632 - 116);
                yyvsp->relative_time.seconds/*error:'l'*/ = *(int*)(ebp_2147483632 - 112);
                yyvsp->relative_time.ns/*error:'l'*/ = *(int*)(ebp_2147483632 - 108);
                yyn = yyr1[ yyn ];
                yystate = yypgoto[ yyn - 26 ] + yyssp[0];
                if ( yystate >= 0 && yystate <= 96 && yyssp[0] == yycheck[ yystate ] )
                  yystate = yytable[ yystate ];
                  yyssp++;
                else
                  yystate = yydefgoto[ yyn - 26 ];
                break;
              case 7:
                pc->times_seen++;
                break;
              case 8:
                pc->local_zones_seen++;
                break;
              case 9:
                pc->zones_seen++;
                break;
              case 10:
                pc->dates_seen++;
                break;
              case 11:
                pc->days_seen++;
                break;
              case 12:
                pc->rels_seen = 1;
                break;
              case 15:
                pc->hour = *(int*)(yyvsp - 24);
                pc->minutes = 0;
                pc->seconds.tv_sec = 0;
                pc->seconds.tv_nsec = 0;
                pc->meridian = yyvsp->intval;
                break;
              case 16:
                pc->hour = *(int*)(yyvsp - 80);
                pc->minutes = *(int*)(yyvsp - 24);
                pc->seconds.tv_sec = 0;
                pc->seconds.tv_nsec = 0;
                pc->meridian = yyvsp->intval;
                break;
              case 17:
                pc->hour = *(int*)(yyvsp - 108);
                pc->minutes = *(int*)(yyvsp - 52);
                pc->seconds.tv_sec = 0;
                pc->seconds.tv_nsec = 0;
                pc->meridian = 2;
                pc->zones_seen++;
                pc->time_zone = time_zone_hhmm( yyvsp - 28, yyvsp->intval );
                break;
              case 18:
                pc->hour = *(int*)(yyvsp - 136);
                pc->minutes = *(int*)(yyvsp - 80);
                pc->seconds.tv_sec = *(int*)(yyvsp - 28);
                pc->seconds.tv_nsec = *(int*)(yyvsp - 24);
                pc->meridian = yyvsp->intval;
                break;
              case 19:
                pc->hour = *(int*)(yyvsp - 164);
                pc->minutes = *(int*)(yyvsp - 108);
                pc->seconds.tv_sec = *(int*)(yyvsp - 56);
                pc->seconds.tv_nsec = *(int*)(yyvsp - 52);
                pc->meridian = 2;
                pc->zones_seen++;
                pc->time_zone = time_zone_hhmm( yyvsp - 28, yyvsp->intval );
                break;
              case 20:
                pc->local_isdst = yyvsp->intval;
                pc->dsts_seen += yyvsp->intval > 0;
                break;
              case 21:
                pc->local_isdst = 1;
                pc->dsts_seen += *(int*)(yyvsp - 28) < 1 ? 1 : 2;
                break;
              case 22:
                pc->time_zone = yyvsp->intval;
                break;
              case 23:
                pc->time_zone = *(int*)(yyvsp - 28);
                pc->rel.ns += yyvsp->relative_time.ns/*error:'l'*/;
                pc->rel.seconds += yyvsp->relative_time.seconds/*error:'l'*/;
                pc->rel.minutes += yyvsp->relative_time.minutes/*error:'l'*/;
                pc->rel.hour += yyvsp->relative_time.hour/*error:'l'*/;
                pc->rel.day += (int)yyvsp->relative_time.day/*error:'l'*/;
                pc->rel.month += yyvsp->relative_time.month/*error:'l'*/;
                pc->rel.year += yyvsp->intval;
                pc->rels_seen = 1;
                break;
              case 24:
                pc->time_zone = *(int*)(yyvsp - 56) + time_zone_hhmm( yyvsp - 28, yyvsp->intval );
                break;
              case 25:
                pc->time_zone = yyvsp->intval + 60;
                break;
              case 26:
                pc->time_zone = *(int*)(yyvsp - 28) + 60;
                break;
              case 27:
                pc->day_ordinal = 1;
                pc->day_number = yyvsp->intval;
                break;
              case 28:
                pc->day_ordinal = 1;
                pc->day_number = *(int*)(yyvsp - 28);
                break;
              case 29:
                pc->day_ordinal = *(int*)(yyvsp - 28);
                pc->day_number = yyvsp->intval;
                break;
              case 30:
                pc->day_ordinal = *(int*)(yyvsp - 24);
                pc->day_number = yyvsp->intval;
                break;
              case 31:
                pc->month = *(int*)(yyvsp - 52);
                pc->day = yyvsp->relative_time.month/*error:'l'*/;
                break;
              case 32:
                if ( *(int*)(yyvsp - 104) > 3 )
                {
                  pc->year.negative = *(int*)(yyvsp - 112);
                  pc->year.value = *(int*)(yyvsp - 108);
                  pc->year.digits = *(int*)(yyvsp - 104);
                  pc->month = *(int*)(yyvsp - 52);
                  pc->day = yyvsp->relative_time.month/*error:'l'*/;
                }
                else
                {
                  pc->month = *(int*)(yyvsp - 108);
                  pc->day = *(int*)(yyvsp - 52);
                  pc->year.negative = yyvsp->intval;
                  pc->year.value = yyvsp->relative_time.month/*error:'l'*/;
                  pc->year.digits = yyvsp->relative_time.day/*error:'l'*/;
                }
                break;
              case 33:
                pc->year.negative = *(int*)(yyvsp - 56);
                pc->year.value = *(int*)(yyvsp - 52);
                pc->year.digits = *(int*)(yyvsp - 48);
                pc->month = *(int*)(yyvsp - 24) * -1;
                pc->day = yyvsp->relative_time.month/*error:'l'*/ * -1;
                break;
              case 34:
                pc->day = *(int*)(yyvsp - 52);
                pc->month = *(int*)(yyvsp - 28);
                pc->year.value = yyvsp->relative_time.month/*error:'l'*/ * -1;
                pc->year.digits = yyvsp->relative_time.day/*error:'l'*/;
                break;
              case 35:
                pc->month = *(int*)(yyvsp - 56);
                pc->day = *(int*)(yyvsp - 24) * -1;
                pc->year.value = yyvsp->relative_time.month/*error:'l'*/ * -1;
                pc->year.digits = yyvsp->relative_time.day/*error:'l'*/;
                break;
              case 36:
                pc->month = *(int*)(yyvsp - 28);
                pc->day = yyvsp->relative_time.month/*error:'l'*/;
                break;
              case 37:
                pc->month = *(int*)(yyvsp - 84);
                pc->day = *(int*)(yyvsp - 52);
                pc->year.negative = yyvsp->intval;
                pc->year.value = yyvsp->relative_time.month/*error:'l'*/;
                pc->year.digits = yyvsp->relative_time.day/*error:'l'*/;
                break;
              case 38:
                pc->day = *(int*)(yyvsp - 24);
                pc->month = yyvsp->intval;
                break;
              case 39:
                pc->day = *(int*)(yyvsp - 52);
                pc->month = *(int*)(yyvsp - 28);
                pc->year.negative = yyvsp->intval;
                pc->year.value = yyvsp->relative_time.month/*error:'l'*/;
                pc->year.digits = yyvsp->relative_time.day/*error:'l'*/;
                break;
              case 40:
                pc->rel.ns -= *(int*)(yyvsp - 4);
                pc->rel.seconds -= *(int*)(yyvsp - 8);
                pc->rel.minutes -= *(int*)(yyvsp - 12);
                pc->rel.hour -= *(int*)(yyvsp - 16);
                pc->rel.day -= *(int*)(yyvsp - 20);
                pc->rel.month -= *(int*)(yyvsp - 24);
                pc->rel.year -= *(int*)(yyvsp - 28);
                break;
              case 41:
                pc->rel.ns += yyvsp->relative_time.ns/*error:'l'*/;
                pc->rel.seconds += yyvsp->relative_time.seconds/*error:'l'*/;
                pc->rel.minutes += yyvsp->relative_time.minutes/*error:'l'*/;
                pc->rel.hour += yyvsp->relative_time.hour/*error:'l'*/;
                pc->rel.day += (int)yyvsp->relative_time.day/*error:'l'*/;
                pc->rel.month += yyvsp->relative_time.month/*error:'l'*/;
                pc->rel.year += yyvsp->intval;
                break;
              case 42:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                yyval.intval = *(int*)(yyvsp - 28);
                break;
              case 43:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                yyval.intval = *(int*)(yyvsp - 24);
                break;
              case 44:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                yyval.intval = 1;
                break;
              case 45:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 128) = *(int*)(yyvsp - 28);
                break;
              case 46:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 128) = *(int*)(yyvsp - 24);
                break;
              case 47:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 128) = 1;
                break;
              case 48:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 124) = yyvsp->intval * *(int*)(yyvsp - 28);
                break;
              case 49:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 124) = yyvsp->intval * *(int*)(yyvsp - 24);
                break;
              case 50:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 124) = yyvsp->intval;
                break;
              case 51:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 120) = *(int*)(yyvsp - 28);
                break;
              case 52:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 120) = *(int*)(yyvsp - 24);
                break;
              case 53:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 120) = 1;
                break;
              case 54:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 116) = *(int*)(yyvsp - 28);
                break;
              case 55:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 116) = *(int*)(yyvsp - 24);
                break;
              case 56:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 116) = 1;
                break;
              case 57:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 112) = *(int*)(yyvsp - 28);
                break;
              case 58:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 112) = *(int*)(yyvsp - 24);
                break;
              case 59:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 112) = *(int*)(yyvsp - 28);
                *(int*)(ebp_2147483632 - 108) = *(int*)(yyvsp - 24);
                break;
              case 60:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 112) = *(int*)(yyvsp - 28);
                *(int*)(ebp_2147483632 - 108) = *(int*)(yyvsp - 24);
                break;
              case 61:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 112) = 1;
                break;
              case 63:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                yyval.intval = *(int*)(yyvsp - 24);
                break;
              case 64:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 128) = *(int*)(yyvsp - 24);
                break;
              case 65:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 124) = yyvsp->intval * *(int*)(yyvsp - 24);
                break;
              case 66:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 120) = *(int*)(yyvsp - 24);
                break;
              case 67:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 116) = *(int*)(yyvsp - 24);
                break;
              case 68:
                yyval.intval = RELATIVE_TIME_0.year;
                *(int*)(ebp_2147483632 - 128) = RELATIVE_TIME_0.month;
                *(int*)(ebp_2147483632 - 124) = RELATIVE_TIME_0.day;
                *(int*)(ebp_2147483632 - 120) = RELATIVE_TIME_0.hour;
                *(int*)(ebp_2147483632 - 116) = RELATIVE_TIME_0.minutes;
                *(int*)(ebp_2147483632 - 112) = RELATIVE_TIME_0.seconds;
                *(int*)(ebp_2147483632 - 108) = RELATIVE_TIME_0.ns;
                *(int*)(ebp_2147483632 - 112) = *(int*)(yyvsp - 24);
                break;
              case 72:
                yyval.intval = yyvsp->relative_time.month/*error:'l'*/;
                *(int*)(ebp_2147483632 - 128) = 0;
                break;
              case 74:
                yyval.intval = yyvsp->relative_time.month/*error:'l'*/;
                *(int*)(ebp_2147483632 - 128) = 0;
                break;
              case 75:
                digits_to_date_time( pc, yyvsp[0].intval/*error:'l'*/ );
                break;
              case 76:
                digits_to_date_time( pc, yyvsp - 28 );
                pc->rel.ns += yyvsp->relative_time.ns/*error:'l'*/;
                pc->rel.seconds += yyvsp->relative_time.seconds/*error:'l'*/;
                pc->rel.minutes += yyvsp->relative_time.minutes/*error:'l'*/;
                pc->rel.hour += yyvsp->relative_time.hour/*error:'l'*/;
                pc->rel.day += (int)yyvsp->relative_time.day/*error:'l'*/;
                pc->rel.month += yyvsp->relative_time.month/*error:'l'*/;
                pc->rel.year += yyvsp->intval;
                pc->rels_seen = 1;
                break;
              case 77:
                yyval.intval = -1;
                break;
              case 78:
                yyval.intval = yyvsp->relative_time.month/*error:'l'*/;
                break;
              case 79:
                yyval.intval = 2;
                break;
              case 80:
                yyval.intval = yyvsp->intval;
                break;
              default:
                break;
              }
            else
            {
              if ( yyerrstatus == 0 )
              {
                yynerrs++;
                yyerror( pc, "syntax error" );
              }
              if ( yyerrstatus == 3 )
              {
                if ( yychar < 1 )
                {
                  if ( yychar != 0 )
                  {
                  }
                  else
                    yyresult = 1;
                    if ( yychar != -2 )
                      yydestruct( "Cleanup: discarding lookahead", yytoken, &yylval, pc );
                    yyvsp = &yyvsp[ yylen * -1 ];
                    yyssp = &yyssp[ yylen * -1 ];
                    for ( ; yyssp != yyss; yyssp = &yyssp[ -1 ] )
                    {
                      yydestruct( "Cleanup: popping", yystos[ yyssp[0] ], yyvsp, pc );
                      yyvsp -= 28;
                      //yyssp = &yyssp[ -1 ];
                    }
                    if ( yyssa[0] != yyss )
                    {
                      free( yyss );
                      break;
                    }
                }
                else
                {
                  yydestruct( "Error: discarding", yytoken, &yylval, pc );
                  yychar = -2;
                }
              }
              yyerrstatus = 3;
              while ( yyn = yypact[ yystate ], yyn == -81 )
              {
                if ( yyssp != yyss )
                {
                  yydestruct( "Error: popping", yystos[ yystate ], yyvsp, pc );
                  yyvsp -= 28;
                  yyssp = &yyssp[ -1 ];
                  yystate = yyssp[0];
                }
              }
              yyn++;
              if ( yyn >= 0 && yyn <= 96 && yycheck[ yyn ] == 1 )
              {
                yyn = yytable[ yyn ];
                if ( yyn >= 1 )
                  yyvsp->intval = yylval.intval;
                {
                  yyvsp->intval = yylval.intval;
                  yyvsp++;
                  yyvsp->relative_time.month/*error:'l'*/ = *(int*)(ebp_2147483632 - 100);
                  yyvsp->relative_time.day/*error:'l'*/ = *(int*)(ebp_2147483632 - 96);
                  yyvsp->relative_time.hour/*error:'l'*/ = *(int*)(ebp_2147483632 - 92);
                  yyvsp->relative_time.minutes/*error:'l'*/ = *(int*)(ebp_2147483632 - 88);
                  yyvsp->relative_time.seconds/*error:'l'*/ = *(int*)(ebp_2147483632 - 84);
                  yyvsp->relative_time.ns/*error:'l'*/ = *(int*)(ebp_2147483632 - 80);
                  yystate = yyn;
                }
              }
            }
          }
          else
          {
            if ( yyerrstatus != 0 )
コード例 #18
0
  int
  xml_parser::parse ()
  {
    // State.
    int yyn;
    /// Length of the RHS of the rule being reduced.
    int yylen = 0;

    // Error handling.
    int yynerrs_ = 0;
    int yyerrstatus_ = 0;

    /// The lookahead symbol.
    symbol_type yyla;

    /// The locations where the error started and ended.
    stack_symbol_type yyerror_range[3];

    /// The return value of parse ().
    int yyresult;

    // FIXME: This shoud be completely indented.  It is not yet to
    // avoid gratuitous conflicts when merging into the master branch.
    try
      {
    YYCDEBUG << "Starting parse" << std::endl;


    /* Initialize the stack.  The initial state will be set in
       yynewstate, since the latter expects the semantical and the
       location values to have been already stored, initialize these
       stacks with a primary value.  */
    yystack_.clear ();
    yypush_ (YY_NULLPTR, 0, yyla);

    // A new symbol was pushed on the stack.
  yynewstate:
    YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;

    // Accept?
    if (yystack_[0].state == yyfinal_)
      goto yyacceptlab;

    goto yybackup;

    // Backup.
  yybackup:

    // Try to take a decision without lookahead.
    yyn = yypact_[yystack_[0].state];
    if (yy_pact_value_is_default_ (yyn))
      goto yydefault;

    // Read a lookahead token.
    if (yyla.empty ())
      {
        YYCDEBUG << "Reading a token: ";
        try
          {
            symbol_type yylookahead (yylex ());
            yyla.move (yylookahead);
          }
        catch (const syntax_error& yyexc)
          {
            error (yyexc);
            goto yyerrlab1;
          }
      }
    YY_SYMBOL_PRINT ("Next token is", yyla);

    /* If the proper action on seeing token YYLA.TYPE is to reduce or
       to detect an error, take that action.  */
    yyn += yyla.type_get ();
    if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
      goto yydefault;

    // Reduce or error.
    yyn = yytable_[yyn];
    if (yyn <= 0)
      {
        if (yy_table_value_is_error_ (yyn))
          goto yyerrlab;
        yyn = -yyn;
        goto yyreduce;
      }

    // Count tokens shifted since error; after three, turn off error status.
    if (yyerrstatus_)
      --yyerrstatus_;

    // Shift the lookahead token.
    yypush_ ("Shifting", yyn, yyla);
    goto yynewstate;

  /*-----------------------------------------------------------.
  | yydefault -- do the default action for the current state.  |
  `-----------------------------------------------------------*/
  yydefault:
    yyn = yydefact_[yystack_[0].state];
    if (yyn == 0)
      goto yyerrlab;
    goto yyreduce;

  /*-----------------------------.
  | yyreduce -- Do a reduction.  |
  `-----------------------------*/
  yyreduce:
    yylen = yyr2_[yyn];
    {
      stack_symbol_type yylhs;
      yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);
      /* Variants are always initialized to an empty instance of the
         correct type. The default '$$ = $1' action is NOT applied
         when using variants.  */
        switch (yyr1_[yyn])
    {
      case 3: // NAME
      case 4: // TEXT
      case 5: // STRING
        yylhs.value.build< std::string > ();
        break;

      default:
        break;
    }


      // Compute the default @$.
      {
        slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
        YYLLOC_DEFAULT (yylhs.location, slice, yylen);
      }

      // Perform the reduction.
      YY_REDUCE_PRINT (yyn);
      try
        {
          switch (yyn)
            {
  case 2:
#line 38 "xml_parser/parser.ypp" // lalr1.cc:859
    { result = "OK"; }
#line 541 "xml_parser/parser.cpp" // lalr1.cc:859
    break;

  case 6:
    if (! (//#line 46 "xml_parser/parser.ypp" // lalr1.cc:859
     yystack_[5].value.as< std::string > () == yystack_[0].value.as< std::string > () )) YYERROR;
#line 547 "xml_parser/parser.cpp" // lalr1.cc:859
    break;


#line 551 "xml_parser/parser.cpp" // lalr1.cc:859
            default:
              break;
            }
        }
      catch (const syntax_error& yyexc)
        {
          error (yyexc);
          YYERROR;
        }
      YY_SYMBOL_PRINT ("-> $$ =", yylhs);
      yypop_ (yylen);
      yylen = 0;
      YY_STACK_PRINT ();

      // Shift the result of the reduction.
      yypush_ (YY_NULLPTR, yylhs);
    }
    goto yynewstate;

  /*--------------------------------------.
  | yyerrlab -- here on detecting error.  |
  `--------------------------------------*/
  yyerrlab:
    // If not already recovering from an error, report this error.
    if (!yyerrstatus_)
      {
        ++yynerrs_;
        error (yyla.location, yysyntax_error_ (yystack_[0].state, yyla));
      }


    yyerror_range[1].location = yyla.location;
    if (yyerrstatus_ == 3)
      {
        /* If just tried and failed to reuse lookahead token after an
           error, discard it.  */

        // Return failure if at end of input.
        if (yyla.type_get () == yyeof_)
          YYABORT;
        else if (!yyla.empty ())
          {
            yy_destroy_ ("Error: discarding", yyla);
            yyla.clear ();
          }
      }

    // Else will try to reuse lookahead token after shifting the error token.
    goto yyerrlab1;


  /*---------------------------------------------------.
  | yyerrorlab -- error raised explicitly by YYERROR.  |
  `---------------------------------------------------*/
  yyerrorlab:

    /* Pacify compilers like GCC when the user code never invokes
       YYERROR and the label yyerrorlab therefore never appears in user
       code.  */
    if (false)
      goto yyerrorlab;
    yyerror_range[1].location = yystack_[yylen - 1].location;
    /* Do not reclaim the symbols of the rule whose action triggered
       this YYERROR.  */
    yypop_ (yylen);
    yylen = 0;
    goto yyerrlab1;

  /*-------------------------------------------------------------.
  | yyerrlab1 -- common code for both syntax error and YYERROR.  |
  `-------------------------------------------------------------*/
  yyerrlab1:
    yyerrstatus_ = 3;   // Each real token shifted decrements this.
    {
      stack_symbol_type error_token;
      for (;;)
        {
          yyn = yypact_[yystack_[0].state];
          if (!yy_pact_value_is_default_ (yyn))
            {
              yyn += yyterror_;
              if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
                {
                  yyn = yytable_[yyn];
                  if (0 < yyn)
                    break;
                }
            }

          // Pop the current state because it cannot handle the error token.
          if (yystack_.size () == 1)
            YYABORT;

          yyerror_range[1].location = yystack_[0].location;
          yy_destroy_ ("Error: popping", yystack_[0]);
          yypop_ ();
          YY_STACK_PRINT ();
        }

      yyerror_range[2].location = yyla.location;
      YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);

      // Shift the error token.
      error_token.state = yyn;
      yypush_ ("Shifting", error_token);
    }
    goto yynewstate;

    // Accept.
  yyacceptlab:
    yyresult = 0;
    goto yyreturn;

    // Abort.
  yyabortlab:
    yyresult = 1;
    goto yyreturn;

  yyreturn:
    if (!yyla.empty ())
      yy_destroy_ ("Cleanup: discarding lookahead", yyla);

    /* Do not reclaim the symbols of the rule whose action triggered
       this YYABORT or YYACCEPT.  */
    yypop_ (yylen);
    while (1 < yystack_.size ())
      {
        yy_destroy_ ("Cleanup: popping", yystack_[0]);
        yypop_ ();
      }

    return yyresult;
  }
    catch (...)
      {
        YYCDEBUG << "Exception caught: cleaning lookahead and stack"
                 << std::endl;
        // Do not try to display the values of the reclaimed symbols,
        // as their printer might throw an exception.
        if (!yyla.empty ())
          yy_destroy_ (YY_NULLPTR, yyla);

        while (1 < yystack_.size ())
          {
            yy_destroy_ (YY_NULLPTR, yystack_[0]);
            yypop_ ();
          }
        throw;
      }
  }
コード例 #19
0
ファイル: interpre.c プロジェクト: ricpelo/prometeo
yyparse()
{
  int statestack[YYMAXDEPTH]; /* state stack */
  int      j, m;              /* working index */
  YYSTYPE *yypvt;
  int      tmpstate, tmptoken, *yyps, n;
  YYSTYPE *yypv;


  tmpstate = 0;
  pcyytoken = -1;
#ifdef YYDEBUG
  tmptoken = -1;
#endif
  pcyyerrct = 0;
  pcyyerrfl = 0;
  yyps = &statestack[-1];
  yypv = &yyv[-1];


  enstack:    /* push stack */
#ifdef YYDEBUG
    printf("at state %d, next token %d\n", tmpstate, tmptoken);
#endif
    if (++yyps - &statestack[YYMAXDEPTH] > 0) {
      yyerror("pcyacc internal stack overflow");
      return(1);
    }
    *yyps = tmpstate;
    ++yypv;
    *yypv = yyval;


  newstate:
    n = yypact[tmpstate];
    if (n <= PCYYFLAG) goto defaultact; /*  a simple state */


    if (pcyytoken < 0) if ((pcyytoken=yylex()) < 0) pcyytoken = 0;
    if ((n += pcyytoken) < 0 || n >= YYLAST) goto defaultact;


    if (yychk[n=yyact[n]] == pcyytoken) { /* a shift */
#ifdef YYDEBUG
      tmptoken  = pcyytoken;
#endif
      pcyytoken = -1;
      yyval = yylval;
      tmpstate = n;
      if (pcyyerrfl > 0) --pcyyerrfl;
      goto enstack;
    }


  defaultact:


    if ((n=yydef[tmpstate]) == -2) {
      if (pcyytoken < 0) if ((pcyytoken=yylex())<0) pcyytoken = 0;
      for (yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=tmpstate); yyxi += 2);
      while (*(yyxi+=2) >= 0) if (*yyxi == pcyytoken) break;
      if ((n=yyxi[1]) < 0) { /* an accept action */
        if (yytflag) {
          int ti; int tj;
          yytfilep = fopen(yytfilen, "w");
          if (yytfilep == NULL) {
            fprintf(stderr, "Can't open t file: %s\n", yytfilen);
            return(0);          }
          for (ti=redcnt-1; ti>=0; ti--) {
            tj = svdprd[redseq[ti]];
            while (strcmp(svdnams[tj], "$EOP"))
              fprintf(yytfilep, "%s ", svdnams[tj++]);
            fprintf(yytfilep, "\n");
          }
          fclose(yytfilep);
        }
        return (0);
      }
    }


    if (n == 0) {        /* error situation */
      switch (pcyyerrfl) {
        case WAS0ERR:          /* an error just occurred */
          yyerror("syntax error");
          yyerrlab:
            ++pcyyerrct;
        case WAS1ERR:
        case WAS2ERR:           /* try again */
          pcyyerrfl = 3;
	   /* find a state for a legal shift action */
          while (yyps >= statestack) {
	     n = yypact[*yyps] + YYERRCODE;
	     if (n >= 0 && n < YYLAST && yychk[yyact[n]] == YYERRCODE) {
	       tmpstate = yyact[n];  /* simulate a shift of "error" */
	       goto enstack;
            }
	     n = yypact[*yyps];


	     /* the current yyps has no shift on "error", pop stack */
#ifdef YYDEBUG
            printf("error: pop state %d, recover state %d\n", *yyps, yyps[-1]);
#endif
	     --yyps;
	     --yypv;
	   }


	   yyabort:
            if (yytflag) {
              int ti; int tj;
              yytfilep = fopen(yytfilen, "w");
              if (yytfilep == NULL) {
                fprintf(stderr, "Can't open t file: %s\n", yytfilen);
                return(1);              }
              for (ti=1; ti<redcnt; ti++) {
                tj = svdprd[redseq[ti]];
                while (strcmp(svdnams[tj], "$EOP"))
                  fprintf(yytfilep, "%s ", svdnams[tj++]);
                fprintf(yytfilep, "\n");
              }
              fclose(yytfilep);
            }
	     return(1);


	 case WAS3ERR:  /* clobber input char */
#ifdef YYDEBUG
          printf("error: discard token %d\n", pcyytoken);
#endif
          if (pcyytoken == 0) goto yyabort; /* quit */
	   pcyytoken = -1;
	   goto newstate;      } /* switch */
    } /* if */


    /* reduction, given a production n */
#ifdef YYDEBUG
    printf("reduce with rule %d\n", n);
#endif
    if (yytflag && redcnt<YYREDMAX) redseq[redcnt++] = n;
    yyps -= yyr2[n];
    yypvt = yypv;
    yypv -= yyr2[n];
    yyval = yypv[1];
    m = n;
    /* find next state from goto table */
    n = yyr1[n];
    j = yypgo[n] + *yyps + 1;
    if (j>=YYLAST || yychk[ tmpstate = yyact[j] ] != -n) tmpstate = yyact[yypgo[n]];
    switch (m) { /* actions associated with grammar rules */
      
      case 1:
# line 28 "interpre.y"
      { syntaxError = terminal = hecho = 0; bandera[33] = bandera[34] =
      			bandera[35] = bandera[36] = bandera[43] = bandera[44] =
      			bandera[45] = bandera[48] = bandera[49] = bandera[50] = -1; } break;
      case 9:
# line 44 "interpre.y"
      { if (!syntaxError) EjecutaSentencia(); } break;
      case 10:
# line 45 "interpre.y"
      { syntaxError = 1; yyerror("syntax error"); } break;
      case 15:
# line 54 "interpre.y"
      { hecho = 0; bandera[33] = yypvt[-0]; } break;
      case 17:
# line 56 "interpre.y"
      { hecho = 0; bandera[33] = yypvt[-0]; } break;
      case 19:
# line 58 "interpre.y"
      { hecho = 0; bandera[33] = yypvt[-0]; } break;
      case 21:
# line 61 "interpre.y"
      { if (bandera[33] >= 0) {
      			  bandera[34] = yypvt[-0];
      			  hecho = 0;
      		  }
      		} break;
      case 23:
# line 67 "interpre.y"
      { if (bandera[33] >= 0) hecho = 0; } break;
      case 27:
# line 75 "interpre.y"
      { bandera[48] = yypvt[-0]; } break;
      case 29:
# line 76 "interpre.y"
      { bandera[49] = yypvt[-0]; } break;
      case 31:
# line 77 "interpre.y"
      { bandera[50] = yypvt[-0]; } break;
      case 33:
# line 81 "interpre.y"
      { bandera[49] = yypvt[-0]; } break;
      case 35:
# line 82 "interpre.y"
      { bandera[50] = yypvt[-0]; } break;
      case 37:
# line 86 "interpre.y"
      { bandera[50] = yypvt[-0]; } break;
      case 39:
# line 90 "interpre.y"
      { bandera[43] = yypvt[-0]; } break;
      case 41:
# line 94 "interpre.y"
      { bandera[34] = yypvt[-0]; } break;
      case 44:
# line 97 "interpre.y"
      { if (!terminal) bandera[34] = -1; } break;
      case 45:
# line 98 "interpre.y"
      { bandera[34] = yypvt[-0]; } break;
      case 47:
# line 100 "interpre.y"
      { bandera[34] = yypvt[-0]; } break;
      case 49:
# line 104 "interpre.y"
      { bandera[35] = yypvt[-0]; } break;
      case 51:
# line 108 "interpre.y"
      { bandera[44] = yypvt[-0]; } break;
      case 55:
# line 113 "interpre.y"
      { bandera[45] = yypvt[-0]; } break;
      case 57:
# line 117 "interpre.y"
      { bandera[36] = yypvt[-0]; } break;    }
    goto enstack;
}
コード例 #20
0
bool match(int token) {
	if(currentId == -1)
		currentId = yylex();
	return token == currentId;
}
コード例 #21
0
ファイル: lexer.cpp プロジェクト: apuch/NopeRead
 Terminal* Lex() {
     int r = yylex();
     if (_lexerTerminal != NULL && r != 0)
         _lexerTerminal->SetCode(r);
     return r == 0 ? NULL : _lexerTerminal;
 }
コード例 #22
0
void advance(void){
	/* Advance the lookahead to the next
	   input symbol.                               */
	currentId = yylex();
}
コード例 #23
0
ファイル: js-norm.c プロジェクト: OPSF/uClinux
/* buffer is html-normlike "chunk", if original file is bigger than buffer,
 * we rewind to a space, so we'll know that tokens won't be broken in half at
 * the end of a buffer. All tokens except string-literals of course.
 * So we can assume that after the buffer there is either a space, EOF, or a
 * chunk of text not containing whitespace at all (for which we care only if its
 * a stringliteral)*/
void cli_js_process_buffer(struct parser_state *state, const char *buf, size_t n)
{
	struct scope* current = state->current;
	YYSTYPE val;
	int yv;
	YY_BUFFER_STATE yyb;

	if(!state->global) {
		/* this state has either not been initialized,
		 * or cli_js_parse_done() was already called on it */
		cli_warnmsg(MODULE "invalid state\n");
		return;
	}
	yyb = yy_scan_bytes(buf, n, state->scanner);
	memset(&val, 0, sizeof(val));
	val.vtype = vtype_undefined;
	/* on EOF yylex will return 0 */
	while( (yv=yylex(&val, state->scanner)) != 0)
	{
		const char *text;
		size_t leng;

		val.type = yv;
		switch(yv) {
			case TOK_VAR:
				current->fsm_state = InsideVar;
				break;
			case TOK_IDENTIFIER_NAME:
				text = yyget_text(state->scanner);
				leng = yyget_leng(state->scanner);
				if(current->last_token == TOK_DOT) {
					/* this is a member name, don't normalize
					*/
					TOKEN_SET(&val, string, cli_strdup(text));
					val.type = TOK_UNNORM_IDENTIFIER;
				} else {
					switch(current->fsm_state) {
						case WaitParameterList:
							state->syntax_errors++;
							/* fall through */
						case Base:
						case InsideInitializer:
							TOKEN_SET(&val, cstring, scope_use(current, text, leng));
							break;
						case InsideVar:
						case InsideFunctionDecl:
							TOKEN_SET(&val, cstring, scope_declare(current, text, leng, state));
							current->fsm_state = InsideInitializer;
							current->brackets = 0;
							break;
						case WaitFunctionName:
							TOKEN_SET(&val, cstring, scope_declare(current, text, leng, state));
							current->fsm_state = WaitParameterList;
							break;
					}
				}
				break;
			case TOK_PAR_OPEN:
				switch(current->fsm_state) {
					case WaitFunctionName:
						/* fallthrough */
					case WaitParameterList:
						current->fsm_state = InsideFunctionDecl;
						break;
					default:
						/* noop */
						break;
				}
				break;
			case TOK_PAR_CLOSE:
				switch(current->fsm_state) {
					case WaitFunctionName:
						state->syntax_errors++;
						break;
					case WaitParameterList:
						current->fsm_state = Base;
						break;
					default:
						/* noop */
						break;
				}
				break;
			case TOK_CURLY_BRACE_OPEN:
				switch(current->fsm_state) {
					case WaitFunctionName:
						/* fallthrough */
					case WaitParameterList:
					case InsideFunctionDecl:
						/* in a syntactically correct
						 * file, we would already be in
						 * the Base state when we see a {
						 */
						current->fsm_state = Base;
						/* fall-through */
					case InsideVar:
					case InsideInitializer:
						state->syntax_errors++;
						/* fall-through */
					case Base:
					default:
						current->blocks++;
						break;
				}
				break;
					case TOK_CURLY_BRACE_CLOSE:
				if(current->blocks > 0)
					current->blocks--;
				else
					state->syntax_errors++;
				if(!current->blocks) {
					if(current->parent) {
						/* add dummy FUNCTION token to
						 * mark function end */
						TOKEN_SET(&val, cstring, "}");
						add_token(state, &val);
						TOKEN_SET(&val, scope, NULL);
						val.type = TOK_FUNCTION;

						state->current = current = current->parent;
					} else{
						/* extra } */
						state->syntax_errors++;
				}
				}
				break;
			case TOK_BRACKET_OPEN:
				current->brackets++;
				break;
			case TOK_BRACKET_CLOSE:
				if(current->brackets > 0)
					current->brackets--;
				else
					state->syntax_errors++;
				break;
			case TOK_COMMA:
				if (current->fsm_state == InsideInitializer && current->brackets == 0 && current->blocks == 0) {
					/* initializer ended only if we
					 * encountered a comma, and [] are
					 * balanced.
					 * This avoids switching state on:
					 * var x = [4,y,u];*/
					current->fsm_state = InsideVar;
				}
				break;
			case TOK_SEMICOLON:
				if (current->brackets == 0 && current->blocks == 0) {
					/* avoid switching state on unbalanced []:
					 * var x = [test;testi]; */
					current->fsm_state = Base;
				}
				break;
			case TOK_FUNCTION:
				current = scope_new(state);
				current->fsm_state = WaitFunctionName;
				TOKEN_SET(&val, scope, state->current);
				break;
			case TOK_StringLiteral:
				if(state->tokens.cnt > 0 && state->tokens.data[state->tokens.cnt-1].type == TOK_PLUS) {
					/* see if can fold */
					yystype *prev_string = &state->tokens.data[state->tokens.cnt-2];
					if(prev_string->type == TOK_StringLiteral) {
						char *str = TOKEN_GET(prev_string, string);
						size_t str_len = strlen(str);

						text = yyget_text(state->scanner);
						leng = yyget_leng(state->scanner);


						/* delete TOK_PLUS */
						free_token(&state->tokens.data[--state->tokens.cnt]);

						str = cli_realloc(str, str_len + leng + 1);
						strncpy(str+str_len, text, leng);
						str[str_len + leng] = '\0';
						TOKEN_SET(prev_string, string, str);
						free(val.val.string);
						memset(&val, 0, sizeof(val));
						val.vtype = vtype_undefined;
						continue;
					}
				}
				break;
		}
		if(val.vtype == vtype_undefined) {
			text = yyget_text(state->scanner);
			TOKEN_SET(&val, string, cli_strdup(text));
			abort();
		}
		add_token(state, &val);
		current->last_token = yv;
		memset(&val, 0, sizeof(val));
		val.vtype = vtype_undefined;
	}
}
コード例 #24
0
ファイル: perly.c プロジェクト: behnaaz/jerl
Perl_yyparse (pTHX_ int gramtype)
#endif
{
    dVAR;
    int yystate;
    int yyn;
    int yyresult;

    /* Lookahead token as an internal (translated) token number.  */
    int yytoken = 0;

    yy_parser *parser;	    /* the parser object */
    yy_stack_frame  *ps;   /* current parser stack frame */

#define YYPOPSTACK   parser->ps = --ps
#define YYPUSHSTACK  parser->ps = ++ps

    /* The variable used to return semantic value and location from the
      action routines: ie $$.  */
    YYSTYPE yyval;

#ifndef PERL_IN_MADLY_C
#  ifdef PERL_MAD
    if (PL_madskills)
        return madparse(gramtype);
#  endif
#endif

    YYDPRINTF ((Perl_debug_log, "Starting parse\n"));

    parser = PL_parser;

    ENTER;  /* force parser state cleanup/restoration before we return */
    SAVEPPTR(parser->yylval.pval);
    SAVEINT(parser->yychar);
    SAVEINT(parser->yyerrstatus);
    SAVEINT(parser->stack_size);
    SAVEINT(parser->yylen);
    SAVEVPTR(parser->stack);
    SAVEVPTR(parser->ps);

    /* initialise state for this parse */
    parser->yychar = gramtype;
    parser->yyerrstatus = 0;
    parser->stack_size = YYINITDEPTH;
    parser->yylen = 0;
    Newx(parser->stack, YYINITDEPTH, yy_stack_frame);
    ps = parser->ps = parser->stack;
    ps->state = 0;
    SAVEDESTRUCTOR_X(S_clear_yystack, parser);

    /*------------------------------------------------------------.
    | yynewstate -- Push a new state, which is found in yystate.  |
    `------------------------------------------------------------*/
yynewstate:

    yystate = ps->state;

    YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));

    parser->yylen = 0;

    {
        size_t size = ps - parser->stack + 1;

        /* grow the stack? We always leave 1 spare slot,
         * in case of a '' -> 'foo' reduction */

        if (size >= (size_t)parser->stack_size - 1) {
            /* this will croak on insufficient memory */
            parser->stack_size *= 2;
            Renew(parser->stack, parser->stack_size, yy_stack_frame);
            ps = parser->ps = parser->stack + size -1;

            YYDPRINTF((Perl_debug_log,
                       "parser stack size increased to %lu frames\n",
                       (unsigned long int)parser->stack_size));
        }
    }

    /* Do appropriate processing given the current state.  */
    /* Read a lookahead token if we need one and don't already have one.  */

    /* First try to decide what to do without reference to lookahead token.  */

    yyn = yypact[yystate];
    if (yyn == YYPACT_NINF)
        goto yydefault;

    /* Not known => get a lookahead token if don't already have one.  */

    /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
    if (parser->yychar == YYEMPTY) {
        YYDPRINTF ((Perl_debug_log, "Reading a token: "));
#ifdef PERL_IN_MADLY_C
        parser->yychar = PL_madskills ? madlex() : yylex();
#else
        parser->yychar = yylex();
#endif

#  ifdef EBCDIC
        if (parser->yychar >= 0 && parser->yychar < 255) {
            parser->yychar = NATIVE_TO_ASCII(parser->yychar);
        }
#  endif
    }

    if (parser->yychar <= YYEOF) {
        parser->yychar = yytoken = YYEOF;
        YYDPRINTF ((Perl_debug_log, "Now at end of input.\n"));
    }
    else {
        yytoken = YYTRANSLATE (parser->yychar);
        YYDSYMPRINTF ("Next token is", yytoken, &parser->yylval);
    }

    /* If the proper action on seeing token YYTOKEN is to reduce or to
      detect an error, take that action.  */
    yyn += yytoken;
    if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
        goto yydefault;
    yyn = yytable[yyn];
    if (yyn <= 0) {
        if (yyn == 0 || yyn == YYTABLE_NINF)
            goto yyerrlab;
        yyn = -yyn;
        goto yyreduce;
    }

    if (yyn == YYFINAL)
        YYACCEPT;

    /* Shift the lookahead token.  */
    YYDPRINTF ((Perl_debug_log, "Shifting token %s, ", yytname[yytoken]));

    /* Discard the token being shifted unless it is eof.  */
    if (parser->yychar != YYEOF)
        parser->yychar = YYEMPTY;

    YYPUSHSTACK;
    ps->state   = yyn;
    ps->val     = parser->yylval;
    ps->compcv  = (CV*)SvREFCNT_inc(PL_compcv);
    ps->savestack_ix = PL_savestack_ix;
#ifdef DEBUGGING
    ps->name    = (const char *)(yytname[yytoken]);
#endif

    /* Count tokens shifted since error; after three, turn off error
      status.  */
    if (parser->yyerrstatus)
        parser->yyerrstatus--;

    goto yynewstate;


    /*-----------------------------------------------------------.
    | yydefault -- do the default action for the current state.  |
    `-----------------------------------------------------------*/
yydefault:
    yyn = yydefact[yystate];
    if (yyn == 0)
        goto yyerrlab;
    goto yyreduce;


    /*-----------------------------.
    | yyreduce -- Do a reduction.  |
    `-----------------------------*/
yyreduce:
    /* yyn is the number of a rule to reduce with.  */
    parser->yylen = yyr2[yyn];

    /* If YYLEN is nonzero, implement the default value of the action:
      "$$ = $1".

      Otherwise, the following line sets YYVAL to garbage.
      This behavior is undocumented and Bison
      users should not rely upon it.  Assigning to YYVAL
      unconditionally makes the parser a bit smaller, and it avoids a
      GCC warning that YYVAL may be used uninitialized.  */
    yyval = ps[1-parser->yylen].val;

    YY_STACK_PRINT(parser);
    YY_REDUCE_PRINT (yyn);

    switch (yyn) {


#define dep() deprecate("\"do\" to call subroutines")

#ifdef PERL_IN_MADLY_C
#  define IVAL(i) (i)->tk_lval.ival
#  define PVAL(p) (p)->tk_lval.pval
#  define TOKEN_GETMAD(a,b,c) token_getmad((a),(b),(c))
#  define TOKEN_FREE(a) token_free(a)
#  define OP_GETMAD(a,b,c) op_getmad((a),(b),(c))
#  define IF_MAD(a,b) (a)
#  define DO_MAD(a) a
#  define MAD
#else
#  define IVAL(i) (i)
#  define PVAL(p) (p)
#  define TOKEN_GETMAD(a,b,c)
#  define TOKEN_FREE(a)
#  define OP_GETMAD(a,b,c)
#  define IF_MAD(a,b) (b)
#  define DO_MAD(a)
#  undef MAD
#endif

        /* contains all the rule actions; auto-generated from perly.y */
#include "perly.act"

    }

    {
        int i;
        for (i=0; i< parser->yylen; i++) {
            SvREFCNT_dec(ps[-i].compcv);
        }
    }

    parser->ps = ps -= (parser->yylen-1);

    /* Now shift the result of the reduction.  Determine what state
      that goes to, based on the state we popped back to and the rule
      number reduced by.  */

    ps->val     = yyval;
    ps->compcv  = (CV*)SvREFCNT_inc(PL_compcv);
    ps->savestack_ix = PL_savestack_ix;
#ifdef DEBUGGING
    ps->name    = (const char *)(yytname [yyr1[yyn]]);
#endif

    yyn = yyr1[yyn];

    yystate = yypgoto[yyn - YYNTOKENS] + ps[-1].state;
    if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == ps[-1].state)
        yystate = yytable[yystate];
    else
        yystate = yydefgoto[yyn - YYNTOKENS];
    ps->state = yystate;

    goto yynewstate;


    /*------------------------------------.
    | yyerrlab -- here on detecting error |
    `------------------------------------*/
yyerrlab:
    /* If not already recovering from an error, report this error.  */
    if (!parser->yyerrstatus) {
        yyerror ("syntax error");
    }


    if (parser->yyerrstatus == 3) {
        /* If just tried and failed to reuse lookahead token after an
              error, discard it.  */

        /* Return failure if at end of input.  */
        if (parser->yychar == YYEOF) {
            /* Pop the error token.  */
            SvREFCNT_dec(ps->compcv);
            YYPOPSTACK;
            /* Pop the rest of the stack.  */
            while (ps > parser->stack) {
                YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
                LEAVE_SCOPE(ps->savestack_ix);
                if (yy_type_tab[yystos[ps->state]] == toketype_opval
                        && ps->val.opval)
                {
                    YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
                    if (ps->compcv != PL_compcv) {
                        PL_compcv = ps->compcv;
                        PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
                    }
                    op_free(ps->val.opval);
                }
                SvREFCNT_dec(ps->compcv);
                YYPOPSTACK;
            }
            YYABORT;
        }

        YYDSYMPRINTF ("Error: discarding", yytoken, &parser->yylval);
        parser->yychar = YYEMPTY;

    }

    /* Else will try to reuse lookahead token after shifting the error
      token.  */
    goto yyerrlab1;


    /*----------------------------------------------------.
    | yyerrlab1 -- error raised explicitly by an action.  |
    `----------------------------------------------------*/
yyerrlab1:
    parser->yyerrstatus = 3;	/* Each real token shifted decrements this.  */

    for (;;) {
        yyn = yypact[yystate];
        if (yyn != YYPACT_NINF) {
            yyn += YYTERROR;
            if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
                yyn = yytable[yyn];
                if (0 < yyn)
                    break;
            }
        }

        /* Pop the current state because it cannot handle the error token.  */
        if (ps == parser->stack)
            YYABORT;

        YYDSYMPRINTF ("Error: popping", yystos[ps->state], &ps->val);
        LEAVE_SCOPE(ps->savestack_ix);
        if (yy_type_tab[yystos[ps->state]] == toketype_opval && ps->val.opval) {
            YYDPRINTF ((Perl_debug_log, "(freeing op)\n"));
            if (ps->compcv != PL_compcv) {
                PL_compcv = ps->compcv;
                PAD_SET_CUR_NOSAVE(CvPADLIST(PL_compcv), 1);
            }
            op_free(ps->val.opval);
        }
        SvREFCNT_dec(ps->compcv);
        YYPOPSTACK;
        yystate = ps->state;

        YY_STACK_PRINT(parser);
    }

    if (yyn == YYFINAL)
        YYACCEPT;

    YYDPRINTF ((Perl_debug_log, "Shifting error token, "));

    YYPUSHSTACK;
    ps->state   = yyn;
    ps->val     = parser->yylval;
    ps->compcv  = (CV*)SvREFCNT_inc(PL_compcv);
    ps->savestack_ix = PL_savestack_ix;
#ifdef DEBUGGING
    ps->name    ="<err>";
#endif

    goto yynewstate;


    /*-------------------------------------.
    | yyacceptlab -- YYACCEPT comes here.  |
    `-------------------------------------*/
yyacceptlab:
    yyresult = 0;
    for (ps=parser->ps; ps > parser->stack; ps--) {
        SvREFCNT_dec(ps->compcv);
    }
    parser->ps = parser->stack; /* disable cleanup */
    goto yyreturn;

    /*-----------------------------------.
    | yyabortlab -- YYABORT comes here.  |
    `-----------------------------------*/
yyabortlab:
    yyresult = 1;
    goto yyreturn;

yyreturn:
    LEAVE;	/* force parser stack cleanup before we return */
    return yyresult;
}
コード例 #25
0
bfd_boolean
ldfile_try_open_bfd (const char *attempt,
                     lang_input_statement_type *entry)
{
    entry->the_bfd = bfd_openr (attempt, entry->target);

    if (trace_file_tries)
    {
        if (entry->the_bfd == NULL)
            info_msg (_("attempt to open %s failed\n"), attempt);
        else
            info_msg (_("attempt to open %s succeeded\n"), attempt);
    }

    if (entry->the_bfd == NULL)
    {
        if (bfd_get_error () == bfd_error_invalid_target)
            einfo (_("%F%P: invalid BFD target `%s'\n"), entry->target);
        return FALSE;
    }

    /* Linker needs to decompress sections.  */
    entry->the_bfd->flags |= BFD_DECOMPRESS;

    /* If we are searching for this file, see if the architecture is
       compatible with the output file.  If it isn't, keep searching.
       If we can't open the file as an object file, stop the search
       here.  If we are statically linking, ensure that we don't link
       a dynamic object.

       In the code below, it's OK to exit early if the check fails,
       closing the checked BFD and returning FALSE, but if the BFD
       checks out compatible, do not exit early returning TRUE, or
       the plugins will not get a chance to claim the file.  */

    if (entry->search_dirs_flag || !entry->dynamic)
    {
        bfd *check;

        if (bfd_check_format (entry->the_bfd, bfd_archive))
            check = bfd_openr_next_archived_file (entry->the_bfd, NULL);
        else
            check = entry->the_bfd;

        if (check != NULL)
        {
            if (! bfd_check_format (check, bfd_object))
            {
                if (check == entry->the_bfd
                        && entry->search_dirs_flag
                        && bfd_get_error () == bfd_error_file_not_recognized
                        && ! ldemul_unrecognized_file (entry))
                {
                    int token, skip = 0;
                    char *arg, *arg1, *arg2, *arg3;
                    extern FILE *yyin;

                    /* Try to interpret the file as a linker script.  */
                    ldfile_open_command_file (attempt);

                    ldfile_assumed_script = TRUE;
                    parser_input = input_selected;
                    ldlex_both ();
                    token = INPUT_SCRIPT;
                    while (token != 0)
                    {
                        switch (token)
                        {
                        case OUTPUT_FORMAT:
                            if ((token = yylex ()) != '(')
                                continue;
                            if ((token = yylex ()) != NAME)
                                continue;
                            arg1 = yylval.name;
                            arg2 = NULL;
                            arg3 = NULL;
                            token = yylex ();
                            if (token == ',')
                            {
                                if ((token = yylex ()) != NAME)
                                {
                                    free (arg1);
                                    continue;
                                }
                                arg2 = yylval.name;
                                if ((token = yylex ()) != ','
                                        || (token = yylex ()) != NAME)
                                {
                                    free (arg1);
                                    free (arg2);
                                    continue;
                                }
                                arg3 = yylval.name;
                                token = yylex ();
                            }
                            if (token == ')')
                            {
                                switch (command_line.endian)
                                {
                                default:
                                case ENDIAN_UNSET:
                                    arg = arg1;
                                    break;
                                case ENDIAN_BIG:
                                    arg = arg2 ? arg2 : arg1;
                                    break;
                                case ENDIAN_LITTLE:
                                    arg = arg3 ? arg3 : arg1;
                                    break;
                                }
                                if (strcmp (arg, lang_get_output_target ()) != 0)
                                    skip = 1;
                            }
                            free (arg1);
                            if (arg2) free (arg2);
                            if (arg3) free (arg3);
                            break;
                        case NAME:
                        case LNAME:
                        case VERS_IDENTIFIER:
                        case VERS_TAG:
                            free (yylval.name);
                            break;
                        case INT:
                            if (yylval.bigint.str)
                                free (yylval.bigint.str);
                            break;
                        }
                        token = yylex ();
                    }
                    ldlex_popstate ();
                    ldfile_assumed_script = FALSE;
                    fclose (yyin);
                    yyin = NULL;
                    if (skip)
                    {
                        if (command_line.warn_search_mismatch)
                            einfo (_("%P: skipping incompatible %s "
                                     "when searching for %s\n"),
                                   attempt, entry->local_sym_name);
                        bfd_close (entry->the_bfd);
                        entry->the_bfd = NULL;
                        return FALSE;
                    }
                }
                goto success;
            }

            if (!entry->dynamic && (entry->the_bfd->flags & DYNAMIC) != 0)
            {
                einfo (_("%F%P: attempted static link of dynamic object `%s'\n"),
                       attempt);
                bfd_close (entry->the_bfd);
                entry->the_bfd = NULL;
                return FALSE;
            }

            if (entry->search_dirs_flag
                    && !bfd_arch_get_compatible (check, link_info.output_bfd,
                                                 command_line.accept_unknown_input_arch)
                    /* XCOFF archives can have 32 and 64 bit objects.  */
                    && ! (bfd_get_flavour (check) == bfd_target_xcoff_flavour
                          && bfd_get_flavour (link_info.output_bfd) == bfd_target_xcoff_flavour
                          && bfd_check_format (entry->the_bfd, bfd_archive)))
            {
                if (command_line.warn_search_mismatch)
                    einfo (_("%P: skipping incompatible %s "
                             "when searching for %s\n"),
                           attempt, entry->local_sym_name);
                bfd_close (entry->the_bfd);
                entry->the_bfd = NULL;
                return FALSE;
            }
        }
    }
success:
#ifdef ENABLE_PLUGINS
    /* If plugins are active, they get first chance to claim
       any successfully-opened input file.  We skip archives
       here; the plugin wants us to offer it the individual
       members when we enumerate them, not the whole file.  We
       also ignore corefiles, because that's just weird.  It is
       a needed side-effect of calling  bfd_check_format with
       bfd_object that it sets the bfd's arch and mach, which
       will be needed when and if we want to bfd_create a new
       one using this one as a template.  */
    if (bfd_check_format (entry->the_bfd, bfd_object)
            && plugin_active_plugins_p ()
            && !no_more_claiming)
    {
        int fd = open (attempt, O_RDONLY | O_BINARY);
        if (fd >= 0)
        {
            struct ld_plugin_input_file file;

            file.name = attempt;
            file.offset = 0;
            file.filesize = lseek (fd, 0, SEEK_END);
            file.fd = fd;
            plugin_maybe_claim (&file, entry);
        }
    }
#endif /* ENABLE_PLUGINS */

    /* It opened OK, the format checked out, and the plugins have had
       their chance to claim it, so this is success.  */
    return TRUE;
}
コード例 #26
0
ファイル: crossref.c プロジェクト: 18959263172/emacs-target
void
crossref(char *srcfile)
{
	int	i;
	int	length;		/* symbol length */
	int	entry_no;		/* function level of the symbol */
	int	token;			/* current token */
	struct stat st;

	if (! ((stat(srcfile, &st) == 0)
	       && S_ISREG(st.st_mode))) {
		cannotopen(srcfile);
		errorsfound = YES;
		return;
	}
	
	entry_no = 0;
	/* open the source file */
	if ((yyin = myfopen(srcfile, "r")) == NULL) {
		cannotopen(srcfile);
		errorsfound = YES;
		return;
	}
	filename = srcfile;	/* save the file name for warning messages */
	putfilename(srcfile);	/* output the file name */
	dbputc('\n');
	dbputc('\n');

	/* read the source file */
	initscanner(srcfile);
	fcnoffset = macrooffset = 0;
	symbols = 0;
	if (symbol == NULL) {
		symbol = mymalloc(msymbols * sizeof(struct symbol));
	}
	for (;;) {
		
		/* get the next token */
		switch (token = yylex()) {
		default:
			/* if requested, truncate C symbols */
			length = last - first;
			if (trun_syms == YES && length > 8 &&
			    token != INCLUDE && token != NEWFILE) {
				length = 8;
				last = first + 8;
			}
			/* see if the token has a symbol */
			if (length == 0) {
				savesymbol(token, entry_no);
				break;
			}
			/* update entry_no if see function entry */
			if (token == FCNDEF) {
				entry_no++;
			}
			/* see if the symbol is already in the list */
			for (i = 0; i < symbols; ++i) {
				if (length == symbol[i].length
				    && strncmp(my_yytext + first,
					       my_yytext + symbol[i].first,
					       length) == 0 
				    && entry_no == symbol[i].fcn_level
				    && token == symbol[i].type
				    ) {	/* could be a::a() */
					break;
				}
			}
			if (i == symbols) {	/* if not already in list */
				savesymbol(token, entry_no);
			}
			break;

		case NEWLINE:	/* end of line containing symbols */
			entry_no = 0;	/* reset entry_no for each line */
#ifdef USING_LEX
			--yyleng; 	/* remove the newline */
#endif
			putcrossref();	/* output the symbols and source line */
			lineno = myylineno;	/* save the symbol line number */
#ifndef USING_LEX
			/* HBB 20010425: replaced yyleng-- by this chunk: */
			if (my_yytext)
				*my_yytext = '\0';
			my_yyleng = 0;
#endif
			break;
			
		case LEXEOF:	/* end of file; last line may not have \n */
			
			/* if there were symbols, output them and the source line */
			if (symbols > 0) {
				putcrossref();
			}
			(void) fclose(yyin);	/* close the source file */

			/* output the leading tab expected by the next call */
			dbputc('\t');
			return;
		}
	}
}
コード例 #27
0
ファイル: y.tab.c プロジェクト: mdabrarniyazi/Compiler-Design
int
yyparse (void)
{
    int yystate;
    /* Number of tokens to shift before error messages enabled.  */
    int yyerrstatus;

    /* The stacks and their tools:
       'yyss': related to states.
       'yyvs': related to semantic values.

       Refer to the stacks through separate pointers, to allow yyoverflow
       to reallocate them elsewhere.  */

    /* The state stack.  */
    yytype_int16 yyssa[YYINITDEPTH];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;

    /* The semantic value stack.  */
    YYSTYPE yyvsa[YYINITDEPTH];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;

    YYSIZE_T yystacksize;

  int yyn;
  int yyresult;
  /* Lookahead token as an internal (translated) token number.  */
  int yytoken = 0;
  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;

#if YYERROR_VERBOSE
  /* Buffer for error messages, and its allocated size.  */
  char yymsgbuf[128];
  char *yymsg = yymsgbuf;
  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif

#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))

  /* The number of symbols on the RHS of the reduced rule.
     Keep to zero when no symbol should be popped.  */
  int yylen = 0;

  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = YYINITDEPTH;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY; /* Cause a token to be read.  */
  goto yysetstate;

/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
 yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed.  So pushing a state here evens the stacks.  */
  yyssp++;

 yysetstate:
  *yyssp = yystate;

  if (yyss + yystacksize - 1 <= yyssp)
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYSIZE_T yysize = yyssp - yyss + 1;

#ifdef yyoverflow
      {
        /* Give user a chance to reallocate the stack.  Use copies of
           these so that the &'s don't force the real ones into
           memory.  */
        YYSTYPE *yyvs1 = yyvs;
        yytype_int16 *yyss1 = yyss;

        /* Each stack pointer address is followed by the size of the
           data in use in that stack, in bytes.  This used to be a
           conditional around just the two extra args, but that might
           be undefined if yyoverflow is a macro.  */
        yyoverflow (YY_("memory exhausted"),
                    &yyss1, yysize * sizeof (*yyssp),
                    &yyvs1, yysize * sizeof (*yyvsp),
                    &yystacksize);

        yyss = yyss1;
        yyvs = yyvs1;
      }
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
      goto yyexhaustedlab;
# else
      /* Extend the stack our own way.  */
      if (YYMAXDEPTH <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (YYMAXDEPTH < yystacksize)
        yystacksize = YYMAXDEPTH;

      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
        if (! yyptr)
          goto yyexhaustedlab;
        YYSTACK_RELOCATE (yyss_alloc, yyss);
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
#  undef YYSTACK_RELOCATE
        if (yyss1 != yyssa)
          YYSTACK_FREE (yyss1);
      }
# endif
#endif /* no yyoverflow */

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;

      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
                  (unsigned long int) yystacksize));

      if (yyss + yystacksize - 1 <= yyssp)
        YYABORT;
    }

  YYDPRINTF ((stderr, "Entering state %d\n", yystate));

  if (yystate == YYFINAL)
    YYACCEPT;

  goto yybackup;

/*-----------.
| yybackup.  |
`-----------*/
yybackup:

  /* Do appropriate processing given the current state.  Read a
     lookahead token if we need one and don't already have one.  */

  /* First try to decide what to do without reference to lookahead token.  */
  yyn = yypact[yystate];
  if (yypact_value_is_default (yyn))
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token: "));
      yychar = yylex ();
    }

  if (yychar <= YYEOF)
    {
      yychar = yytoken = YYEOF;
      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else
    {
      yytoken = YYTRANSLATE (yychar);
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    }

  /* If the proper action on seeing token YYTOKEN is to reduce or to
     detect an error, take that action.  */
  yyn += yytoken;
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (yytable_value_is_error (yyn))
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }

  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  /* Shift the lookahead token.  */
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);

  /* Discard the shifted token.  */
  yychar = YYEMPTY;

  yystate = yyn;
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END

  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- Do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     '$$ = $1'.

     Otherwise, the following line sets YYVAL to garbage.
     This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
        case 2:
#line 24 "stage3.y" /* yacc.c:1646  */
    {exit(0);}
#line 1235 "y.tab.c" /* yacc.c:1646  */
    break;

  case 5:
#line 29 "stage3.y" /* yacc.c:1646  */
    {A[(yyvsp[-3].chid)-'a']=eval((yyvsp[-1].nptr));}
#line 1241 "y.tab.c" /* yacc.c:1646  */
    break;

  case 6:
#line 30 "stage3.y" /* yacc.c:1646  */
    {scanf("%d",&A[(yyvsp[-2].chid)-'a']);}
#line 1247 "y.tab.c" /* yacc.c:1646  */
    break;

  case 7:
#line 31 "stage3.y" /* yacc.c:1646  */
    { printf("%d\n",eval((yyvsp[-2].nptr)));}
#line 1253 "y.tab.c" /* yacc.c:1646  */
    break;

  case 8:
#line 33 "stage3.y" /* yacc.c:1646  */
    {(yyval.nptr)=mkopnode('+', (yyvsp[-2].nptr), (yyvsp[0].nptr));}
#line 1259 "y.tab.c" /* yacc.c:1646  */
    break;

  case 9:
#line 34 "stage3.y" /* yacc.c:1646  */
    {(yyval.nptr)=mkopnode('-',(yyvsp[-2].nptr), (yyvsp[0].nptr));}
#line 1265 "y.tab.c" /* yacc.c:1646  */
    break;

  case 10:
#line 35 "stage3.y" /* yacc.c:1646  */
    {(yyval.nptr)=mkopnode('*',(yyvsp[-2].nptr), (yyvsp[0].nptr));}
#line 1271 "y.tab.c" /* yacc.c:1646  */
    break;

  case 11:
#line 36 "stage3.y" /* yacc.c:1646  */
    {(yyval.nptr)=mkopnode('/',(yyvsp[-2].nptr), (yyvsp[0].nptr));}
#line 1277 "y.tab.c" /* yacc.c:1646  */
    break;

  case 12:
#line 37 "stage3.y" /* yacc.c:1646  */
    {(yyval.nptr)=(yyvsp[-1].nptr);}
#line 1283 "y.tab.c" /* yacc.c:1646  */
    break;

  case 13:
#line 38 "stage3.y" /* yacc.c:1646  */
    {(yyval.nptr)=mkleafnode(A[(yyvsp[0].chid)-'a']);}
#line 1289 "y.tab.c" /* yacc.c:1646  */
    break;

  case 14:
#line 40 "stage3.y" /* yacc.c:1646  */
    {(yyval.nptr)=mkleafnode((yyvsp[0].ival));}
#line 1295 "y.tab.c" /* yacc.c:1646  */
    break;


#line 1299 "y.tab.c" /* yacc.c:1646  */
      default: break;
    }
  /* User semantic actions sometimes alter yychar, and that requires
     that yytoken be updated with the new translation.  We take the
     approach of translating immediately before every use of yytoken.
     One alternative is translating here after every semantic action,
     but that translation would be missed if the semantic action invokes
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
     incorrect destructor might then be invoked immediately.  In the
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
     to an incorrect destructor call or verbose syntax error message
     before the lookahead is translated.  */
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);

  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);

  *++yyvsp = yyval;

  /* Now 'shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTOKENS];

  goto yynewstate;


/*--------------------------------------.
| yyerrlab -- here on detecting error.  |
`--------------------------------------*/
yyerrlab:
  /* Make sure we have latest lookahead translation.  See comments at
     user semantic actions for why this is necessary.  */
  yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);

  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;
#if ! YYERROR_VERBOSE
      yyerror (YY_("syntax error"));
#else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
                                        yyssp, yytoken)
      {
        char const *yymsgp = YY_("syntax error");
        int yysyntax_error_status;
        yysyntax_error_status = YYSYNTAX_ERROR;
        if (yysyntax_error_status == 0)
          yymsgp = yymsg;
        else if (yysyntax_error_status == 1)
          {
            if (yymsg != yymsgbuf)
              YYSTACK_FREE (yymsg);
            yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
            if (!yymsg)
              {
                yymsg = yymsgbuf;
                yymsg_alloc = sizeof yymsgbuf;
                yysyntax_error_status = 2;
              }
            else
              {
                yysyntax_error_status = YYSYNTAX_ERROR;
                yymsgp = yymsg;
              }
          }
        yyerror (yymsgp);
        if (yysyntax_error_status == 2)
          goto yyexhaustedlab;
      }
# undef YYSYNTAX_ERROR
#endif
    }



  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse lookahead token after an
         error, discard it.  */

      if (yychar <= YYEOF)
        {
          /* Return failure if at end of input.  */
          if (yychar == YYEOF)
            YYABORT;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = YYEMPTY;
        }
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */
  goto yyerrlab1;


/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR.  |
`---------------------------------------------------*/
yyerrorlab:

  /* Pacify compilers like GCC when the user code never invokes
     YYERROR and the label yyerrorlab therefore never appears in user
     code.  */
  if (/*CONSTCOND*/ 0)
     goto yyerrorlab;

  /* Do not reclaim the symbols of the rule whose action triggered
     this YYERROR.  */
  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);
  yystate = *yyssp;
  goto yyerrlab1;


/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
`-------------------------------------------------------------*/
yyerrlab1:
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */

  for (;;)
    {
      yyn = yypact[yystate];
      if (!yypact_value_is_default (yyn))
        {
          yyn += YYTERROR;
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }

      /* Pop the current state because it cannot handle the error token.  */
      if (yyssp == yyss)
        YYABORT;


      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      YYPOPSTACK (1);
      yystate = *yyssp;
      YY_STACK_PRINT (yyss, yyssp);
    }

  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END


  /* Shift the error token.  */
  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);

  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturn;

/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturn;

#if !defined yyoverflow || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here.  |
`-------------------------------------------------*/
yyexhaustedlab:
  yyerror (YY_("memory exhausted"));
  yyresult = 2;
  /* Fall through.  */
#endif

yyreturn:
  if (yychar != YYEMPTY)
    {
      /* Make sure we have latest lookahead translation.  See comments at
         user semantic actions for why this is necessary.  */
      yytoken = YYTRANSLATE (yychar);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  /* Do not reclaim the symbols of the rule whose action triggered
     this YYABORT or YYACCEPT.  */
  YYPOPSTACK (yylen);
  YY_STACK_PRINT (yyss, yyssp);
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      YYPOPSTACK (1);
    }
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif
#if YYERROR_VERBOSE
  if (yymsg != yymsgbuf)
    YYSTACK_FREE (yymsg);
#endif
  return yyresult;
}
コード例 #28
0
ファイル: yydriver.cpp プロジェクト: ABratovic/open-watcom-v2
int YYPARSER::yyparse()
//---------------------
{
  int yypnum;
  int yyi, yyk, yylhs, yyaction;
  int yytoken;
  YYSTYPE yys[MAXDEPTH];
  YYSTYPE *yysp;
  YYSTYPE yyv[MAXDEPTH];
  YYSTYPE *yyvp;
  int yyerrflag;

  yyerrflag = 0;
  yyaction = 0;
  yysp = yys;
  yyvp = yyv;
  *yysp = YYSTART;
  yytoken = yylex();
  for(;;){
yynewact:
      yyk = *yysp;
      while( (yyi = yyk + yytoken) < 0 || yyi >= YYUSED || yychktab[yyi] != yytoken )
          if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN )
              goto yycheck1;
          else
              yyk = yyacttab[yyi];
      yyaction = yyacttab[yyi];
      if( yyaction == YYNOACTION ){
yycheck1:
          yyk = *yysp;
          while( (yyi = yyk + YYDTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYDTOKEN )
              if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN )
                  goto yycheck2;
              else
                  yyk = yyacttab[yyi];
          yyaction = yyacttab[yyi];
          if( yyaction == YYNOACTION ){
yycheck2:
              switch( yyerrflag ){
                case 0:
                  yyerror( "syntax error" );
                  //Never used
                  //yyerrlab:
                case 1:
                case 2:
                  yyerrflag = 3;
                  while( yysp >= yys ){
                      yyk = *yysp;
                      while( (yyi = yyk + YYETOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYETOKEN )
                          if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN )
                              goto continu;
                          else
                              yyk = yyacttab[yyi];
                      yyaction = yyacttab[yyi];
                      if( yyaction < YYUSED ){
                          *++yysp = yyaction;
                          ++yyvp;
                          goto yynewact;
                      };
                      continu:;
                      --yysp;
                      --yyvp;
                  };
                  YYABORT;
                case 3:
                  if( yytoken == 0 ) /* EOF token */
                      YYABORT;
                  yytoken = yylex();
                  goto yynewact;
              };
          };
      };
      if( yyaction < YYUSED ){
          if( yyaction == YYSTOP ){
              YYACCEPT;
          } else {
              *++yysp = yyaction;
              *++yyvp = yylval;
              if( yyerrflag )
                  --yyerrflag;
              yytoken = yylex();
          };
      } else {
          yypnum = yyaction - YYUSED;
          yyi = yyplentab[yypnum];
          yysp -= yyi;
          yyvp -= yyi;
          yylhs = yyplhstab[yypnum];
          if( yysp < yys ){
              yyerror( "stack underflow\n" );
              YYABORT;
          };
          yyk = *yysp;
          while( (yyi = yyk + yylhs) < 0 || yyi >= YYUSED || yychktab[yyi] != yylhs ){
              if( (yyi = yyk + YYPTOKEN) < 0 || yyi >= YYUSED || yychktab[yyi] != YYPTOKEN ){
                  yyerror( "missing nonterminal\n" );
                  YYABORT;
              };
              yyk = yyacttab[yyi];
          };
          *++yysp = yyacttab[yyi];
          ++yyvp;
          switch( yypnum ){

            default:
              yyval = yyvp[0];
          };
          *yyvp = yyval;
      };
  };
}
コード例 #29
0
ファイル: token.c プロジェクト: pauley/pcc
int
yylex()
{
	static int ifdef, noex;
	struct symtab *nl;
	int ch, c2;

	while ((ch = sloscan()) == WSPACE)
		;
	if (ch < 128 && spechr[ch] & C_2)
		c2 = inpch();
	else
		c2 = 0;

#define	C2(a,b,c) case a: if (c2 == b) return c; break
	switch (ch) {
	C2('=', '=', EQ);
	C2('!', '=', NE);
	C2('|', '|', OROR);
	C2('&', '&', ANDAND);
	case '<':
		if (c2 == '<') return LS;
		if (c2 == '=') return LE;
		break;
	case '>':
		if (c2 == '>') return RS;
		if (c2 == '=') return GE;
		break;
	case '+':
	case '-':
		if (ch == c2)
			badop("");
		break;

	case '/':
		if (Cflag == 0 || c2 != '*')
			break;
		/* Found comment that need to be skipped */
		for (;;) {
			ch = inpch();
		c1:	if (ch != '*')
				continue;
			if ((ch = inpch()) == '/')
				break;
			goto c1;
		}
		return yylex();

	case NUMBER:
		if (yytext[0] == '\'') {
			yylval.node.op = NUMBER;
			yylval.node.nd_val = charcon((usch *)yytext);
		} else
			cvtdig(yytext[0] != '0' ? 10 :
			    yytext[1] == 'x' || yytext[1] == 'X' ? 16 : 8);
		return NUMBER;

	case IDENT:
		if (strcmp(yytext, "defined") == 0) {
			ifdef = 1;
			return DEFINED;
		}
		nl = lookup((usch *)yytext, FIND);
		if (ifdef) {
			yylval.node.nd_val = nl != NULL;
			ifdef = 0;
		} else if (nl && noex == 0) {
			usch *c, *och = stringbuf;

			c = gotident(nl);
			unch(1);
			unpstr(c);
			stringbuf = och;
			noex = 1;
			return yylex();
		} else {
			yylval.node.nd_val = 0;
		}
		yylval.node.op = NUMBER;
		return NUMBER;
	case 1: /* WARN */
		noex = 0;
		return yylex();
	default:
		return ch;
	}
	unch(c2);
	return ch;
}
コード例 #30
0
ファイル: main.c プロジェクト: QiuLihua83/unix_src_v7
main(){
yylex();
exit(0);
}