Skip to content
Snippets Groups Projects
Commit 45be2f18 authored by Xun Yang's avatar Xun Yang
Browse files

implement/extend

parent 46ced3f2
No related branches found
No related tags found
No related merge requests found
import string
import os
##################### Weeding ##########################################
##################### Weeding after scanning ##########################################
def weedTokens(tokens, file):
result = fileNameCheck(tokens, file)
result += extendCheck(tokens)
return result
def fileNameCheck(tokens, f):
fileName = os.path.basename(f).split('.java')[0]
......@@ -9,13 +15,26 @@ def fileNameCheck(tokens, f):
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
return ("ERROR: Class or Interface name should be the same as file name. " + t.lex + " " + fileName + "\n")
return ""
if t.name == 'INTERFACE' or t.name == 'CLASS':
check = True
return None
return ""
def extendCheck(tokens):
check = False
for t in tokens:
if check:
if (not t.lex.startswith('java.' )):
return ("ERROR: Can not extend/implement class type " + t.lex + ". \n")
return ""
if t.name == 'EXTENDS' or t.name == 'IMPLEMENTS':
check = True
return ""
######################## Weeding after parsing ################################
# node: Node[]
......
......@@ -5,22 +5,28 @@ from os.path import isfile, join
from Scanning import scan
from Parsing import parse
from Weeding import weedTokens
def main():
inputfile = sys.argv[1]
content = open(inputfile, "r").read()
# Scanning
try:
(tokens, errorString) = scan(content)
except:
return 42
# Error in Scanning
if tokens is None:
return 42
# Weed the tokens
weeds = weedTokens(tokens, inputfile)
if weeds != "":
return 42
# Parsing
try:
(steps, error) = parse(tokens)
......@@ -34,4 +40,4 @@ def main():
print("success in scanning and parsing")
return 0
main()
\ No newline at end of file
main()
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