-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.java
More file actions
62 lines (49 loc) · 1.32 KB
/
Parser.java
File metadata and controls
62 lines (49 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class terminalSymbol{}
public class Parser {
//abB
public static terminalSymbol[] B(String input){
if input[0]=='a' && input[1]=='b'{
B(str.substring(2,input))
}
}
//a(bB)*
public static terminalSymbol[] B(String input){
String[] arrOfStr = input.split("b");
for (String a: arrOfStr)
arr+=B(str.substring(1,a))
arr = new terminalSymbol[]
if input[0]=='a'{
return arr
}
throw new Error()
}
//a(bB)?
public static terminalSymbol[] B(String input){
if !input.contains("b")
throw new Error()
arr = new terminalSymbol[]
String[] arrOfStr = input.split("b");
for (String a: arrOfStr)
arr += B(str.substring(2,a))
if input[0]=='a'{
return arr
}
throw new Error()
}
//aA | bB | c(aC)*
public static terminalSymbol[] B(String input){
if input[0]=='a'{
A(str.substring(1,input))
}else if input[0]=='b'{
B(str.substring(1,input))
}else if input[0]=='c'{
if(input[1]=='a'){
C(str.substring(2,input))
}else {
throw new Error()
}
}else {
throw new Error()
}
}
}