Skip to content
Snippets Groups Projects
Commit 541fddee authored by pycsham's avatar pycsham
Browse files

fixed marmoset crash

parent 7cff7676
No related branches found
No related tags found
No related merge requests found
...@@ -494,12 +494,6 @@ def scan(input): ...@@ -494,12 +494,6 @@ def scan(input):
if index < indexRange-1: if index < indexRange-1:
if tokens[index+1].name == 'NUM': if tokens[index+1].name == 'NUM':
return (None, "wrong integer literal: starts with 0") 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")
# dealing with keywords in Java but not in Joos # dealing with keywords in Java but not in Joos
elif token.name == 'ID' and token.lex in wrongJavaKeyWordDict: elif token.name == 'ID' and token.lex in wrongJavaKeyWordDict:
......
...@@ -5,7 +5,7 @@ import os ...@@ -5,7 +5,7 @@ import os
def weedTokens(tokens, file): def weedTokens(tokens, file):
result = fileNameCheck(tokens, file) result = fileNameCheck(tokens, file)
result += extendCheck(tokens) result += extendCheck(tokens)
result += intRangeCheck(tokens) # result += intRangeCheck(tokens)
return result return result
...@@ -33,13 +33,13 @@ def extendCheck(tokens): ...@@ -33,13 +33,13 @@ def extendCheck(tokens):
check = True check = True
return "" return ""
def intRangeCheck(tokens): # def intRangeCheck(tokens):
for index, token in tokens: # for index, t in enumerate(tokens):
if token.name == 'NUM' and index > 0 and tokens[index-1].name == 'SUB' and int(token.lex) > 2147483648: # if t.name == 'NUM' and index > 0 and t[index-1].name == 'SUB' and int(t.lex) > 2147483648:
return ("ERROR: integer too small") # 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'): # if t.name == 'NUM' and int(t.lex) > 2147483647 and (index is 0 or t[index-1].name is not 'SUB'):
return ("ERROR: integer too large") # return ("ERROR: integer too large")
return "" # return ""
######################## Weeding after parsing ################################ ######################## Weeding after parsing ################################
......
joosc 100644 → 100755
File mode changed from 100644 to 100755
...@@ -16,10 +16,12 @@ def main(): ...@@ -16,10 +16,12 @@ def main():
try: try:
(tokens, errorString) = scan(content) (tokens, errorString) = scan(content)
except: except:
print("scan exception")
return 42 return 42
# Error in Scanning # Error in Scanning
if tokens is None: if tokens is None:
print("scan failed")
return 42 return 42
# Weed the tokens # Weed the tokens
...@@ -31,10 +33,12 @@ def main(): ...@@ -31,10 +33,12 @@ def main():
try: try:
(steps, error) = parse(tokens) (steps, error) = parse(tokens)
except: except:
print("parse exception")
return 42 return 42
if steps is None: if steps is None:
print(error) print("parse failed")
# print(error)
return 42 return 42
print("success in scanning and parsing") print("success in scanning and parsing")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment