-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegularExpParser.java
More file actions
45 lines (37 loc) · 1.32 KB
/
RegularExpParser.java
File metadata and controls
45 lines (37 loc) · 1.32 KB
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
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
/**
*
* @author khalil, awilson40, jcanida
*/
public class RegularExpParser {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//** Creating a scanner for user's input
Scanner scanner = new Scanner(System.in);
//* Getting user's input
System.out.println("Enter regular expression: ");
String regularExpression = scanner.nextLine();
System.out.println("Enter maximum accepted string length: ");
int length = scanner.nextInt();
scanner.nextLine();
Parser parser = new Parser();
String postfixRegEx = parser.ParseRegExString(regularExpression);
//System.out.println(postfixRegEx);
NFA nfa = new NFA();
nfa.generate(postfixRegEx);
Set<String> stringSet = new HashSet();
stringSet = GraphTraverser.TraverseGraph(nfa, length);
if (stringSet != null && !stringSet.isEmpty()) {
System.out.println("Printing result");
System.out.println(stringSet);
//Test.TestRegex(regularExpression.replaceAll("\\s+", ""), stringSet, length, false);
}else{
System.out.println("There are no accepted strings.");
}
}
}