KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestExpTree


1 import lexer.*;
2 import lexer.exceptions.*;
3 import java.util.*;
4
5 class TestExpTree {
6     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
7         
8 // String parseString = "(((a(f|a)*dsn|b)((a|b|c))(a)\\*a*af(ab|c)a)*)";
9
// String parseString = "(a(b|c)d*(e|f)*)|b*";
10
String JavaDoc parseString = "(ab)|c*";
11         System.out.println("Parse String: "+parseString);
12         try {
13             ExpList el = new ExpList(parseString);
14             System.out.println("List: "+el);
15
16             ExpTree et = new ExpTree(el);
17             System.out.print("Tree: ");
18             Iterator it = et.preIterator();
19             while (it.hasNext()) {
20                 System.out.print(it.next());
21             }
22             System.out.println();
23             
24             RTS r = new RTS(et);
25             r.print();
26             
27             DFA d = new DFA(r);
28             d.print();
29             
30 /* String s;
31             s = "";
32             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
33             s = "b";
34             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
35             s = "bbbbb";
36             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
37             s = "acfef";
38             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
39             s = "abdef";
40             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
41             s = "ab";
42             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
43             s = "acdddddeeefefe";
44             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
45             s = "ccfef";
46             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
47             s = "abdaef";
48             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
49             s = "abdfb"; // Error?
50             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
51             s = "abdffd";
52             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
53             s = "abdffbb";
54             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
55             s = "abb";
56             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));
57             s = "acc";
58             System.out.println("acceptsString(\""+s+"\"): "+d.acceptsString(s));*/

59             
60         } catch (ExpParseError e) {
61             e.printStackTrace();
62             System.err.println(parseString);
63             System.err.println(e.emphasize());
64             System.exit(-1);
65         }
66     }
67 }
68
Popular Tags