📄 typicalcompilerscannerbyjlex.lex
字号:
package lolo.test;import java.io.IOException;import java.io.InputStreamReader;import java.io. FileReader;import java.io.FileNotFoundException;/** An example to meassure the scanning time using JLex for typical symbols * in compiler construction. * * @author <a href="http://www.inf.uos.de/bernd" target="_blank">Bernd Kühl</a> (<a href="mailto:bernd@informatik.uni-osnabrueck.de">bernd@informatik.uni-osnabrueck.de</a>) */%%%public%class TypicalCompilerScannerByJLex%type boolean%eofval{ return false;%eofval}%{ public static void main (String args []) throws Exception {System.err.println("go ..."); long old = System.currentTimeMillis();System.err.println("start time\t"+old+"..."); TypicalCompilerScannerByJLex scanner = new TypicalCompilerScannerByJLex(args.length != 0 ? new FileReader(args[0]) :new InputStreamReader(System.in)); try { while (scanner.yylex()) ; } catch (IOException ioe) { System.err.println(ioe); } long current = System.currentTimeMillis();System.err.println("end time\t"+current+"..."); TimeUtil.printMilliSecons("time: ", current-old, System.err); }%}alpha = [a-zA-Z_]alnum = [a-zA-Z_0-9]whitespace = [\u0000- ]dec = [0-9]sign = [+-]?exp = ([eE]{sign}{dec}+) %% ">=" { PrintTypicalCompilerSymbols.word(yytext()); return true; }"<=" { PrintTypicalCompilerSymbols.word(yytext()); return true; }"==" { PrintTypicalCompilerSymbols.word(yytext()); return true; }"&&" { PrintTypicalCompilerSymbols.word(yytext()); return true; }"||" { PrintTypicalCompilerSymbols.word(yytext()); return true; }{dec}+ { PrintTypicalCompilerSymbols.integer(yytext()); return true; }{dec}+"."{dec}*{exp}?|{dec}*"."{dec}+{exp}?|{dec}+{exp} { PrintTypicalCompilerSymbols.floating(yytext()); return true; } {alpha}{alnum}* { PrintTypicalCompilerSymbols.identifier(yytext()); return true; }{whitespace}+ { PrintTypicalCompilerSymbols.whitespace(yytext()); return true; } "/*"([^*]|"*"+[^/*])*"*"+"/" { PrintTypicalCompilerSymbols.comment(yytext()); return true; }"/**"([^*/]|"*"+[^/*])*"*"+"/" { PrintTypicalCompilerSymbols.comment(yytext()); return true; }"//".*$ { PrintTypicalCompilerSymbols.comment(yytext()); return true; }\"([^\"\\\n]|\\.|\\\n)*\" { PrintTypicalCompilerSymbols.quotedText(yytext()); return true; }'([^'\\\n]|\\[^0-7\n]|\\[0-7][0-7]?[0-7]?)' { PrintTypicalCompilerSymbols.quotedChar(yytext().charAt(0)); return true; }[+-=/*@/!<>?:;|\[\]{}().,%&] { PrintTypicalCompilerSymbols.character(yytext().charAt(0)); return true; }. { throw new RuntimeException("illegal character "+yytext()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -