Skip to content
Snippets Groups Projects
joosc.py 1.17 KiB
import sys
import random as random
from os import listdir
from os.path import isfile, join

from Scanning import scan
from Parsing import parse
from AstBuilding import astBuild, buildEnvAndLink
import Weeding


def main():
    inputFiles = [f for f in sys.argv[1:]]

    parseTrees = []

    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:
        buildEnvAndLink(ASTs)
    except Exception as e:
        return 42 # double local variable declarations

    return 0

re = main()
print(re)