Skip to content

Commit 966e352

Browse files
Add files via upload
0 parents  commit 966e352

File tree

15 files changed

+920
-0
lines changed

15 files changed

+920
-0
lines changed

IT327/Asg1/LL1.class

2.92 KB
Binary file not shown.

IT327/Asg1/LL1.java

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* LL1 is a recirsive descent parser created by Seth Tummillo, a student at Illinois State University
3+
* I own the code written below and forbid anyone to use the code below without my written consent.
4+
*
5+
*/
6+
7+
8+
import java.util.StringTokenizer;
9+
import java.util.NoSuchElementException;
10+
11+
public class LL1 {
12+
13+
public static String token;
14+
public static StringTokenizer st;
15+
16+
public static void main(String[] args) {
17+
18+
String expression = convertExp(args[0]);
19+
st = new StringTokenizer(expression, "()*/+-$", true );
20+
token = st.nextToken();
21+
try {
22+
e();
23+
System.out.println("Yes");
24+
} catch (IllegalArgumentException e) {
25+
System.out.println("No");
26+
} catch (NoSuchElementException e) {
27+
System.out.println("No");
28+
}
29+
}
30+
31+
public static void e() {
32+
switch (token) {
33+
case "n":
34+
t();ePrime();
35+
break;
36+
case "(":
37+
t();ePrime();
38+
break;
39+
default:
40+
throw new IllegalArgumentException();
41+
}
42+
return;
43+
}
44+
45+
public static void ePrime(){
46+
switch (token) {
47+
case "+":
48+
token=st.nextToken();t();ePrime();
49+
break;
50+
case "-":
51+
token=st.nextToken();t();ePrime();
52+
break;
53+
case ")":
54+
return;
55+
//break;
56+
case "$":
57+
return;
58+
//break;
59+
default:
60+
throw new IllegalArgumentException();
61+
}
62+
return;
63+
}
64+
65+
public static void t() {
66+
switch (token) {
67+
case "n":
68+
f();tPrime();
69+
break;
70+
case "(":
71+
f();tPrime();
72+
break;
73+
default:
74+
throw new IllegalArgumentException();
75+
}
76+
return;
77+
}
78+
79+
public static void tPrime() {
80+
switch (token) {
81+
case "+":
82+
return;
83+
//break;
84+
case "-":
85+
return;
86+
//break;
87+
case "*":
88+
token=st.nextToken();f();tPrime();
89+
break;
90+
case "/":
91+
token=st.nextToken();f();tPrime();
92+
break;
93+
case ")":
94+
return;
95+
//break;
96+
case "$":
97+
return;
98+
//break;
99+
default:
100+
throw new IllegalArgumentException();
101+
}
102+
return;
103+
}
104+
105+
public static void f() {
106+
switch (token) {
107+
case "n":
108+
token=st.nextToken();
109+
break;
110+
case "(":
111+
token=st.nextToken();e();token=st.nextToken();
112+
break;
113+
default:
114+
throw new IllegalArgumentException();
115+
}
116+
return;
117+
118+
}
119+
120+
121+
122+
//Converts the numbers in a string to n if they are valid numbers
123+
public static String convertExp(String initial) {
124+
String converted = "";
125+
126+
StringTokenizer temp = new StringTokenizer(initial.concat("$"),"()*/+-$", true );
127+
while (temp.hasMoreTokens()) {
128+
String token = temp.nextToken();
129+
if (isNumeric(token)) {
130+
token = "n";
131+
}
132+
converted=converted.concat(token);
133+
134+
}
135+
return converted;
136+
}
137+
138+
//checks if a given string is a numeric number. Used in the convertExp method.
139+
public static boolean isNumeric(String strNum) {
140+
try {
141+
double d = Integer.parseInt(strNum);
142+
} catch (NumberFormatException | NullPointerException nfe) {
143+
return false;
144+
}
145+
return true;
146+
}
147+
148+
}
149+
150+
151+
152+

IT327/Asg1/output.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
No
2+
Yes
3+
Yes
4+
Yes

IT327/Asg2/Key.class

1.4 KB
Binary file not shown.

IT327/Asg2/Key.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
public class Key {
3+
private int state;
4+
private String symbol;
5+
private int value;
6+
7+
public Key(String symbol, int state, int value) {
8+
this.state = state;
9+
this.symbol = symbol;
10+
this.value = value;
11+
}
12+
13+
14+
15+
public Key() {
16+
this.state = 0;
17+
this.symbol = "-";
18+
this.value = 0;
19+
}
20+
21+
22+
23+
public int getState() {
24+
return state;
25+
}
26+
27+
public String getSymbol() {
28+
return symbol;
29+
}
30+
31+
public int getValue() {
32+
return value;
33+
}
34+
35+
public void setSymbol(String symbol) {
36+
this.symbol = symbol;
37+
}
38+
39+
public void setState(int state) {
40+
this.state = state;
41+
}
42+
43+
public void setValue(int value) {
44+
this.value = value;
45+
}
46+
47+
48+
49+
@Override
50+
public String toString() {
51+
if (symbol == "n")
52+
return "[" + value + ":" + state + "]";
53+
else
54+
return "[" + symbol + ":" + state + "]";
55+
}
56+
57+
58+
59+
60+
61+
}
62+
63+
64+

IT327/Asg2/LR1.class

10.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)