📄 lexscan.flex
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * JFlex 1.4.2 * * Copyright (C) 1998-2008 Gerwin Klein <lsf@jflex.de> * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License. See the file * * COPYRIGHT for more information. * * * * 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. * * * * You should have received a copy of the GNU General Public License along * * with this program; if not, write to the Free Software Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */package JFlex;import java_cup.runtime.Symbol;import java.util.Vector;import java.io.*;import java.util.Stack;/** * The lexer of JFlex. * * Generated by <a href="http://www.jflex.de/">JFlex</a>. * * @author Gerwin Klein * @version JFlex 1.4.2, $Revision: 358 $, $Date: 2008-05-27 16:28:29 +1000 (Tue, 27 May 2008) $ */%%%final%public%class LexScan%implements sym, java_cup.runtime.Scanner%function next_token%type Symbol%unicode%column%line%eofclose%state COMMENT, STATELIST, MACROS, REGEXPSTART%state REGEXP, JAVA_CODE, STATES, STRING_CONTENT%state CHARCLASS, COPY, REPEATEXP, EATWSPNL%state CTOR_ARG%cupdebug%{ int balance = 0; int commentbalance = 0; int action_line = 0; int bufferSize = 16384; File file; Stack files = new Stack(); StringBuffer userCode = new StringBuffer(); String classCode; String initCode; String initThrow; String eofCode; String eofThrow; String lexThrow; String eofVal; String scanErrorException; String cupSymbol = "sym"; StringBuffer actionText = new StringBuffer(); StringBuffer string = new StringBuffer(); boolean charCount; boolean lineCount; boolean columnCount; boolean cupCompatible; boolean cupDebug; boolean isInteger; boolean isIntWrap; boolean isYYEOF; boolean notUnix; boolean isPublic; boolean isFinal; boolean isAbstract; boolean bolUsed; boolean standalone; boolean debugOption; boolean useRowMap = Options.gen_method == Options.PACK || Options.gen_method == Options.TABLE; boolean packed = Options.gen_method == Options.PACK; boolean caseless; boolean inclusive_states; boolean eofclose; String isImplementing; String isExtending; String className = "Yylex"; String functionName; String tokenType; String visibility = "public"; Vector /* String */ ctorArgs = new Vector(); Vector /* String */ ctorTypes = new Vector(); LexicalStates states = new LexicalStates(); Vector actions = new Vector(); private int nextState; boolean macroDefinition; Timer t = new Timer(); public int currentLine() { return yyline; } public void setFile(File file) { this.file = file; } private Symbol symbol(int type, Object value) { return new Symbol(type, yyline, yycolumn, value); } private Symbol symbol(int type) { return new Symbol(type, yyline, yycolumn); } // updates line and column count to the beginning of the first // non whitespace character in yytext, but leaves yyline+yycolumn // untouched private Symbol symbol_countUpdate(int type, Object value) { int lc = yyline; int cc = yycolumn; String text = yytext(); for (int i=0; i < text.length(); i++) { char c = text.charAt(i); if (c != '\n' && c != '\r' && c != ' ' && c != '\t' ) return new Symbol(type, lc, cc, value); if (c == '\n') { lc++; cc = 0; } else cc++; } return new Symbol(type, yyline, yycolumn, value); } private String makeMacroIdent() { String matched = yytext().trim(); return matched.substring(1, matched.length()-1).trim(); } public static String conc(Object a, Object b) { if (a == null && b == null) return null; if (a == null) return b.toString(); if (b == null) return a.toString(); return a.toString()+b.toString(); } public static String concExc(Object a, Object b) { if (a == null && b == null) return null; if (a == null) return b.toString(); if (b == null) return a.toString(); return a.toString()+", "+b.toString(); }%}%init{ states.insert("YYINITIAL", true);%init}Digit = [0-9]HexDigit = [0-9a-fA-F]OctDigit = [0-7]Number = {Digit}+HexNumber = \\ x {HexDigit} {2}Unicode = \\ u {HexDigit} {1, 4}OctNumber = \\ [0-3]? {OctDigit} {1, 2} // see http://www.unicode.org/unicode/reports/tr18/WSP = [ \t\b]WSPNL = [\u2028\u2029\u000A\u000B\u000C\u000D\u0085\t\b\ ]NL = [\u2028\u2029\u000A\u000B\u000C\u000D\u0085] | \u000D\u000ANNL = [^\u2028\u2029\u000A\u000B\u000C\u000D\u0085]Ident = {IdentStart} {IdentPart}*QualIdent = {Ident} ( {WSP}* "." {WSP}* {Ident} )*QUIL = {QualIdent} ( {WSP}* "," {WSP}* {QualIdent} )*Array = "[" {WSP}* "]"ParamPart = {IdentStart}|{IdentPart}|"<"|">"|","|{WSP}|"&"|"?"|"."GenParam = "<" {ParamPart}+ ">"ClassT = {Ident} ({WSP}* {GenParam})?QClassT = {QualIdent} ({WSP}* {GenParam})?ArrType = ({GenParam} {WSP}*)? {QClassT} ({WSP}* {Array})*IdentStart = [:jletter:]IdentPart = [:jletterdigit:]JFlexCommentChar = [^*/]|"/"+[^*/]|"*"+[^*/]JFlexComment = {JFlexCommentChar}*/* Java comments */JavaComment = {TraditionalComment}|{EndOfLineComment}TraditionalComment = "/*"{CommentContent}\*+"/"EndOfLineComment = "//".*{NL}CommentContent = ([^*]|\*+[^*/])*StringCharacter = [^\u2028\u2029\u000A\u000B\u000C\u000D\u0085\"\\]CharLiteral = \'([^\u2028\u2029\u000A\u000B\u000C\u000D\u0085\'\\]|{EscapeSequence})\'StringLiteral = \"({StringCharacter}|{EscapeSequence})*\"EscapeSequence = \\[^\u2028\u2029\u000A\u000B\u000C\u000D\u0085]|\\+u{HexDigit}{4}|\\[0-3]?{OctDigit}{1,2}/* \\(b|t|n|f|r|\"|\'|\\|[0-3]?{OctDigit}{1,2}|u{HexDigit}{4}) */JavaRest = [^\{\}\"\'/]|"/"[^*/] JavaCode = ({JavaRest}|{StringLiteral}|{CharLiteral}|{JavaComment})+%%<YYINITIAL> { "%%".*{NL}? { t.start(); yybegin(MACROS); macroDefinition = true; return symbol(USERCODE,userCode); } .*{NL} { userCode.append(yytext()); } .* { return symbol(EOF); }}<MACROS> ("%{"|"%init{"|"%initthrow{"|"%eof{"|"%eofthrow{"|"%yylexthrow{"|"%eofval{").*{NL} { string.setLength(0); yybegin(COPY); }<COPY> { "%}".*{NL} { classCode = conc(classCode,string); yybegin(MACROS); } "%init}".*{NL} { initCode = conc(initCode,string); yybegin(MACROS); } "%initthrow}".*{NL} { initThrow = concExc(initThrow,string); yybegin(MACROS); } "%eof}".*{NL} { eofCode = conc(eofCode,string); yybegin(MACROS); } "%eofthrow}".*{NL} { eofThrow = concExc(eofThrow,string); yybegin(MACROS); } "%yylexthrow}".*{NL} { lexThrow = concExc(lexThrow,string); yybegin(MACROS); } "%eofval}".*{NL} { eofVal = string.toString(); yybegin(MACROS); } .*{NL} { string.append(yytext()); } <<EOF>> { throw new ScannerException(file,ErrorMessages.EOF_IN_MACROS); }}<MACROS> ^"%s" ("tate" "s"?)? {WSP}+ { inclusive_states = true; yybegin(STATELIST); }<MACROS> ^"%x" ("state" "s"?)? {WSP}+ { inclusive_states = false; yybegin(STATELIST); }<STATELIST> { {Ident} { states.insert(yytext(),inclusive_states); } ([\ \t]*","[\ \t]*)|([\ \t]+) { } {NL} { yybegin(MACROS); } <<EOF>> { throw new ScannerException(file,ErrorMessages.EOF_IN_MACROS); }}<MACROS> { "%char" { charCount = true; } "%line" { lineCount = true; } "%column" { columnCount = true; } "%byaccj" { isInteger = true; if (eofVal == null) eofVal = "return 0;"; eofclose = true; } "%cup" { cupCompatible = true; isImplementing = concExc(isImplementing, "java_cup.runtime.Scanner"); if (functionName == null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -