📄 calc_flex.c
字号:
/* copied from yy_switch_to_buffer. */ yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1;}/** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * */void yypop_buffer_state (void){ if (!YY_CURRENT_BUFFER) return; yy_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; if ((yy_buffer_stack_top) > 0) --(yy_buffer_stack_top); if (YY_CURRENT_BUFFER) { yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; }}/* Allocates the stack if it does not exist. * Guarantees space for at least one push. */static void yyensure_buffer_stack (void){ int num_to_alloc; if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; }}/** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * * @return the newly allocated buffer state object. */YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ){ YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; yy_switch_to_buffer(b ); return b;}/** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param str a NUL-terminated string to scan * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ){ return yy_scan_bytes(yystr,strlen(yystr) );}/** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param bytes the byte buffer to scan * @param len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ){ YY_BUFFER_STATE b; char *buf; yy_size_t n; int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) yyalloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); for ( i = 0; i < _yybytes_len; ++i ) buf[i] = yybytes[i]; buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = yy_scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b;}#ifndef YY_EXIT_FAILURE#define YY_EXIT_FAILURE 2#endifstatic void yy_fatal_error (yyconst char* msg ){ (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE );}/* Redefine yyless() so it works in section 3 code. */#undef yyless#define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ yytext[yyleng] = (yy_hold_char); \ (yy_c_buf_p) = yytext + yyless_macro_arg; \ (yy_hold_char) = *(yy_c_buf_p); \ *(yy_c_buf_p) = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 )/* Accessor methods (get/set functions) to struct members. *//** Get the current line number. * */int yyget_lineno (void){ return yylineno;}/** Get the input stream. * */FILE *yyget_in (void){ return yyin;}/** Get the output stream. * */FILE *yyget_out (void){ return yyout;}/** Get the length of the current token. * */int yyget_leng (void){ return yyleng;}/** Get the current token. * */char *yyget_text (void){ return yytext;}/** Set the current line number. * @param line_number * */void yyset_lineno (int line_number ){ yylineno = line_number;}/** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. * * @see yy_switch_to_buffer */void yyset_in (FILE * in_str ){ yyin = in_str ;}void yyset_out (FILE * out_str ){ yyout = out_str ;}int yyget_debug (void){ return yy_flex_debug;}void yyset_debug (int bdebug ){ yy_flex_debug = bdebug ;}static int yy_init_globals (void){ /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ (yy_buffer_stack) = 0; (yy_buffer_stack_top) = 0; (yy_buffer_stack_max) = 0; (yy_c_buf_p) = (char *) 0; (yy_init) = 0; (yy_start) = 0;/* Defined in main.c */#ifdef YY_STDINIT yyin = stdin; yyout = stdout;#else yyin = (FILE *) 0; yyout = (FILE *) 0;#endif /* For future reference: Set errno on error, since we are called by * yylex_init() */ return 0;}/* yylex_destroy is for both reentrant and non-reentrant scanners. */int yylex_destroy (void){ /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ yy_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; yypop_buffer_state(); } /* Destroy the stack itself. */ yyfree((yy_buffer_stack) ); (yy_buffer_stack) = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ yy_init_globals( ); return 0;}/* * Internal utility routines. */#ifndef yytext_ptrstatic void yy_flex_strncpy (char* s1, yyconst char * s2, int n ){ register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i];}#endif#ifdef YY_NEED_STRLENstatic int yy_flex_strlen (yyconst char * s ){ register int n; for ( n = 0; s[n]; ++n ) ; return n;}#endifvoid *yyalloc (yy_size_t size ){ return (void *) malloc( size );}void *yyrealloc (void * ptr, yy_size_t size ){ /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size );}void yyfree (void * ptr ){ free( (char *) ptr ); /* see yyrealloc() for (char *) cast */}#define YYTABLES_NAME "yytables"#line 120 "calc_flex.l"yywrap(){ return(1);}#ifdef __cplusplusvoid skip_comment(void){ char c, c1;loop: while ((c = yyinput()) != '*' && c != 0) /*putchar(c)*/; if ((c1 = yyinput()) != '/' && c != 0) { unput(c1); goto loop; } if (c != 0) { /*putchar(c)*/; }}#else /*__cplusplus*/void skip_comment(void){ char c, c1;loop: while ((c = input()) != '*' && c != 0) /*putchar(c)*/; if ((c1 = input()) != '/' && c != 0) { unput(c1); goto loop; } if (c != 0) { /*putchar(c1)*/; }}#endif /*__cplusplus*/void skip_spaceSS(void){ /* fprintf(yyout, "space: [%d]\n", *yytext); */}void save_tokenID(const char *s){ yylval.s_value = strdup(s);#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenID:[%s]\n", yylval.s_value);#endif/*DEBUG_PRINT_TOKEN*/}void save_tokenCS(const char *s){ yylval.s_value = strdup(s);#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenCS:[%s]\n", yylval.s_value);#endif/*DEBUG_PRINT_TOKEN*/}void save_tokenCC(const char *s){ yylval.c_value = *s;#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenCC:[%c]\n", yylval.c_value);#endif/*DEBUG_PRINT_TOKEN*/}void save_tokenCI(const char *s){ yylval.i_value = my_strTOint(s);#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenCI:[%d]\n", yylval.i_value);#endif/*DEBUG_PRINT_TOKEN*/}void save_tokenCH(const char *s){ yylval.i_value = my_hexTOint(s);#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenCH:[%d]\n", yylval.i_value);#endif/*DEBUG_PRINT_TOKEN*/}void save_tokenCF(const char *s){ yylval.r_value = my_strTOdbl(s);#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenCF:[%f]\n", yylval.r_value);#endif/*DEBUG_PRINT_TOKEN*/}void save_tokenOP(const char *s){#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenOP:[%s]\n", s);#endif/*DEBUG_PRINT_TOKEN*/}void save_tokenAS(short i){ yylval.i_value = i;#ifdef DEBUG_PRINT_TOKEN fprintf(yyout, "tokenAS:[%d]\n", i);#endif/*DEBUG_PRINT_TOKEN*/}long my_strTOint(const char *s){ long result = 0; while(*s) { result = (result << 1) + (result << 3) + (*s - '0'); s ++; }; return(result);}long my_hexTOint(const char *s){ long result = 0; s += 2; while(*s) { if(*s <= '9') result = (result << 4) | (*s - '0'); else if(*s <= 'F') result = (result << 4) | (*s - 'A'); else result = (result << 4) | (*s - 'a'); s ++; };}Real my_strTOdbl(const char *s){ long p = 0; Real r = 0; while(*s) { if(*s >= '0' && *s <= '9') { r = r * 10 +(*s - '0'); s ++ ; } else break; } if(*s == '.') { s ++ ; while(*s) { if(*s >= '0' && *s <= '9') { r = r * 10 +(*s - '0'); p -- ; s ++ ; } else break; }; } if(*s == 'e' || *s == 'E') { s ++ ; if(*s == '-') { p += (0 - my_strTOint(++ s)); } else if(*s == '+') { p += (0 + my_strTOint(++ s)); } else { p += my_strTOint(s); } } return(pow(10.0, p)* r);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -