diff --git a/Scanning.py b/Scanning.py index 24226b443011e851e38d9977236fd218e9ef6e64..3df1440cf6f3148e71d62c6460a6751350eab084 100644 --- a/Scanning.py +++ b/Scanning.py @@ -478,7 +478,7 @@ def scan(input): # Checking integer range (does not cover all edge cases) elif token.name == 'NUM' and index > 0 and tokens[index-1].name == 'SUB' and int(token.lex) > 2147483648: return (None, "integer too small") - elif token.name == 'NUM' and int(token.lex) > 2147483647: + elif token.name == 'NUM' and int(token.lex) > 2147483647 and (index is 0 or tokens[index-1].name is not 'SUB'): return (None, "interger too large") @@ -514,4 +514,5 @@ def scan(input): # remove whitespace, newline characters and comments tokens = list(filter(lambda t: t.name not in ("WHITESPACE", "COMMENT", 'LCOMMENT', 'RCOMMENT', 'NEWLINE', 'NEWLINEC', 'LCOM2', 'LCOM3'), tokens)) + return (tokens, "success") diff --git a/Weeding.py b/Weeding.py index 0b86e7ab35c4aa65fa4403a4433a17042b4fc363..72ec68ecc919d7e176b7787b74649dfcbbebcf6a 100644 --- a/Weeding.py +++ b/Weeding.py @@ -5,6 +5,7 @@ import os def weedTokens(tokens, file): result = fileNameCheck(tokens, file) result += extendCheck(tokens) + result += intRangeCheck(tokens) return result @@ -32,6 +33,13 @@ def extendCheck(tokens): check = True return "" +def intRangeCheck(tokens): + for index, token in tokens: + if token.name == 'NUM' and index > 0 and tokens[index-1].name == 'SUB' and int(token.lex) > 2147483648: + return ("ERROR: integer too small") + if token.name == 'NUM' and int(token.lex) > 2147483647 and (index is 0 or tokens[index-1].name is not 'SUB'): + return ("ERROR: integer too large") + return "" ######################## Weeding after parsing ################################