summaryrefslogtreecommitdiffstats
path: root/src/Compiler/TokenScanner.java
diff options
context:
space:
mode:
authorAidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com>2021-11-22 16:30:45 +0000
committerAidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com>2021-11-22 16:30:45 +0000
commit8e368b67de60442c483bd9def7036e52562ccc81 (patch)
tree947d775285ad2df464177df8ec9e1d63e99cae0d /src/Compiler/TokenScanner.java
parentab5584190b83a8cda9cbb3469ce841dbaa3aa38a (diff)
downloadesotericFORTRAN-8e368b67de60442c483bd9def7036e52562ccc81.tar.gz
esotericFORTRAN-8e368b67de60442c483bd9def7036e52562ccc81.zip
Improved error handing and added logical statements
Diffstat (limited to 'src/Compiler/TokenScanner.java')
-rw-r--r--src/Compiler/TokenScanner.java35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/Compiler/TokenScanner.java b/src/Compiler/TokenScanner.java
index 49500c5..5f55119 100644
--- a/src/Compiler/TokenScanner.java
+++ b/src/Compiler/TokenScanner.java
@@ -10,6 +10,7 @@ public class TokenScanner {
List<Token> tokens = new ArrayList<>();
private int tokenStart=0;
private int currentLoc=0;
+ private int line=0;
//Extract tokens from the source code by reading character by character
List<Token> extractTokens(String sourceCode){
@@ -18,7 +19,7 @@ public class TokenScanner {
tokenStart=currentLoc;
readToken();
}
- tokens.add(new Token(TokenType.EOF, "", null));
+ tokens.add(new Token(TokenType.EOF, "", null,line));
return tokens;
}
@@ -28,7 +29,9 @@ public class TokenScanner {
switch(checkChar){
case ' ':break;
- case '\n':break;
+ case '\n':
+ line++;
+ break;
case '\r':break;
case '\t':
break;
@@ -81,12 +84,34 @@ public class TokenScanner {
currentLoc++;
}
if(checkEOF()){
- Language.displayError("Strings must end with \"");
+ Language.displayError(line, "Strings must end with a closing \"");
break;
}
currentLoc++;
createToken(TokenType.STRING, sourceCode.substring(tokenStart, currentLoc+1));
break;
+ case '.':
+ if(checkIsAlpha(lookAhead()))
+ while (checkIsAlpha(lookAhead())){
+ currentLoc++;
+ }
+ String logical = sourceCode.substring(tokenStart+1, currentLoc+1);
+ if (checkNextChar('.')){
+ if (logical.equals("and")){
+ createTokenNull(TokenType.AND);
+ break;
+ } else if(logical.equals("or")){
+ createTokenNull(TokenType.OR);
+ break;
+ } else if(logical.equals("not")){
+ createTokenNull(TokenType.NOT);
+ break;
+ } else{
+ Language.displayError(line, "Expected logical expression");
+ }
+ } else {
+ Language.displayError(line, "Expected '.' after logical expression");
+ }
default:
//Check for numer
@@ -122,7 +147,7 @@ public class TokenScanner {
}
} else {
- Language.displayError("Unexpected Character");
+ Language.displayError(line,"Unexpected Character");
}
}
currentLoc++;
@@ -142,7 +167,7 @@ public class TokenScanner {
//Create token
private void createToken(TokenType type, Object value){
String tokenText = sourceCode.substring(tokenStart, currentLoc+1);
- tokens.add(new Token(type, tokenText, value));
+ tokens.add(new Token(type, tokenText, value, line));
}
//Check if the next char matches a given char