diff --git a/Test.py b/Test.py index 72d5abee424709521b94d71f25b1b01190b61ae8..e92c8276c7a29db33fdad4cd70ad01213714b5fa 100644 --- a/Test.py +++ b/Test.py @@ -4,6 +4,7 @@ from os.path import isfile, join from Scanning import scan from Parsing import parse +import Weeding def allFiles(testDir): @@ -19,28 +20,42 @@ def main(): for f in testFiles: # print(f) - # Scanning + # Scanning content = open(f, "r").read() (tokens, errorString) = scan(content) - # Error in Scanning + # Error in Scanning if tokens is None: # print("ERROR in Scanning: " + errorString) print("**********************************************************") continue - # s = "All Tokens: " - # for token in tokens: - # if (token.name and token.lex): - # s += '(' + token.name + ',' + token.lex + '), ' - # print(s) - + s = "All Tokens: " + for token in tokens: + if (token.name and token.lex): + s += '(' + token.name + ',' + token.lex + '), ' + print(s) + + # No weeds if everything is good (weeds = None) + weeds = Weeding.fileNameCheck(tokens, f) + if weeds: + print(weeds) + continue + + + # Parsing # print("Parsing starts") - try: - (steps, errorString) = parse(tokens) - except: - print("Exception in Parsing") + # try: + # (steps, errorString) = parse(tokens) + # except: + # print("Exception in Parsing") + # + # # Error in Parsing + # if steps is None: + # print("ERROR in Parsing: ", errorString) + # print("**********************************************************") + # continue # Error in Parsing if steps is None: @@ -54,4 +69,4 @@ def main(): print("**********************************************************") -main() \ No newline at end of file +main() diff --git a/Weeding.py b/Weeding.py index b918cac3e9c56995d4890991effb9e6a9ad44cc2..93abb8de6df3eb5617a14fc678b2fe91ba30cbfc 100644 --- a/Weeding.py +++ b/Weeding.py @@ -1,6 +1,22 @@ import string +import os ##################### Weeding ########################################## +def fileNameCheck(tokens, f): + fileName = os.path.basename(f).split('.java')[0] + + check = False + for t in tokens: + if check: + if (t.lex != fileName): + print(t.lex, fileName) + return ("ERROR: Class or Interface name should be the same as file name.") + return None + if t.name == 'INTERFACE' or t.name == 'CLASS': + check = True + return None + + # node: Node[] def oneConstructor(node, insideClass): @@ -14,7 +30,7 @@ def oneConstructor(node, insideClass): elif insideClass: if node.name == 'constructorDcl': return True - + # tree: Node[] def weed(tree):