use of priv.bajdcc.util.lexer.Lexer in project jMiniLang by bajdcc.
the class TestLexer method main.
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
scanner.close();
Lexer lexer = new Lexer(str);
Token token;
for (; ; ) {
token = lexer.scan();
if (token.kToken == TokenType.EOF) {
break;
}
System.out.println(token.toString());
}
} catch (RegexException e) {
System.err.println(e.getPosition() + "," + e.getMessage());
e.printStackTrace();
}
}
use of priv.bajdcc.util.lexer.Lexer in project jMiniLang by bajdcc.
the class Main method main.
public static void main(String[] args) {
String filename = "E:/vmm.cpp";
try {
// 读文件
BufferedReader br = new BufferedReader(new FileReader(filename));
String line;
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line).append(System.lineSeparator());
}
br.close();
String context = sb.toString();
// 词法分析
Lexer lexer = new Lexer(context);
lexer.discard(TokenType.COMMENT);
lexer.discard(TokenType.WHITESPACE);
lexer.discard(TokenType.ERROR);
Token token;
PrintStream ps = new PrintStream(new FileOutputStream("E:\\output.txt"));
for (; ; ) {
token = lexer.scan();
if (token == null) {
continue;
}
if (token.kToken == TokenType.EOF) {
break;
}
ps.println(token.toString());
ps.flush();
}
ps.close();
} catch (Exception e) {
System.err.print(e.getMessage());
e.printStackTrace();
}
}
Aggregations