📄 lex.c
字号:
case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case '$': StartIdentifier(t); t = GetChar(); while (isalnum(t) || t == '_' || t == '$' || t == '\\') { if(t == '\\') { switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; t = GetChar(); continue; default: UngetChar(t); UngetChar('\\'); EndIdentifier(); goto next; } } ContinueIdentifier(t); t = GetChar(); } UngetChar(t); EndIdentifier(); goto next; case '0': if(preproc) { LexPreprocNumber('0'); goto next; } switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto next; default: UngetChar(t); UngetChar('\\'); StartBase10OrLowerNum(0); EndNum(); goto next; } case 'x': case 'X': t2 = t; StartHexNum(); starting_hex_num: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto starting_hex_num; default: goto errBadToken; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'A': case 'b': case 'B': case 'c': case 'C': case 'd': case 'D': case 'e': case 'E': case 'f': case 'F': AddHexDigit(t); next_hex_digit: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto next_hex_digit; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case 'a': case 'A': case 'b': case 'B': case 'c': case 'C': case 'd': case 'D': case 'e': case 'E': case 'f': case 'F': AddHexDigit(t); goto next_hex_digit; case 'l': case 'L': MakeLong(); check_for_unsigned: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_for_unsigned; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'u': case 'U': MakeUnsigned(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } case 'u': case 'U': MakeUnsigned(); check_for_long: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_for_long; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'l': case 'L': MakeLong(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } default: EndNum(); UngetChar(t); goto next; } default: UngetChar(t); UngetChar(t2); StartBase10OrLowerNum(0); EndNum(); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': StartBase10OrLowerNum('0'); AddOctDigit(t); next_oct_digit: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto next_oct_digit; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': AddOctDigit(t); goto next_oct_digit; case '.': AddDecDigit(t); goto next_mantissa_digit; case 'l': case 'L': MakeLong(); check_for_unsigned_2: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_for_unsigned_2; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'u': case 'U': MakeUnsigned(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } case 'u': case 'U': MakeUnsigned(); check_for_long_2: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_for_long_2; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'l': case 'L': MakeLong(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } default: EndNum(); UngetChar(t); goto next; } case '.': StartBase10OrLowerNum('0'); AddDecDigit('.'); next_mantissa_digit: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto next_mantissa_digit; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': AddDecDigit(t); goto next_mantissa_digit; case 'e': case 'E': collect_exponent: saved_char = t; switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto collect_exponent; default: goto errBadToken; } case '+': case '-': got_sign: switch(t2 = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto got_sign; default: UngetChar(t2); UngetChar(t); UngetChar(saved_char); EndNum(); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': UngetChar(t2); break; default: UngetChar(t2); UngetChar(t); UngetChar(saved_char); EndNum(); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': BeginExponent(t); next_exp_digit_v1: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto next_exp_digit_v1; default: EndNum(); UngetChar(t); UngetChar('\\'); } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': AddExponent(t); goto next_exp_digit_v1; case 'f': case 'F': MakeFloat(); EndNum(); goto next; case 'l': case 'L': MakeLong(); EndNum(); goto next; default: EndNum(); UngetChar(t); goto next; } default: UngetChar(t); EndNum(); goto next; } case 'f': case 'F': MakeFloat(); EndNum(); goto next; case 'l': case 'L': MakeLong(); EndNum(); goto next; default: EndNum(); UngetChar(t); goto next; } default: UngetChar(t); StartBase10OrLowerNum('0'); EndNum(); goto next; } case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if(cpp_mode) { LexPreprocNumber(t); goto next; } StartBase10OrLowerNum(t); got_first_digit: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto got_first_digit; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': AddDecDigit(t); next_dec_digit: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto next_dec_digit; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': AddDecDigit(t); goto next_dec_digit; case 'e': case 'E': goto collect_exponent; case '.': AddDecDigit('.'); goto next_mantissa_digit; case 'l': case 'L': MakeLong(); check_unsigned_3: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_unsigned_3; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'u': case 'U': MakeUnsigned(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } case 'u': case 'U': MakeUnsigned(); check_long_3: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_long_3; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'l': case 'L': MakeLong(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } default: UngetChar(t); EndNum(); goto next; } case 'e': case 'E': goto collect_exponent; case '.': AddDecDigit('.'); goto next_mantissa_digit; case 'l': case 'L': MakeLong(); check_unsigned_4: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_unsigned_4; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'u': case 'U': MakeUnsigned(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } case 'u': case 'U': MakeUnsigned(); check_long_4: switch(t = GetChar()) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto check_long_4; default: EndNum(); UngetChar(t); UngetChar('\\'); goto next; } case 'l': case 'L': MakeLong(); EndNum(); goto next; default: UngetChar(t); EndNum(); goto next; } default: UngetChar(t); EndNum(); goto next; } case '.': if(cpp_mode) { t= GetChar(); UngetChar(t); switch(t) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': LexPreprocNumber('.'); goto next; default: GenOp("."); goto next; } } got_period: t = GetChar(); switch(t) { case '\\': switch(t = GetChar()) { case '\n': lineno++; lineno_offset++; goto got_period; default: UngetChar(t); UngetChar('\\'); GenOp("."); goto next; } case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': StartBase10OrLowerNum('0'); AddDecDigit('.'); UngetChar(t); goto next_mantissa_digit; default: UngetChar(t); GenOp("."); goto next; } case '\\': switch(t = GetChar()) { case '\n': lineno++; // Don't bump lineno_offset; haven't started a token. goto next; default: goto errBadToken; } default: goto errBadToken; } unterminatedCommentError: if(return_on_error) return EOF; fprintf(stderr, "%s: Error: Unterminated comment." NEWLINE, source_id); exit(0); eofError: if(return_on_error) return EOF; fprintf(stderr, "%s: Error: Unexpected end of file encountered." NEWLINE, source_id); exit(0); errBadToken: if(return_on_error) return EOF; fprintf(stderr, "%s:%d: Unrecognized token." NEWLINE "Skipping to the next line and continuing..." NEWLINE, source_id, lineno); while((t = GetChar())) { switch(t) { case '\n': lineno++; return 1; case EOF: return 0; default: continue; } } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -