diff --git a/Scanning.py b/Scanning.py index acacf01179209338ef90641047600f329b49de57..cbc0b47af053a8b66ee30c172c2a7e09f0aa21a5 100644 --- a/Scanning.py +++ b/Scanning.py @@ -77,7 +77,6 @@ wrongJavaKeyWordDict = { 'long', 'private', 'strictfp', - 'super', 'switch', 'synchronized', 'throw', @@ -86,7 +85,6 @@ wrongJavaKeyWordDict = { 'try', 'volatile', '_', - 'super', 'Long', 'Float' } @@ -496,10 +494,10 @@ def scan(input): if tokens[index+1].name == 'NUM': return (None, "wrong integer literal: starts with 0") # 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 and (index is 0 or tokens[index-1].name is not 'SUB'): - return (None, "interger too large") + # 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 and (index is 0 or tokens[index-1].name is not 'SUB'): + # return (None, "interger too large") # dealing with keywords in Java but not in Joos @@ -511,6 +509,8 @@ def scan(input): # TODO: need to figure out what is allowed in compID and refactor this checking for explicit this calls elif token.name == 'ID' and token.lex is 'this': return (None, "explicit this call not allowed") + elif token.name == 'ID' and token.lex is 'super': + return (None, "explicit super call not allowed") # Checking wrong keywords in compIDs elif token.name == 'COMPID': @@ -539,4 +539,11 @@ 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)) + for index,token in enumerate(tokens): + # Checking integer range (does not cover all edge cases) + if 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 and (index is 0 or tokens[index-1].name is not 'SUB'): + return (None, "interger too large") + return (tokens, "success")