Skip to content
Snippets Groups Projects
Commit 62c0e242 authored by pycsham's avatar pycsham
Browse files

Finished joosc.py file. Fixed a small error in ASTBuilding.py

parent fb5945a7
No related branches found
No related tags found
1 merge request!4Chloe environment building
...@@ -24,6 +24,7 @@ def buildEnvAndLink(ASTs): ...@@ -24,6 +24,7 @@ def buildEnvAndLink(ASTs):
try: try:
t[1].recurseBuildEnv(globalEnv) t[1].recurseBuildEnv(globalEnv)
except Exception as e: # to handle double local variable declaration except Exception as e: # to handle double local variable declaration
raise e
print('\n\n\n', t[0]) print('\n\n\n', t[0])
print("###################### Comp Unit Env ####################") print("###################### Comp Unit Env ####################")
t[1].recurseAction("printEnv") t[1].recurseAction("printEnv")
......
...@@ -5,37 +5,54 @@ from os.path import isfile, join ...@@ -5,37 +5,54 @@ from os.path import isfile, join
from Scanning import scan from Scanning import scan
from Parsing import parse from Parsing import parse
from Weeding import weedTokens from AstBuilding import astBuild, buildEnvAndLink
import Weeding
def main(): def main():
inputfile = sys.argv[1] inputFiles = [f for f in sys.argv[1:]]
content = open(inputfile, "r").read()
parseTrees = []
# Scanning
for f in inputFiles:
content = open(f, "r").read()
# Scanning
try:
(tokens, error) = scan(content)
except:
return 42
if tokens is None:
return 42
# Weeding after scanning
# No weeds if everything is good (weeds = None)
weeds = Weeding.fileNameCheck(tokens, f)
if weeds:
return 42
# Parsing
tree = None
try:
(tree, error) = parse(tokens)
except:
return 42
# Error in Parsing
if tree is None:
return 42
parseTrees.append((f, tree))
print(tree)
# Building ASTs from all parse trees
ASTs = astBuild(parseTrees)
try: try:
(tokens, errorString) = scan(content) buildEnvAndLink(ASTs)
except: except Exception as e:
return 42 return 42 # double local variable declarations
# Error in Scanning
if tokens is None:
return 42
# Weed the tokens
weeds = weedTokens(tokens, inputfile)
if weeds != "":
return 42
# Parsing
(steps, error) = parse(tokens)
if steps is None:
return 42
# print("success in scanning and parsing")
return 0 return 0
re = main() re = 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