📄 javalexer.lex
字号:
/* JavaLexer.java is a generated file. You probably want to * edit JavaLexer.lex to make changes. Use JFlex to generate it. * To generate JavaLexer.java * Install <a href="http://jflex.de/">JFlex</a> v1.3.2 or later. * Once JFlex is in your classpath run<br> * <code>java JFlex.Main JavaLexer.lex</code><br> * You will then have a file called JavaLexer.java *//* * This file is part of a <a href="http://ostermiller.org/syntax/">syntax * highlighting</a> package. * Copyright (C) 1999-2002 Stephen Ostermiller * http://ostermiller.org/contact.pl?regarding=Syntax+Highlighting * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * See COPYING.TXT for details. */package com.Ostermiller.Syntax.Lexer;import java.io.*;/** * JavaLexer is a java lexer. Created with JFlex. An example of how it is used: * <CODE> * <PRE> * JavaLexer shredder = new JavaLexer(System.in); * JavaToken t; * while ((t = shredder.getNextToken()) != null){ * System.out.println(t); * } * </PRE> * </CODE> * The tokens returned should comply with the * <A Href=http://java.sun.com/docs/books/jls/html/>Java * Language Specification</A>. * @see JavaToken */ %%%public%class JavaLexer%implements Lexer%function getNextToken%type Token %{ private int lastToken; private int nextState=YYINITIAL; /** * next Token method that allows you to control if whitespace and comments are * returned as tokens. */ public Token getNextToken(boolean returnComments, boolean returnWhiteSpace)throws IOException{ Token t = getNextToken(); while (t != null && ((!returnWhiteSpace && t.isWhiteSpace()) || (!returnComments && t.isComment()))){ t = getNextToken(); } return (t); } /** * Prints out tokens from a file or System.in. * If no arguments are given, System.in will be used for input. * If more arguments are given, the first argument will be used as * the name of the file to use as input * * @param args program arguments, of which the first is a filename */ public static void main(String[] args) { InputStream in; try { if (args.length > 0){ File f = new File(args[0]); if (f.exists()){ if (f.canRead()){ in = new FileInputStream(f); } else { throw new IOException("Could not open " + args[0]); } } else { throw new IOException("Could not find " + args[0]); } } else { in = System.in; } JavaLexer shredder = new JavaLexer(in); Token t; while ((t = shredder.getNextToken()) != null) { if (t.getID() != JavaToken.WHITE_SPACE){ System.out.println(t); } } } catch (IOException e){ System.out.println(e.getMessage()); } } /** * Closes the current input stream, and resets the scanner to read from a new input stream. * All internal variables are reset, the old input stream cannot be reused * (content of the internal buffer is discarded and lost). * The lexical state is set to the initial state. * Subsequent tokens read from the lexer will start with the line, char, and column * values given here. * * @param reader The new input. * @param yyline The line number of the first token. * @param yychar The position (relative to the start of the stream) of the first token. * @param yycolumn The position (relative to the line) of the first token. * @throws IOException if an IOExecption occurs while switching readers. */ public void reset(java.io.Reader reader, int yyline, int yychar, int yycolumn) throws IOException{ yyreset(reader); this.yyline = yyline; this.yychar = yychar; this.yycolumn = yycolumn; }%}%line%char%fullHexDigit=([0-9a-fA-F])Digit=([0-9])OctalDigit=([0-7])TetraDigit=([0-3])NonZeroDigit=([1-9])Letter=([a-zA-Z_$])BLANK=([ ])TAB=([\t])FF=([\f])EscChar=([\\])CR=([\r])LF=([\n])EOL=({CR}|{LF}|{CR}{LF})WhiteSpace=({BLANK}|{TAB}|{FF}|{EOL})AnyNonSeparator=([^\t\f\r\n\ \(\)\{\}\[\]\;\,\.\=\>\<\!\~\?\:\+\-\*\/\&\|\^\%\"\'])OctEscape1=({EscChar}{OctalDigit})OctEscape2=({EscChar}{OctalDigit}{OctalDigit})OctEscape3=({EscChar}{TetraDigit}{OctalDigit}{OctalDigit})OctEscape=({OctEscape1}|{OctEscape2}|{OctEscape3})UnicodeEscape=({EscChar}[u]{HexDigit}{HexDigit}{HexDigit}{HexDigit})Escape=({EscChar}([r]|[n]|[b]|[f]|[t]|[\\]|[\']|[\"]))JavaLetter=({Letter}|{UnicodeEscape})Identifier=({JavaLetter}({JavaLetter}|{Digit})*)ErrorIdentifier=({AnyNonSeparator}+)Comment=("//"[^\r\n]*)TradCommentBegin=("/*")DocCommentBegin =("/**")NonTermStars=([^\*\/]*[\*]+[^\*\/])TermStars=([\*]+[\/])CommentText=((([^\*]*[\/])|{NonTermStars})*)CommentEnd=([^\*]*{TermStars})TradComment=({TradCommentBegin}{CommentText}{CommentEnd})DocCommentEnd1=([^\/\*]{CommentText}{CommentEnd})DocCommentEnd2=({NonTermStars}{CommentText}{CommentEnd})DocComment=({DocCommentBegin}({DocCommentEnd1}|{DocCommentEnd2}|{TermStars}|[\/]))OpenComment=({TradCommentBegin}{CommentText}([^\*]*)([\*]*))Sign=([\+]|[\-])LongSuffix=([l]|[L])DecimalNum=(([0]|{NonZeroDigit}{Digit}*))OctalNum=([0]{OctalDigit}*)HexNum=([0]([x]|[X]){HexDigit}{HexDigit}*)DecimalLong=({DecimalNum}{LongSuffix})OctalLong=({OctalNum}{LongSuffix})HexLong=({HexNum}{LongSuffix})SignedInt=({Sign}?{Digit}+)Expo=([e]|[E])ExponentPart=({Expo}{SignedInt})FloatSuffix=([f]|[F])DoubleSuffix=([d]|[D])FloatDouble1=({Digit}+[\.]{Digit}*{ExponentPart}?)FloatDouble2=([\.]{Digit}+{ExponentPart}?)FloatDouble3=({Digit}+{ExponentPart})FloatDouble4=({Digit}+)Double1=({FloatDouble1}{DoubleSuffix}?)Double2=({FloatDouble2}{DoubleSuffix}?)Double3=({FloatDouble3}{DoubleSuffix}?)Double4=({FloatDouble4}{DoubleSuffix})Float1=({FloatDouble1}{FloatSuffix})Float2=({FloatDouble2}{FloatSuffix})Float3=({FloatDouble3}{FloatSuffix})Float4=({FloatDouble4}{FloatSuffix})Float=({Float1}|{Float2}|{Float3}|{Float4})Double=({Double1}|{Double2}|{Double3}|{Double4}) ZeroFloatDouble1=([0]+[\.][0]*{ExponentPart}?)ZeroFloatDouble2=([\.][0]+{ExponentPart}?)ZeroFloatDouble3=([0]+{ExponentPart})ZeroFloatDouble4=([0]+)ZeroDouble1=({ZeroFloatDouble1}{DoubleSuffix}?)ZeroDouble2=({ZeroFloatDouble2}{DoubleSuffix}?)ZeroDouble3=({ZeroFloatDouble3}{DoubleSuffix}?)ZeroDouble4=({ZeroFloatDouble4}{DoubleSuffix})ZeroFloat1=({ZeroFloatDouble1}{FloatSuffix})ZeroFloat2=({ZeroFloatDouble2}{FloatSuffix})ZeroFloat3=({ZeroFloatDouble3}{FloatSuffix})ZeroFloat4=({ZeroFloatDouble4}{FloatSuffix})ZeroFloat=({ZeroFloat1}|{ZeroFloat2}|{ZeroFloat3}|{ZeroFloat4})ZeroDouble=({ZeroDouble1}|{ZeroDouble2}|{ZeroDouble3}|{ZeroDouble4})ErrorFloat=({Digit}({AnyNonSeparator}|[\.])*)AnyChrChr=([^\'\n\r\\])UnclosedCharacter=([\']({Escape}|{OctEscape}|{UnicodeEscape}|{AnyChrChr}))Character=({UnclosedCharacter}[\'])MalformedUnclosedCharacter=([\']({AnyChrChr}|({EscChar}[^\n\r]))*)MalformedCharacter=([\'][\']|{MalformedUnclosedCharacter}[\'])AnyStrChr=([^\"\n\r\\])UnclosedString=([\"]({Escape}|{OctEscape}|{UnicodeEscape}|{AnyStrChr})*)String=({UnclosedString}[\"])MalformedUnclosedString=([\"]({EscChar}|{AnyStrChr})*)MalformedString=({MalformedUnclosedString}[\"])%%<YYINITIAL> "(" { lastToken = JavaToken.SEPARATOR_LPAREN; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t); }<YYINITIAL> ")" { lastToken = JavaToken.SEPARATOR_RPAREN; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "{" { lastToken = JavaToken.SEPARATOR_LBRACE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "}" { lastToken = JavaToken.SEPARATOR_RBRACE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "[" { lastToken = JavaToken.SEPARATOR_LBRACKET; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "]" { lastToken = JavaToken.SEPARATOR_RBRACKET; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> ";" { lastToken = JavaToken.SEPARATOR_SEMICOLON; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "," { lastToken = JavaToken.SEPARATOR_COMMA; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "." { lastToken = JavaToken.SEPARATOR_PERIOD; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "=" { lastToken = JavaToken.OPERATOR_ASSIGN; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> ">" { lastToken = JavaToken.OPERATOR_GREATER_THAN; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "<" { lastToken = JavaToken.OPERATOR_LESS_THAN; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "!" { lastToken = JavaToken.OPERATOR_LOGICAL_NOT; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "~" { lastToken = JavaToken.OPERATOR_BITWISE_COMPLIMENT; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "?" { lastToken = JavaToken.OPERATOR_QUESTION; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> ":" { lastToken = JavaToken.OPERATOR_COLON; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "+" { lastToken = JavaToken.OPERATOR_ADD; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "-" { lastToken = JavaToken.OPERATOR_SUBTRACT; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "*" { lastToken = JavaToken.OPERATOR_MULTIPLY; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "/" { lastToken = JavaToken.OPERATOR_DIVIDE; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "&" { lastToken = JavaToken.OPERATOR_BITWISE_AND; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "|" { lastToken = JavaToken.OPERATOR_BITWISE_OR; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState)); return (t);}<YYINITIAL> "^" { lastToken = JavaToken.OPERATOR_BITWISE_XOR; String text = yytext(); JavaToken t = (new JavaToken(lastToken,text,yyline,yychar,yychar+text.length(),nextState));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -