-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewlang3Main.java
47 lines (42 loc) · 997 Bytes
/
newlang3Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import newlang3.*;
import java.io.*;
class newlang3Main {
public static void main(String[] args) {
InputStream in;
String fileName="test.bas";
LexicalAnalyzer la;
LexicalUnit lu;
if (args.length>0){
fileName=args[0];
}
try{
in=new FileInputStream(fileName);
} catch(IOException e) {
System.out.println(fileName+"を読み込めませんでした。");
return;
}
la=new LexicalAnalyzerImpl(in);
try {
while(true){
System.out.print(la.getLine()+": ");
lu=la.get();
System.out.println(lu);
if (lu.getType()==LexicalType.EOF){
break;
}
}
} catch (IOException e){
System.out.println("I/Oエラーが発生しました。");
} catch (SyntaxException e){
System.out.println(e.getMessage());
} catch (Exception e){
System.out.println("不明な例外:"+e);
} finally {
try {
in.close();
} catch(IOException e){
System.out.println("ファイルのクローズに失敗しました。");
}
}
}
}