📄 javalexer.lex
字号:
return (t);}<YYINITIAL> "synchronized" { lastToken = JavaToken.RESERVED_WORD_SYNCHRONIZED; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "this" { lastToken = JavaToken.RESERVED_WORD_THIS; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "throw" { lastToken = JavaToken.RESERVED_WORD_THROW; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "throws" { lastToken = JavaToken.RESERVED_WORD_THROWS; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "transient" { lastToken = JavaToken.RESERVED_WORD_TRANSIENT; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "try" { lastToken = JavaToken.RESERVED_WORD_TRY; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "void" { lastToken = JavaToken.RESERVED_WORD_VOID; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "volatile" { lastToken = JavaToken.RESERVED_WORD_VOLATILE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "while" { lastToken = JavaToken.RESERVED_WORD_WHILE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "null" { lastToken = JavaToken.LITERAL_NULL; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "true" { lastToken = JavaToken.LITERAL_BOOLEAN; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "false" { lastToken = JavaToken.LITERAL_BOOLEAN; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {Identifier} { lastToken = JavaToken.IDENTIFIER; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {DecimalNum} { /* At this point, the number we found could still be too large. * If it is too large, we need to return an error. * Java has methods built in that will decode from a string * and throw an exception the number is too large */ String text = yytext(); try { /* bigger negatives are allowed than positives. Thus * we have to be careful to make sure a neg sign is preserved */ if (lastToken == JavaToken.OPERATOR_SUBTRACT){ Integer.decode('-' + text); } else { Integer.decode(text); } lastToken = JavaToken.LITERAL_INTEGER_DECIMAL; } catch (NumberFormatException e){ lastToken = JavaToken.ERROR_INTEGER_DECIMIAL_SIZE; } JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {OctalNum} { /* An Octal number cannot be too big. After removing * initial zeros, It can have 11 digits, the first * of which must be 3 or less. */ lastToken = JavaToken.LITERAL_INTEGER_OCTAL; int i; String text = yytext(); int length = text.length(); for (i=1 ; i<length-11; i++){ //check for initial zeros if (yytext().charAt(i) != '0'){ lastToken = JavaToken.ERROR_INTEGER_OCTAL_SIZE; } } if (length - i > 11){ lastToken = JavaToken.ERROR_INTEGER_OCTAL_SIZE; } else if (length - i == 11){ // if the rest of the number is as big as possible // the first digit can only be 3 or less if (text.charAt(i) != '0' && text.charAt(i) != '1' && text.charAt(i) != '2' && text.charAt(i) != '3'){ lastToken = JavaToken.ERROR_INTEGER_OCTAL_SIZE; } } // Otherwise, it should be OK JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {HexNum} { /* A Hex number cannot be too big. After removing * initial zeros, It can have 8 digits */ lastToken = JavaToken.LITERAL_INTEGER_HEXIDECIMAL; int i; String text = yytext(); int length = text.length(); for (i=2 ; i<length-8; i++){ //check for initial zeros if (text.charAt(i) != '0'){ lastToken = JavaToken.ERROR_INTEGER_HEXIDECIMAL_SIZE; } } if (length - i > 8){ lastToken = JavaToken.ERROR_INTEGER_HEXIDECIMAL_SIZE; } JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {DecimalLong} { String text = yytext(); try { if (lastToken == JavaToken.OPERATOR_SUBTRACT){ Long.decode('-' + text.substring(0,text.length()-1)); } else { Long.decode(text.substring(0,text.length()-1)); } lastToken = JavaToken.LITERAL_LONG_DECIMAL; } catch (NumberFormatException e){ lastToken = JavaToken.ERROR_LONG_DECIMIAL_SIZE; } JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {OctalLong} { /* An Octal number cannot be too big. After removing * initial zeros, It can have 23 digits, the first * of which must be 1 or less. The last will be the L or l * at the end. */ lastToken = JavaToken.LITERAL_LONG_OCTAL; int i; String text = yytext(); int length = text.length(); for (i=1 ; i<length-23; i++){ //check for initial zeros if (text.charAt(i) != '0'){ lastToken = JavaToken.ERROR_LONG_OCTAL_SIZE; } } if (length - i > 23){ lastToken = JavaToken.ERROR_LONG_OCTAL_SIZE; } else if (length - i == 23){ // if the rest of the number is as big as possible // the first digit can only be 3 or less if (text.charAt(i) != '0' && text.charAt(i) != '1'){ lastToken = JavaToken.ERROR_LONG_OCTAL_SIZE; } } // Otherwise, it should be OK JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {HexLong} { /* A Hex long cannot be too big. After removing * initial zeros, It can have 17 digits, the last of which is * the L or l */ lastToken = JavaToken.LITERAL_LONG_HEXIDECIMAL; int i; String text = yytext(); int length = text.length(); for (i=2 ; i<length-17; i++){ //check for initial zeros if (text.charAt(i) != '0'){ lastToken = JavaToken.ERROR_LONG_HEXIDECIMAL_SIZE; } } if (length - i > 17){ lastToken = JavaToken.ERROR_LONG_HEXIDECIMAL_SIZE; } JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {ZeroFloat} { /* catch the case of a zero in parsing, so that we do not incorrectly * give an error that a number was rounded to zero */ lastToken = JavaToken.LITERAL_FLOATING_POINT; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {ZeroDouble} { lastToken = JavaToken.LITERAL_DOUBLE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {Float} { /* Sun s java has a few bugs here. Their MAX_FLOAT and MIN_FLOAT do not * quite match the spec. Its not far off, so we will deal. If they fix * then we are fixed. So all good. */ Float f; try { f = Float.valueOf(yytext()); if (f.isInfinite() || f.compareTo(new Float(0f)) == 0){ lastToken = JavaToken.ERROR_FLOAT_SIZE; } else { lastToken = JavaToken.LITERAL_FLOATING_POINT; } } catch (NumberFormatException e){ lastToken = JavaToken.ERROR_FLOAT_SIZE; } String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {Double} { Double d; try { d = Double.valueOf(yytext()); if (d.isInfinite() || d.compareTo(new Double(0d)) == 0){ lastToken = JavaToken.ERROR_DOUBLE_SIZE; } else { lastToken = JavaToken.LITERAL_DOUBLE; } } catch (NumberFormatException e){ lastToken = JavaToken.ERROR_DOUBLE_SIZE; } String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {Character} { lastToken = JavaToken.LITERAL_CHARACTER; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {String} { lastToken = JavaToken.LITERAL_STRING; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> ({WhiteSpace}+) { lastToken = JavaToken.WHITE_SPACE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {Comment} { lastToken = JavaToken.COMMENT_END_OF_LINE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {DocComment} { lastToken = JavaToken.COMMENT_DOCUMENTATION; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {TradComment} { lastToken = JavaToken.COMMENT_TRADITIONAL; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {UnclosedString} { /* most of these errors have to be caught down near the end of the file. * This way, previous expressions of the same length have precedence. * This is really useful for catching anything bad by just allowing it * to slip through the cracks. */ lastToken = JavaToken.ERROR_UNCLOSED_STRING; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {MalformedUnclosedString} { lastToken = JavaToken.ERROR_MALFORMED_UNCLOSED_STRING; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {MalformedString} { lastToken = JavaToken.ERROR_MALFORMED_STRING; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {UnclosedCharacter} { lastToken = JavaToken.ERROR_UNCLOSED_CHARACTER; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {MalformedUnclosedCharacter} { lastToken = JavaToken.ERROR_MALFORMED_UNCLOSED_CHARACTER; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {MalformedCharacter} { lastToken = JavaToken.ERROR_MALFORMED_CHARACTER; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {ErrorFloat} { lastToken = JavaToken.ERROR_FLOAT; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {ErrorIdentifier} { lastToken = JavaToken.ERROR_IDENTIFIER; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> {OpenComment} { lastToken = JavaToken.ERROR_UNCLOSED_COMMENT; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -