Skip to content

Commit 6148d6f

Browse files
JazzepiJazzepi
Jazzepi
authored and
Jazzepi
committed
1 parent 371a3fe commit 6148d6f

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/lexer/TextFile.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public Token getToken()
143143

144144
String returnTokText = null;
145145
TokenType returnTokType = null;
146-
StringTokenizer st = new StringTokenizer(rVal," \t;(){}=!<>+-/*%",true);
146+
StringTokenizer st = new StringTokenizer(rVal," \t;(){}=!<>+-,/*%",true);
147147
String temp = st.nextToken();
148148
String lookAhead = null;
149149

@@ -180,17 +180,17 @@ else if(TokenType.matchesToken(TokenType.GAMEORDER, temp))
180180
}
181181
else if(TokenType.matchesToken(TokenType.SYMBOL, temp))
182182
{
183-
if(temp.matches("=") && lookAhead == null) //This is the last token, so it must just be the = symbol
183+
if(temp.equals("=") && lookAhead == null) //This is the last token, so it must just be the = symbol
184184
{
185185
returnTokText = temp;
186186
returnTokType = TokenType.SYMBOL;
187187
}
188-
else if(temp.matches("=") && lookAhead != null) //This is not the last token, so something must come after it
188+
else if(temp.equals("=") && lookAhead != null) //This is not the last token, so something must come after it
189189
{
190-
if(lookAhead.matches("="))//Check to see if you actually found == instead of just =
190+
if(lookAhead.equals("="))//Check to see if you actually found == instead of just =
191191
{
192192
returnTokText = temp.concat(lookAhead);
193-
returnTokType = TokenType.SYMBOL;
193+
returnTokType = TokenType.CONDITION;
194194
}
195195
else //Wasn't ==, so it must just be the symbol operator for assignment
196196
{
@@ -205,11 +205,11 @@ else if(temp.matches("=") && lookAhead != null) //This is not the last token, so
205205
}
206206

207207
}
208-
else if(temp.matches("!") ||temp.matches("<") ||temp.matches(">")) //Must be a condition
208+
else if(temp.equals("!") ||temp.equals("<") ||temp.equals(">")) //Must be a condition
209209
{
210-
if(temp.matches("!"))//Must have = after it, or it's an error
210+
if(temp.equals("!"))//Must have = after it, or it's an error
211211
{
212-
if(lookAhead.matches("="))
212+
if(lookAhead != null && lookAhead.equals("="))
213213
{
214214
returnTokText = temp + lookAhead;
215215
returnTokType = TokenType.CONDITION;
@@ -221,9 +221,9 @@ else if(temp.matches("!") ||temp.matches("<") ||temp.matches(">")) //Must be a c
221221
}
222222
}
223223

224-
if(temp.matches("<") || temp.matches(">"))
224+
if(temp.equals("<") || temp.equals(">"))
225225
{
226-
if(lookAhead == null || !lookAhead.matches("="))
226+
if(lookAhead == null || !lookAhead.equals("="))
227227
{
228228
returnTokText = temp;
229229
returnTokType = TokenType.CONDITION;

src/lexer/Token.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
public class Token {
77

88
private static String[] WS1 = {"\t"," "};
9-
private static String[] IDENTIFIER1 = {"0","1","2","3","4","5","6","7","8","9","10",
9+
private static String[] IDENTIFIER1 = {"0","1","2","3","4","5","6","7","8","9",
1010
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
1111
"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","_"};
1212
private static String[] DIGITS1 = {"0","1","2","3","4","5","6","7","8","9"};
1313
private static String[] OPERATOR1 = {"+","-","/","*","%"};
14-
private static String[] SYMBOL1 = {";",")","(","}","{","="};
14+
private static String[] SYMBOL1 = {";",")","(","}","{","=",","};
1515
private static String[] CONDITION1 = {"!=", "==", "<", ">", "<=", ">="};
16-
private static String[] KEYWORD1 = {"IF", "IFELSE", "VAR", "SUBROUTINE", "RETURN", "MAIN", "WHILE"};
16+
private static String[] KEYWORD1 = {"IF", "IFELSE","ELSE", "VAR", "SUBROUTINE", "RETURN", "MAIN", "WHILE"};
1717
private static String[] GAMEFUNCTION1 = {"isEnemyInRange","isHealth","directionOfClosestEnemy"};
1818
private static String[] GAMEORDER1 = {"move","turn","skip","selfDestruct","attackWithWeapon","useItem"};
1919

@@ -61,7 +61,7 @@ else if(type == TokenType.IDENTIFIER)
6161
{
6262
for(String element : type.collection)
6363
{
64-
if(element.startsWith(text))
64+
if(element.equals(text))
6565
{
6666
flag = true;
6767
}

0 commit comments

Comments
 (0)