typicalcompilerscannerbyjlex.lex

来自「JAVA在编译原理上的应用。」· LEX 代码 · 共 76 行

LEX
76
字号
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&uuml;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 + =
减小字号Ctrl + -
显示快捷键?