📄 typicalcompilerscannerbyoolex.java
字号:
package lolo.test;import oolex.Input;import oolex.Scan;import oolex.Scan.Action;import oolex.Scan.Alt;import oolex.Scan.Set;import oolex.Scan.Word;import oolex.scanobjects.Int;import oolex.scanobjects.Flt;import oolex.scanobjects.JavaIdentifier;import oolex.scanobjects.JavaWhitespace;import oolex.scanobjects.QuotedString;import oolex.scanobjects.SlashSlashComment;import oolex.scanobjects.HashComment;import oolex.scanobjects.JavadocComment;import java.io.InputStreamReader;import java.io.FileReader;/** An example to meassure the scanning time using oolex 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 TypicalCompilerScannerByOOlex { public static void main(String args[]) throws Exception { Action wordAction = new Action () { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.word(new String(buf, off, len)); } }; Action commentAction = new Action () { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.comment(new String(buf, off, len)); } }; Scan scanner = new Alt(new Scan[] { new Word("<=").setAction(wordAction), new Word(">=").setAction(wordAction), new Word("==").setAction(wordAction), new Word("&&").setAction(wordAction), new Word("||").setAction(wordAction), new Int().setAction(new Action() { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.integer(new String(buf, off, len)); } }), new Flt().setAction(new Action() { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.floating(new String(buf, off, len)); } }), new JavaIdentifier().setAction(new Action() { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.identifier(new String(buf, off, len)); } }), new JavaWhitespace().setIgnore(false).setAction(new Action() { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.whitespace(new String(buf, off, len)); } }), new QuotedString().setAction(new Action() { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.quotedText(new String(buf, off, len)); } }), new QuotedString('\'').setAction(new Action() { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.quotedChar(buf[off]); } }), new Set("+-=/*@/!<>?:;|[]{}().,%&", true).setAction(new Action() { public void action(Scan sender, char[] buf, int off, int len) { PrintTypicalCompilerSymbols.character(buf[off]); } }), new SlashSlashComment().setAction(commentAction).setIgnore(false), new HashComment().setAction(commentAction).setIgnore(false), new JavadocComment().setAction(commentAction).setIgnore(false) }); int front = 1024, rear = 1024; try { front = Integer.parseInt(System.getProperty("TypicalCompilerScannerByOOlex.front")); } catch (Exception e) { System.err.println(e); } try { rear = Integer.parseInt(System.getProperty("TypicalCompilerScannerByOOlex.rear")); } catch (Exception e) { System.err.println(e); }System.err.println("go (front "+front+", rear "+rear+")..."); long old = System.currentTimeMillis();System.err.println("start time\t"+old+"..."); Input input = new Input(args.length != 0 ? new FileReader(args[0]) :new InputStreamReader(System.in), front, rear); while (input.token(scanner)) ; long current = System.currentTimeMillis();System.err.println("end time\t"+current+"..."); TimeUtil.printMilliSecons("time: ", current-old, System.err); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -