int yyreject(void) { for(; yylsp < yyolsp; yylsp++) yytext[yyleng++] = yyinput(); if(*yyfnd > 0) return yyracc(*yyfnd++); while(yylsp-- > yylstate) { yyunput(yytext[yyleng-1]); yytext[--yyleng] = 0; if(*yylsp != 0 && (yyfnd = (*yylsp)->yystops) && *yyfnd > 0) return yyracc(*yyfnd++); } if(yytext[0] == 0) return 0; yyoutput(yyprevious = yyinput()); yyleng = 0; return -1; }
static int input (void) #endif { int c; *(yy_c_buf_p) = (yy_hold_char); if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) /* This was really a NUL. */ *(yy_c_buf_p) = '\0'; else { /* need more input */ int offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() * sees that we've accumulated a * token and flags that we need to * try matching the token before * proceeding. But for input(), * there's no matching to consider. * So convert the EOB_ACT_LAST_MATCH * to EOB_ACT_END_OF_FILE. */ /* Reset buffer status. */ yyrestart(yyin ); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { if ( yywrap( ) ) return EOF; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; #ifdef __cplusplus return yyinput(); #else return input(); #endif } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + offset; break; } } } c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ *(yy_c_buf_p) = '\0'; /* preserve yytext */ (yy_hold_char) = *++(yy_c_buf_p); return c; }
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 } } } }
JBoolean CBPerlScanner::SlurpQuoted ( const JSize count, const JCharacter* suffixList ) { assert( count > 0 ); const int startChar = yyinput(); if (startChar == EOF || startChar == 0) { return kJFalse; } itsCurrentRange.last++; int endChar = startChar; if (startChar == '(') { endChar = ')'; } else if (startChar == '<') { endChar = '>'; } else if (startChar == '[') { endChar = ']'; } else if (startChar == '{') { endChar = '}'; } JSize remainder = count; while (1) { int c = yyinput(); if (c == EOF || c == 0) { return kJFalse; } itsCurrentRange.last++; if (startChar != endChar && c == startChar) { remainder++; } else if (c == endChar) // check for endChar before '\\' because qq\abc\ is legal { if (remainder > 0) { remainder--; } if (remainder == 0) { while (1) // slurp in characters in suffixList { c = yyinput(); if (c == EOF || c == 0) { return kJTrue; } else if (strchr(suffixList, c) == NULL) { yyunput(c, yytext); return kJTrue; } itsCurrentRange.last++; } } else if (count > 1 && remainder < count) { remainder--; // compensate for extra openChar in s(a)(b)g } } else if (c == '\\') { c = yyinput(); if (c == EOF || c == 0) { return kJFalse; } itsCurrentRange.last++; } } }