#define YY_DEFAULT_ACTION ECHO; /* A lexical scanner generated by pclex */ #define YY_END_TOK 0 #define YY_NEW_FILE -1 #define YY_DO_DEFAULT -2 #ifndef BUFSIZ #include #endif #define F_BUFSIZ BUFSIZ #define YY_BUF_SIZE (F_BUFSIZ * 2) #define YY_BUF_MAX (YY_BUF_SIZE - 1) #ifndef YY_MAX_LINE #define YY_MAX_LINE F_BUFSIZ #endif #define YY_BUF_LIM (YY_BUF_MAX - YY_MAX_LINE) #define ECHO (void) fwrite( (unsigned char *) yytext, yyleng, 1, yyout ) #define YY_INPUT(buf,result,max_size) \ if ( ( result = fread((unsigned char *) buf, sizeof(unsigned char), max_size, yyin) ) < 0 )\ YY_FATAL_ERROR( "L0048: fread() in PCLEX scanner failed" ); #define YY_NULL 0 #define YY_OUTPUT(c) fputc(c, yyout); #define YY_FATAL_ERROR(msg) \ { \ fputs(msg, stderr); \ putc('\n', stderr); \ exit(1); \ } #define YY_FIRST_CHAR yy_ch_buf[yy_b_buf_p] #define yywrap() 1 #define BEGIN yy_start = 1 + #define YY_SET_BOL(array,pos) array[pos - 1] = '\n'; #define YY_DECL int yylex() #define yyless(n) \ { \ YY_DO_BEFORE_SCAN; \ yy_c_buf_p = yy_b_buf_p + (n) - 1; \ YY_DO_BEFORE_ACTION; \ } #define YY_BREAK break; #define YY_INIT \ { \ yyleng = yy_c_buf_p = yy_e_buf_p = 0; \ yy_hold_char = yy_ch_buf[yy_c_buf_p] = '\n'; \ yytext = &yy_ch_buf[yy_c_buf_p]; \ yy_saw_eof = 0; \ } #define YY_LENG (yy_c_buf_p - yy_b_buf_p + 1) #define YY_DO_BEFORE_SCAN \ yytext[yyleng] = yy_hold_char; #define YY_DO_BEFORE_ACTION \ yytext = &yy_ch_buf[yy_b_buf_p]; \ yyleng = YY_LENG; \ yy_hold_char = yytext[yyleng]; \ yytext[yyleng] = '\0'; #define REJECT \ { \ YY_DO_BEFORE_SCAN; \ yy_c_buf_p = yy_full_match; \ ++yy_lp; \ goto find_rule; \ } static int input(void); static void unput(unsigned char); # line 1 "wc.l" #define INITIAL 0 /* * word count, WC - the program. simple standalone PCLEX application. */ # line 6 "wc.l" #include static unsigned nchar = 0; /* # of characters in file */ static unsigned nword = 0; /* # of words in file */ static unsigned nline = 1; /* # of lines in file */ # line 12 "wc.l" #define YY_JAM 7 #define YY_JAM_BASE 546 static char a[9] = { 0, 2, 3, 4, 3, 4, 1, 4, 2 } ; static char l[9] = { 0, -2, -2, 1, 4, 6, 8, 9, 9 } ; static short int b[10] = { 0, 0, 2, 0, 546, 546, 0, 546, 34, 290 } ; static short int d[10] = { 0, 8, 8, 9, 7, 7, 9,-32767, 7, 7 } ; static short int n[803] = { 0, 7, 7, 7, 7, 7, 7, 7, 7, 4, 5, 4, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 4, 7, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 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, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 } ; FILE *yyin = stdin, *yyout = stdout; static int yy_start, yy_b_buf_p, yy_c_buf_p, yy_e_buf_p; static int yy_saw_eof = 1, yy_init = 1; static unsigned char yy_ch_buf[YY_BUF_SIZE + 1]; static int yy_st_buf[YY_BUF_SIZE]; static unsigned char yy_hold_char; unsigned char *yytext; int yyleng; static int input(void) { int c; YY_DO_BEFORE_SCAN if (yy_c_buf_p == yy_e_buf_p) { int yy_n_chars; if (yy_saw_eof) { if (yywrap()) return (EOF); YY_INIT; } yy_b_buf_p = 0; YY_INPUT(yy_ch_buf, yy_n_chars, YY_MAX_LINE); if (yy_n_chars == YY_NULL) { yy_saw_eof = 1; if (yywrap()) return (EOF); YY_INIT; return (input()); } yy_c_buf_p = -1; yy_e_buf_p = yy_n_chars - 1; } c = yy_ch_buf[++yy_c_buf_p]; YY_DO_BEFORE_ACTION; return (c); } static void unput(unsigned char c) { YY_DO_BEFORE_SCAN; if (yy_c_buf_p == 0) { register int i; register int yy_buf_pos = YY_BUF_MAX; for (i = yy_e_buf_p; i >= yy_c_buf_p; --i) { yy_ch_buf[yy_buf_pos] = yy_ch_buf[i]; yy_st_buf[yy_buf_pos] = yy_st_buf[i]; --yy_buf_pos; } yy_c_buf_p = YY_BUF_MAX - yy_e_buf_p; yy_e_buf_p = YY_BUF_MAX; } if (yy_c_buf_p <= 0) YY_FATAL_ERROR("L0027: PCLEX scanner push-back overflow"); if (yy_c_buf_p >= yy_b_buf_p && yy_ch_buf[yy_c_buf_p] == '\n') yy_ch_buf[yy_c_buf_p - 1] = '\n'; yy_ch_buf[yy_c_buf_p--] = c; YY_DO_BEFORE_ACTION; } YY_DECL { register int yy_curst; register unsigned char yy_sym; int yy_n_chars, yy_lp, yy_iii, yy_buf_pos, yy_act, yy_full_match; if (yy_init) { YY_INIT; yy_start = 1; yy_init = 0; } goto get_next_token; do_action: yy_full_match = yy_c_buf_p; for ( ; ; ) { YY_DO_BEFORE_ACTION switch (yy_act) { case 1: # line 14 "wc.l" nchar += 2, ++nline; /* line boundary in MS-DOS is CR LF */ YY_BREAK case 2: # line 16 "wc.l" ++nword, nchar += yyleng; YY_BREAK case 3: # line 18 "wc.l" ++nchar; YY_BREAK case 4: # line 20 "wc.l" YY_DEFAULT_ACTION; YY_BREAK case YY_NEW_FILE: break; case YY_END_TOK: return (YY_END_TOK); default: YY_FATAL_ERROR("L0028: fatal PCLEX scanner internal error"); } get_next_token: YY_DO_BEFORE_SCAN yy_curst = yy_start; if (yy_ch_buf[yy_c_buf_p] == '\n') ++yy_curst; yy_b_buf_p = yy_c_buf_p + 1; do { if (yy_c_buf_p == yy_e_buf_p) { if (yy_e_buf_p >= YY_BUF_LIM) { yy_n_chars = yy_e_buf_p - yy_b_buf_p; if (yy_n_chars >= 0) { for (yy_iii = 0; yy_iii <= yy_n_chars; ++yy_iii) { yy_buf_pos = yy_b_buf_p + yy_iii; yy_ch_buf[yy_iii] = yy_ch_buf[yy_buf_pos]; yy_st_buf[yy_iii] = yy_st_buf[yy_buf_pos]; } } yy_b_buf_p = 0; yy_e_buf_p = yy_n_chars; if (yy_e_buf_p >= YY_BUF_LIM) YY_FATAL_ERROR("L0029: PCLEX input buffer overflowed"); yy_c_buf_p = yy_e_buf_p; } else if (yy_saw_eof) { saweof: if (yy_b_buf_p <= yy_e_buf_p) break; if (yywrap()) yy_act = YY_END_TOK; else { YY_INIT; yy_act = YY_NEW_FILE; } goto do_action; } YY_INPUT((yy_ch_buf + yy_c_buf_p + 1), yy_n_chars, YY_MAX_LINE); if (yy_n_chars == YY_NULL) { if (yy_saw_eof) YY_FATAL_ERROR("L0030: PCLEX scanner saw EOF twice - shouldn't happen"); yy_saw_eof = 1; goto saweof; } yy_e_buf_p += yy_n_chars; } ++yy_c_buf_p; yy_sym = yy_ch_buf[yy_c_buf_p]; if(yy_sym == '\000') yy_sym = '\001'; while (c[b[yy_curst] + yy_sym] != yy_curst) yy_curst = d[yy_curst]; yy_curst = n[b[yy_curst] + yy_sym]; yy_st_buf[yy_c_buf_p] = yy_curst; } while (b[yy_curst] != YY_JAM_BASE); if (yy_c_buf_p >= yy_b_buf_p) { yy_curst = yy_st_buf[yy_c_buf_p]; yy_lp = l[yy_curst]; find_rule: for ( ; ; ) { if (yy_lp && yy_lp < l[yy_curst + 1]) { yy_act = a[yy_lp]; goto do_action; } if (--yy_c_buf_p < yy_b_buf_p) break; yy_curst = yy_st_buf[yy_c_buf_p]; yy_lp = l[yy_curst]; } } ++yy_c_buf_p; yy_act = YY_DO_DEFAULT; } } # line 20 "wc.l" main() { yylex(); printf( "%d\t%d\t%d\n", nchar, nword, nline ); exit(0); }