Esempio n. 1
0
def main():

    content = ""
    path = os.getcwd()

    try:
        fileName = sys.argv[1]
    except:
        print(
            "[ERROR] Expected 1 Argument Containing File Name to be Run e.g 'tachyon main.tn'"
        )
        return

    if fileName[len(fileName) - 3:len(fileName)] != ".cosmix":
        print(
            "[ERROR] File extension not recognised please make sure extension is '.tn'"
        )
        return

    try:
        print('[ERROR] Expected 1 argument found 2 (' + sys.argv[1] + ", " +
              sys.argv[2] + ')')
        return  # quit programme
    except:
        pass

    # Open source code file and get it's content and save it to the 'contents' var
    try:
        with open(path + "/" + fileName, "r") as file:
            content = file.read()
    except:
        print('Cannot find "' + fileName + '"')

    print('LEXER LOG \n')

    lex = lexer.Lexer()

    tokens = lex.tokenize(content)
    print(tokens)

    print('  PARSER LOG \n')
    Parser = parser.Parser(tokens)
    source_ast = Parser.parse(tokens)
    print(source_ast)

    print('  OBJECT GENERATION LOG   \n')
    object_generator = objgen.ObjectGenerator(source_ast)

    exec_string = object_generator.object_definer(False)

    print(' TRANSPILED CODE  \n')
    print(exec_string)
    print('\n')

    print('OUTPUT  \n')
    exec(exec_string)
    print('\n| \n')
Esempio n. 2
0
def main():
    content = ""
    path = os.getcwd()

    try:
        fileName = sys.argv[1]
    except:
        print("[ERROR] Expected 1 Argument Containing File Name to be Run e.g 'fluffy main.f'")
        return

    if fileName[len(fileName) - 2:len(fileName)] != ".f":
        print("[ERROR] File extension not recognised please make sure extension is '.tn'")
        return  # quit program

    try:
        print('[ERROR] Expected 1 argument found 2 (' + sys.argv[1] + ", " + sys.argv[2] + ')')
        return  # quit program
    except:
        pass

    try:
        with open(path + "/" + fileName, "r") as file:
            content = file.read()
    except:
        print('Cannot find "' + fileName + '"')

    lex = Lexer.Lexer()
    tokens = lex.tokenize(content)

    parser = Parser.Parser(tokens)
    source_ast = parser.parse(tokens)

    object_gene = objgen.ObjectGenerator(source_ast)
    exec_string = object_gene.object_generation(False)

    print(exec_string)
Esempio n. 3
0
def main():

    content = ""  # This variable will hold the contents of the source code
    path = os.getcwd()  # Holds path this script was executed from

    # Holds the name of the file the user wants to compile
    try:
        fileName = sys.argv[1]
    except:
        print(
            "[ERROR] Expected 1 Argument Containing File Name to be Run e.g 'gleem main.gl'"
        )
        return

    # Check if the file extension is correct
    if fileName[len(fileName) - 3:len(fileName)] != ".gl":
        print(
            "[ERROR] File extension not recognised please make sure extension is '.gl'"
        )
        return  # quit programme

    # Check to make sure that only one argument is passed
    try:
        print('[ERROR] Expected 1 argument found 2 (' + sys.argv[1] + ", " +
              sys.argv[2] + ')')
        return  # quit programme
    except:
        pass

    # Open source code file and get it's content and save it to the 'contents' var
    try:
        with open(path + "/" + fileName, "r") as file:
            content = file.read()
    except:
        print('Cannot find "' + fileName + '"')

    # --------------------------------------
    #  LEXER
    # --------------------------------------

    print('|||||||||||||||||||||  LEXER LOG  ||||||||||||||||||||| \n')
    # Create an instance of the lexer class
    lex = lexer.Lexer()

    # Call lexer method to perform lexical analysis on code
    tokens = lex.tokenize(content)
    print(tokens)
    print('\n||||||||||||||||||||||||||||||||||||||||||||||||||||||| \n')

    # --------------------------------------
    #  PARSER
    # --------------------------------------

    print('|||||||||||||||||||||  PARSER LOG  |||||||||||||||||||| \n')
    # Create an instance of the parser class
    Parser = parser.Parser(tokens)

    # Call the parser method and pass in the tokens as arguments
    source_ast = Parser.parse(tokens)
    print(source_ast)
    print('\n||||||||||||||||||||||||||||||||||||||||||||||||||||||| \n')

    # --------------------------------------
    # Object Generation
    # --------------------------------------

    print('||||||||||||||||  OBJECT GENERATION LOG  ||||||||||||||| \n')
    # Create an instance of the Object Generator (objgen) class
    object_generator = objgen.ObjectGenerator(source_ast)

    # Call the object definer to get python exec() string
    exec_string = object_generator.object_definer(False)
    print('\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||| \n')

    # Execute the gleem code that has been transpiled to python code to get output
    print('|||||||||||||||||||  TRANSPILED CODE  |||||||||||||||||| \n')
    print(exec_string)
    print('\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||| \n')

    print('|||||||||||||||||||||||  OUTPUT  ||||||||||||||||||||||| \n')
    exec(exec_string)
    print('\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||| \n')
def main():

    content = ""  # This variable will hold the contents of the source code
    path = os.getcwd()  # Holds path this script was executed from

    # Holds the name of the file the user wants to compile
    try:
        fileName = sys.argv[1]
    except:
        print(' +---------------------------------------------+')
        print(' |               Y# - v1.0                     |')
        print(' |          Developed By Yehan Wasura          |')
        print(' +---------------------------------------------+')
        print("     Operating System : " + platform.system())
        print("     Release          : " + platform.release())
        print("     Y# Version       : v1.2.0")
        print(' +---------------------------------------------+')
        print(
            "Please use this command for run a program on this compiler : python3 main.py filename.yshp"
        )
        return

    # Check if the file extension is correct
    if fileName[len(fileName) - 5:len(fileName)] != ".yshp":
        print(
            "[ERROR] File extension not recognised please make sure extension is '.yshp'"
        )
        return  # quit programme

    # Check to make sure that only one argument is passed
    try:
        print('[ERROR] Expected 1 argument found 2 (' + sys.argv[1] + ", " +
              sys.argv[2] + ')')
        return  # quit programme
    except:
        pass

    # Open source code file and get it's content and save it to the 'contents' var
    try:
        with open(path + "/" + fileName, "r") as file:
            content = file.read()
    except:
        print('Cannot find "' + fileName + '"')

    # --------------------------------------
    #  LEXER
    # --------------------------------------

    # Create an instance of the lexer class
    lex = lexer.Lexer()

    # Call lexer method to perform lexical analysis on code
    tokens = lex.tokenize(content)

    # --------------------------------------
    #  PARSER
    # --------------------------------------

    # Create an instance of the parser class
    Parser = pars.Parser(tokens)

    # Call the parser method and pass in the tokens as arguments
    source_ast = Parser.parse(tokens)

    # --------------------------------------
    # Object Generation
    # --------------------------------------

    # Create an instance of the Object Generator (objgen) class
    object_generator = objgen.ObjectGenerator(source_ast)

    # Call the object definer to get python exec() string
    exec_string = object_generator.object_definer(False)

    # Execute the Y# code that has been transpiled to python code to get output
    print(' +---------------------------------------------+')
    print(' |               Y# - v1.0                     |')
    print(' |          Developed By Yehan Wasura          |')
    print(' +---------------------------------------------+')
    print("     Operating System : " + platform.system())
    print("     Release          : " + platform.release())
    print("     Y# Version       : v1.2.0")
    print(' +---------------------------------------------+\n\n')

    print("Filename: " + fileName + '\n\n')
    print('|||||||||||||||||||||||  OUTPUT  ||||||||||||||||||||||| \n')
    exec(exec_string)
    print('\n|||||||||||||||||||||||||||||||||||||||||||||||||||||||| \n')