📄 lex.yy.c
字号:
/* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) (yy_buffer_stack_top)++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* 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 261 "spl.l"KEYENTRY Keytable[] = {{"abs", SYS_FUNCT, fABS, TYPE_INTEGER, TYPE_INTEGER },{"and", kAND, KEYWORD, 0, 0 },{"array", kARRAY, KEYWORD, 0, 0 },{"begin", kBEGIN, KEYWORD, 0, 0 },{"boolean", SYS_TYPE, tBOOLEAN, 0, 0 },{"case", kCASE, KEYWORD, 0, 0 },{"char", SYS_TYPE, tCHAR, 0, 0 },{"chr", SYS_FUNCT, fCHR, TYPE_CHAR, TYPE_CHAR },{"const", kCONST, KEYWORD, 0, 0 },{"div", kDIV, KEYWORD, 0, 0 },{"do", kDO, KEYWORD, 0, 0 },{"downto", kDOWNTO, KEYWORD, 0, 0 },{"else", kELSE, KEYWORD, 0, 0 },{"end", kEND, KEYWORD, 0, 0 },{"false", SYS_CON, cFALSE, 0, 0 },{"for", kFOR, KEYWORD, 0, 0 },{"function", kFUNCTION, KEYWORD, 0, 0 },{"goto", kGOTO, KEYWORD, 0, 0 },{"if", kIF, KEYWORD, 0, 0 },{"in", kIN, KEYWORD, 0, 0 },{"integer", SYS_TYPE, tINTEGER, 0, 0 },{"label", kLABEL, KEYWORD, 0, 0 },{"maxint", SYS_CON, cMAXINT, 0, 0 },{"mod", kMOD, KEYWORD, 0, 0 },{"not", kNOT, KEYWORD, 0, 0 },{"odd", SYS_FUNCT, fODD, TYPE_INTEGER, TYPE_BOOLEAN },{"of", kOF, KEYWORD, 0, 0 },{"or", kOR, KEYWORD, 0, 0 },{"ord", SYS_FUNCT, fORD, TYPE_INTEGER, TYPE_INTEGER },{"packed", kPACKED, KEYWORD, 0, 0 },{"pred", SYS_FUNCT, fPRED, TYPE_INTEGER, TYPE_INTEGER },{"procedure", kPROCEDURE, KEYWORD, 0, 0 },{"program", kPROGRAM, KEYWORD, 0, 0 },{"read", pREAD, pREAD, 0, 0 },{"readln", pREAD, pREADLN, 0, 0 },{"real", SYS_TYPE, KEYWORD, 0, 0 },{"record", kRECORD, KEYWORD, 0, 0 },{"repeat", kREPEAT, KEYWORD, 0, 0 },{"set", kSET, KEYWORD, 0, 0 },{"sqr", SYS_FUNCT, fSQR, TYPE_INTEGER, TYPE_INTEGER },{"sqrt", SYS_FUNCT, fSQRT, TYPE_INTEGER, TYPE_INTEGER },{"succ", SYS_FUNCT, fSUCC, TYPE_INTEGER, TYPE_INTEGER },{"then", kTHEN, KEYWORD, 0, 0 },{"to", kTO, KEYWORD, 0, 0 },{"true", SYS_CON, cTRUE, 0, 0 },{"type", kTYPE, KEYWORD, 0, 0 },{"until", kUNTIL, KEYWORD, 0, 0 },{"var", kVAR, KEYWORD, 0, 0 },{"while", kWHILE, KEYWORD, 0, 0 },{"with", kWITH, KEYWORD, 0, 0 },{"write", SYS_PROC, pWRITE, 0, 0 },{"writeln", SYS_PROC, pWRITELN, 0, 0 },{"----", LAST_ENTRY, KEYWORD, 0, 0 },};struct { char *name; int key;}key_to_name[] = { {"SYS_FUNCT", SYS_FUNCT }, {"kAND", kAND }, {"kARRAY", kARRAY }, {"kBEGIN", kBEGIN }, {"SYS_TYPE", SYS_TYPE }, {"kCASE", kCASE }, {"SYS_TYPE", SYS_TYPE }, {"kCONST", kCONST }, {"kDIV", kDIV }, {"kDO", kDO }, {"kDOWNTO", kDOWNTO }, {"kELSE", kELSE }, {"kEND", kEND }, {"SYS_CON", SYS_CON }, {"kFOR", kFOR }, {"kFUNCTION", kFUNCTION }, {"kGOTO", kGOTO }, {"kIF", kIF }, {"kIN", kIN }, {"kLABEL", kLABEL }, {"kMOD", kMOD }, {"kNOT", kNOT }, {"kOF", kOF }, {"kOR", kOR }, {"kPACKED", kPACKED }, {"kPROCEDURE", kPROCEDURE }, {"kPROGRAM", kPROGRAM }, {"pREAD", pREAD }, {"kRECORD", kRECORD }, {"kREPEAT", kREPEAT }, {"kSET", kSET }, {"kTHEN", kTHEN }, {"kTO", kTO }, {"kTYPE", kTYPE }, {"kUNTIL", kUNTIL }, {"kVAR", kVAR }, {"kWHILE", kWHILE }, {"kWITH", kWITH }, {"SYS_PROC", SYS_PROC }, {"LAST_ENTRY", LAST_ENTRY }};static char *get_name_by_key(int key){ int i; for (i = 0; i < sizeof(key_to_name) / sizeof(key_to_name[0]); i++) { if (key_to_name[i].key == key) return key_to_name[i].name; } return "bad key";}static int id_or_keyword(char *lex){ int left = 0, right = Keytable_size; int mid = (left + right) / 2; char *p; if (!Keytable_size) { internal_error("Key table size not known.\n"); exit(0); } for (p = lex; *p; p++) *p = tolower(*p); while (mid != left && mid != right) { if (!strcmp(Keytable[mid].name, lex)) { if (dump_token) { printf("token: %s ", get_name_by_key(Keytable[mid].key)); } if (Keytable[mid].key == SYS_FUNCT || Keytable[mid].key == SYS_PROC) { yylval.p_lex = &Keytable[mid]; if (dump_token) { printf(",yylval.p_lex = &Keytable[%d]", mid); } } else if (Keytable[mid].key == SYS_CON) { yylval.num = Keytable[mid].attr; if (dump_token) { printf(",yylval.p_num = Keytable[%d].atrr = %d", mid, Keytable[mid].attr); } } else if (Keytable[mid].key == SYS_TYPE) { strncpy(yylval.p_char, yytext, NAME_LEN); if (dump_token) { printf(",yylval.p_char = %s", yylval.p_char); } } if (dump_token) printf(".\n"); return Keytable[mid].key; } else if (strcmp(Keytable[mid].name, lex) < 0) left = mid; else if (strcmp(Keytable[mid].name, lex) > 0) right = mid; mid = (left + right) / 2; } if (dump_token) { printf("token: yNAME, yylval.p_char = %s.\n", yylval.p_char); } return yNAME;}int get_keytable_size(){ int i; Keytable_size = 0; for (i = 0; ; Keytable_size++, i++) { if (Keytable[i].key == LAST_ENTRY) break; } return 0;}int yywrap() { return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -