⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typicalcompilerscannerbylolo.java

📁 JAVA在编译原理上的应用。
💻 JAVA
字号:
package lolo.test;import lolo.Input;import lolo.Scan;import lolo.Scan.Action;import lolo.Scanner;import lolo.scans.Word;import lolo.scans.JavaIdentifier;import lolo.scans.SimpleIdentifier;import lolo.scans.Int;import lolo.scans.SimpleWhitespace;import lolo.scans.JavaWhitespace;import lolo.scans.Flt;import lolo.scans.QuotedText;import lolo.scans.QuotedChar;import lolo.scans.SlashSlashComment;import lolo.scans.Set;import lolo.scans.JavadocComment;import java.io.StringReader;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.ObjectOutputStream;import java.io.ObjectInputStream;import java.io.FileOutputStream;import java.io.FileInputStream;import java.io.FileReader;/** An example to meassure the scanning time using lolo 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 TypicalCompilerScannerByLolo {    public static void main(String args[]) throws Exception {        Action wordAction = new Action () {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.word(new String(buffer, off, len));            }        };        Action commentAction = new Action () {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.comment(new String(buffer, off, len));            }        };        Scanner scanner = new Scanner();                scanner.add(new Word("<=").setAction(wordAction));        scanner.add(new Word(">=").setAction(wordAction));        scanner.add(new Word("==").setAction(wordAction));        scanner.add(new Word("&&").setAction(wordAction));        scanner.add(new Word("||").setAction(wordAction));        scanner.add(new Int().setAction(new Action() {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.integer(new String(buffer, off, len));            }        }));        scanner.add(new Flt(false).setAction(new Action() {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.floating(new String(buffer, off, len));            }        }));        scanner.add(new SimpleIdentifier().setAction(new Action() {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.identifier(new String(buffer, off, len));            }        }));        scanner.add(new SimpleWhitespace().setIgnore(false).setAction(new Action() {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.whitespace(new String(buffer, off, len));            }        }));        scanner.add(new QuotedText().setAction(new Action() {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.quotedText(new String(buffer, off, len));            }        }));        scanner.add(new QuotedChar().setAction(new Action() {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.quotedChar(buffer[off]);            }        }));        scanner.add(new Set("+-=/@*/!<>?:;|[]{}().,%&").setAction(new Action() {            public void action(Scan sender, char [] buffer, int off, int len) {                PrintTypicalCompilerSymbols.character(buffer[off]);            }        }));        scanner.add(new SlashSlashComment().setAction(commentAction).setIgnore(false));        scanner.add(new JavadocComment().setAction(commentAction).setIgnore(false));        if (System.getProperty("TypicalCompilerScannerByLolo.unicode") != null)            scanner.setUnicode(true);  // forces repack of table        int bufferSize = 1024;        try {            bufferSize = Integer.parseInt(System.getProperty("TypicalCompilerScannerByLolo.bufferSize"));        } catch (Exception e) {            System.err.println(e);        }                scanner.pack();System.err.println("go (bufferSize "+bufferSize+", unicode "+scanner.getUnicode()+")...");        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), bufferSize);        while (scanner.scan(input) != null)            ;                    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 + -