Exemple #1
0
void yyparser::yydestructpop(int num)
{
	yyassert(num >= 0);
	yyassert(yytop - num >= -1);

	if (yydestructorptr != NULL) {
		while (num > 0) {
			yystack_t state = yypeek();
			int action = yydestructorptr[state];
			if (action != -1) {
				// user actions in here
				memcpy(yyvalptr, &((char YYFAR*)yyattributestackptr)
					[yytop * yyattribute_size], yyattribute_size);

				yyaction(action);

				memcpy(&((char YYFAR*)yyattributestackptr)
					[yytop * yyattribute_size], yyvalptr, yyattribute_size);
			}
			yypop(1);
			num--;
		}
	}
	else {
		yypop(num);
	}
}
Exemple #2
0
void yyfparser::yydestructclearin()
{
	if (yylookahead) {
		// clean up any token attributes
		if (yytokendestptr != NULL) {
			int index = yytokendestbase + yychar;
			if (index >= 0 && index < yytokendest_size) {
				int action = yytokendestptr[index];
				if (action != -1) {
					// user actions in here
					memcpy(yyvalptr, yylvalptr, yyattribute_size);

					yyaction(action);

					memcpy(yylvalptr, yyvalptr, yyattribute_size);
				}
			}
		}
		yylookahead = 0;
	}
}
Exemple #3
0
int yycparser::yywork()
{
    int errorpop = 0;
    while (1) {
        yystack_t state = yypeek();			// get top state

        int index = yycstateaction[state];
        while (1) {
            if (yyctokenaction[index].token == YYTK_ALL) {
                if (yyctokenaction[index].type == YYAT_DEFAULT) {
                    state = yyctokenaction[index].sr;
                    index = yycstateaction[state];
                    continue;
                }
                break;
            }

            if (!yylookahead) {
                yychar = yygettoken();
                if (yychar < 0) {
                    yychar = 0;
                }
                yylookahead = 1;
#ifdef YYDEBUG
                yydgettoken(yychar);
#endif
            }
            if (yyctokenaction[index].token == yychar) {
                break;
            }
            index++;
        }
        unsigned char type = yyctokenaction[index].type;
        short sr = yyctokenaction[index].sr;

        // action
        switch (type) {
        case YYAT_SHIFT:
#ifdef YYDEBUG
            yydshift(yychar);
#endif
            if (yyskip > 0) {
                yysetskip(yyskip - 1);
            }
            if (!yypush(sr)) {
#ifdef YYDEBUG
                yydabort();
#endif
                if (yywipeflg) {
                    yywipe();	// clean up
                }
                return 1;
            }
            memcpy(&((char YYFAR*)yyattributestackptr)[yytop * yyattribute_size],
                   yylvalptr, yyattribute_size);
            yylookahead = 0;
            continue;		// go to top of while loop
        case YYAT_REDUCE:
#ifdef YYDEBUG
            yydreduce(sr);
#endif
            yyretireflg = 0;
            if (yyreduction[sr].action != -1) {
                // user actions in here
                if (yyreduction[sr].length > 0) {
                    memcpy(yyvalptr, &((char YYFAR*)yyattributestackptr)
                           [(yytop + 1 - yyreduction[sr].length) * yyattribute_size],
                           yyattribute_size);
                }

                yyerrorflg = 0;
                yyexitflg = 0;
                yyaction(yyreduction[sr].action);

                // check for special user requected actions
                if (yyexitflg) {
#ifdef YYDEBUG
                    yydexit(yyexitcode);
#endif
                    return yyexitcode;
                }
                if (yyerrorflg) {
                    errorpop = yyerrorpop;
#ifdef YYDEBUG
                    yydthrowerror(yyerrorpop);
#endif
                    yyerrorcount++;
                    break;		// go to error handler
                }
            }

            yypop(yyreduction[sr].length);
            {
                yystack_t state = yypeek();       // get top state

                int index = yycnontermgoto[yyreduction[sr].rule];
                while (yycstategoto[index].current != YYST_ALL &&
                        yycstategoto[index].current != state) {
                    index++;
                }
                short next = yycstategoto[index].next;
                assert(next != YYST_ERROR);

                if (!yypush(next)) {
#ifdef YYDEBUG
                    yydabort();
#endif
                    if (yywipeflg) {
                        yywipe();	// clean up
                    }
                    return 1;
                }
            }
            if (yyreduction[sr].action != -1) {
                memcpy(&((char YYFAR*)yyattributestackptr)[yytop * yyattribute_size],
                       yyvalptr, yyattribute_size);
            }
            if (yyretireflg) {
#ifdef YYDEBUG
                yydretire(yyretirecode);
#endif
                return yyretirecode;
            }
            continue;		// go to top of while loop
        case YYAT_ERROR:
#ifdef YYDEBUG
            yydsyntaxerror();
#endif
            if (yyskip == 0) {
                yyerrorcount++;
                yysyntaxerror();
            }
            break;		// go to error handler
        default:
            yyassert(type == YYAT_ACCEPT);
#ifdef YYDEBUG
            yydaccept();
#endif
            return 0;
        }

        // error handler
        if (yyskip < 3 || yyerrorpop > 0) {
#ifdef YYDEBUG
            yydattemptrecovery();
#endif
            yypopflg = 0;		// clear flag
            while (yytop >= 0) {
                state = yypeek();			// get top state
                index = yycstateaction[state];
                while (1) {
                    if (yyctokenaction[index].token == YYTK_ALL) {
                        if (yyctokenaction[index].type == YYAT_DEFAULT) {
                            state = yyctokenaction[index].sr;
                            index = yycstateaction[state];
                            continue;
                        }
                        break;
                    }
                    if (yyctokenaction[index].token == YYTK_ERROR) {
                        break;
                    }
                    index++;
                }
                type = yyctokenaction[index].type;
                sr = yyctokenaction[index].sr;

                if (type == YYAT_SHIFT) {
                    if (errorpop <= 0) {
#ifdef YYDEBUG
                        yydshift(YYTK_ERROR);
#endif
                        if (!yypush(sr)) {
#ifdef YYDEBUG
                            yydabort();
#endif
                            if (yywipeflg) {
                                yywipe();	// clean up
                            }
                            return 1;
                        }
                        yysetskip(3);		// skip 3 erroneous characters
                        break;
                    }
                    errorpop--;
                }

                yypopflg = 1;

                // clean up any symbol attributes
                if (yydestructorptr != NULL) {
                    state = yypeek();
                    int action = yydestructorptr[state];
                    if (action != -1) {
                        // user actions in here
                        memcpy(yyvalptr, &((char YYFAR*)yyattributestackptr)
                               [yytop * yyattribute_size], yyattribute_size);

                        yyaction(action);

                        memcpy(&((char YYFAR*)yyattributestackptr)
                               [yytop * yyattribute_size], yyvalptr, yyattribute_size);
                    }
                }
                yypop(1);
                if (yytop < 0) {
#ifdef YYDEBUG
                    yydabort();
#endif
                    if (yywipeflg) {
                        yywipe();	// clean up
                    }
                    return 1;
                }
            }
        }
        else {
            if (yylookahead) {
                if (yychar != 0) {
#ifdef YYDEBUG
                    yyddiscard(yychar);
#endif
                    yydiscard(yychar);

                    // clean up any token attributes
                    if (yyctokendestptr != NULL) {
                        const yyctokendest_t YYNEARFAR *tokendestptr = yyctokendestptr;
                        while (tokendestptr->token != 0) {
                            if (tokendestptr->token == yychar) {
                                // user actions in here
                                memcpy(yyvalptr, yylvalptr, yyattribute_size);

                                yyaction(tokendestptr->action);

                                memcpy(yylvalptr, yyvalptr, yyattribute_size);
                                break;
                            }
                            tokendestptr++;
                        }
                    }

                    yylookahead = 0;	// skip erroneous character
                }
                else {
#ifdef YYDEBUG
                    yydabort();
#endif
                    if (yywipeflg) {
                        yywipe();	// clean up
                    }
                    return 1;
                }
            }
        }
    }
}
int
yyparse (void)
{
  register int yystate;
  register int yyn;
  register short *yyssp;
  register short *yyrq0;
  register short *yyptr;
  register YYSTYPE *yyvsp;

  int yylen;
  YYLTYPE *yylsp;
  short *yyrq1;
  short *yyrq2;

  yystate = 0;
  yyssp = yyss - 1;
  yyvsp = yyvs - 1;
  yylsp = yyls - 1;
  yyrq0 = yyrq;
  yyrq1 = yyrq0;
  yyrq2 = yyrq0;

  yychar = yylex();
  if (yychar < 0)
    yychar = 0;
  else yychar = YYTRANSLATE(yychar);

yynewstate:

  if (yyssp >= yyss + YYMAXDEPTH - 1)
    {
      yyabort("Parser Stack Overflow");
      YYABORT;
    }

  *++yyssp = yystate;

yyresume:

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

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

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

  yystate = yyn;

  yyptr = yyrq2;
  while (yyptr != yyrq1)
    {
      yyn = *yyptr++;
      yylen = yyr2[yyn];
      yyvsp -= yylen;
      yylsp -= yylen;

      yyguard(yyn, yyvsp, yylsp);
      if (yyerror)
	goto yysemerr;

      yyaction(yyn, yyvsp, yylsp);
      *++yyvsp = yyval;

      yylsp++;
      if (yylen == 0)
	{
	  yylsp->timestamp = timeclock;
	  yylsp->first_line = yytloc.first_line;
	  yylsp->first_column = yytloc.first_column;
	  yylsp->last_line = (yylsp-1)->last_line;
	  yylsp->last_column = (yylsp-1)->last_column;
	  yylsp->text = 0;
	}
      else
	{
	  yylsp->last_line = (yylsp+yylen-1)->last_line;
	  yylsp->last_column = (yylsp+yylen-1)->last_column;
	}
	  
      if (yyptr == yyrq + YYMAXRULES)
        yyptr = yyrq;
    }

  if (yystate == YYFINAL)
    YYACCEPT;

  yyrq2 = yyptr;
  yyrq1 = yyrq0;

  *++yyvsp = yytval;
  *++yylsp = yytloc;
  yytval = yylval;
  yytloc = yylloc;
  yyget ();

  goto yynewstate;

yydefault:

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

yyreduce:

  *yyrq0++ = yyn;

  if (yyrq0 == yyrq + YYMAXRULES)
    yyrq0 = yyrq;

  if (yyrq0 == yyrq2)
    {
      yyabort("Parser Rule Queue Overflow");
      YYABORT;
    }

  yyssp -= yyr2[yyn];
  yyn = yyr1[yyn];

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

  goto yynewstate;

yysemerr:
  *--yyptr = yyn;
  yyrq2 = yyptr;
  yyvsp += yyr2[yyn];

yyerrlab:

  yygssp = yyssp;
  yygvsp = yyvsp;
  yyglsp = yylsp;
  yyrestore(yyrq0, yyrq2);
  yyrecover();
  yystate = *yygssp;
  yyssp = yygssp;
  yyvsp = yygvsp;
  yyrq0 = yyrq;
  yyrq1 = yyrq0;
  yyrq2 = yyrq0;
  goto yyresume;
}
Exemple #5
0
int yyclexer::yylex()
{
	while (1) {
		int state = 1 + yystart;
		if (yyeol) {
			state++;
		}
	
		// yymore
		if (yymoreflg) {
			yymoreflg = 0;		// clear flag
		}
		else {
			yyleng = 0;
			yyoldeol = yyeol;
		}
		int oldleng = yyleng;

		// look for a string
		do {
			// get input character (lookahead character)
			int ch = yyinput();
			yyassert(ch >= 0 && ch <= UCHAR_MAX || ch == EOF);
			if (ch == EOF) {
				break;
			}
			
			// check for possible overflow
			if (yyleng == yytext_size) {
				do {
					if (yytextgrow) {
						if (yytext_size != 0) {
							int size = yytext_size * 2;
							if (size / 2 == yytext_size) {		// overflow check
								if (yysettextsize(size)) {
									break;
								}
							}
						}
						else {
							if (yysettextsize(100)) {
								break;
							}
						}
					}
					yytextoverflow();
					exit(EXIT_FAILURE);
				}
				while (0);
			}

			// look for a transition
			int index = yystate[state].base;
			while (1) {
				if (yyctransition[index].next == 0) {
					state = yystate[state].def;
					if (state <= 0) {
						if (state < 0) {
							if (ch >= 0 && ch <= 0xff) {
								state = -state;
							}
							else {
								state = 0;
							}
						}
						break;
					}
				}
				if (ch >= yyctransition[index].first &&
					ch <= yyctransition[index].last) {
					state = yyctransition[index].next;
					break;
				}
				index++;
			}

			int leng = yyleng;		// slightly more efficient code
			yytext[leng] = (char)ch;
			yystatebuf[leng] = state;
			leng++;
			yyleng = leng;
		}
		while (state != 0 && (yystate[state].def != 0 || yystate[state].base != 0));

		// now find a match
		if (yyleng > oldleng) {
			int rejectmatch = 0;
			while (1) {
				int match = yystate[yystatebuf[yyleng - 1]].match;
				if (rejectmatch != 0) {
					if (match < 0) {
						int index = -match;
						do {
							match = yymatch[index++];
						}
						while (match > 0 && match <= rejectmatch);
					}
					else {
						if (match == rejectmatch) {
							match = 0;
						}
					}
					rejectmatch = 0;
				}
				else {
					if (match < 0) {
						match = yymatch[-match];
					}
				}
				if (match > 0) {
					// check for backup
					if (yybackup[match]) {
						while (yyleng > oldleng) {
							int index = yystate[yystatebuf[yyleng - 1]].match;
							if (index < 0) {
								if (yyback(&yymatch[-index], -match)) {
									break;	// found an expression
								}
							}
							yyleng--;
							yyunput((unsigned char)yytext[yyleng]);
						}
					}
					yytext[yyleng] = '\0';
#ifdef YYDEBUG
					yydmatch(match);
#endif
					yyrejectflg = 0;		// clear flag
					int rejectleng = yyleng;

					if (yyleng > 0) {
						yyeol = (unsigned char)(yytext[yyleng - 1] == '\n');
					}
					else {
						yyeol = yyoldeol;
					}

					// perform user action
					int token = yyaction(match);

					if (yyreturnflg) {
						return token;
					}
					if (!yyrejectflg) {
						break;
					}
					if (rejectleng == yyleng) {
						rejectmatch = match;
					}
				}
				else if (yyleng > oldleng + 1) {
					yyleng--;
					yyunput((unsigned char)yytext[yyleng]);
				}
				else {
					yyeol = (unsigned char)(yytext[0] == '\n');
					yyoutput(yytext[0]);	// non-matched character
					break;
				}
			}
		}
		else {
			yyassert(yyleng == oldleng);

			// handles <<EOF>> rules
			int index = 0;
			int match = yystate[state].match;
			if (match < 0) {
				index = -match;
				match = yymatch[index++];
			}
			while (match > 0) {
				yytext[yyleng] = '\0';
#ifdef YYDEBUG
				yydmatch(match);
#endif
				yyrejectflg = 0;		// clear flag

				// perform user action
				int token = yyaction(match);

				if (yyreturnflg) {
					return token;
				}
				if (!yyrejectflg) {
					break;
				}

				if (index == 0) {
					break;
				}
				match = yymatch[index++];
			}

			if (yywrap()) {
				yyoldeol = 1;
				yyeol = 1;
				yystart = 0;
				return 0;			// eof reached
			}
		}
	}
}