diff options
Diffstat (limited to 'src/Compiler/TokenScanner.java')
-rw-r--r-- | src/Compiler/TokenScanner.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Compiler/TokenScanner.java b/src/Compiler/TokenScanner.java index 7783c01..27501fa 100644 --- a/src/Compiler/TokenScanner.java +++ b/src/Compiler/TokenScanner.java @@ -79,17 +79,23 @@ public class TokenScanner { //Check for numer if (checkIsDigit(checkChar)){ + String type = "int"; while (checkIsDigit(lookAhead())){ currentLoc++; } //Check if number contains a decimal point if (lookAhead()=='.' && checkIsDigit(lookTwoAhead())){ + type="double"; currentLoc++; while (checkIsDigit(lookAhead())){ currentLoc++; } } - createToken(TokenType.NUMBER, Double.parseDouble(sourceCode.substring(tokenStart, currentLoc+1))); + if (type.equals("double")){ + createToken(TokenType.NUMBER, Double.parseDouble(sourceCode.substring(tokenStart, currentLoc+1))); + } else{ + createToken(TokenType.NUMBER, Integer.parseInt(sourceCode.substring(tokenStart, currentLoc+1))); + } } else if (checkIsAlpha(checkChar)){ while (checkIsAlpha(lookAhead())){ @@ -173,7 +179,8 @@ public class TokenScanner { static { keywords = new HashMap<>(); - keywords.put("var", TokenType.VAR); + keywords.put("int", TokenType.INT); + keywords.put("real", TokenType.REAL); keywords.put("print", TokenType.PRINT); keywords.put("if", TokenType.IF); keywords.put("then", TokenType.THEN); |