Exemple #1
0
# Shell for executing statements
import lexer

while True:
    statement = input("L >> ")
    result = lexer.run(statement)
    print(result)
Exemple #2
0
# Get command line arguments
args = cl_args.get_args()

# Prepare Compiler Environment
prepare_compiler.load_csharp_environment()

# Open source code
f = open(args.src, "r")
if f.mode == 'r':
    # =======================================================
    # =                      Lexer                          =
    # =======================================================
    # msgs_log.print_title("Doing Lexer")
    # start = time.time()
    contents = f.read()
    tokens = lexer.run(contents)
    # end = time.time()
    # print("Execution time: " + str(end - start) + "ms")
    # =======================================================
    # =                     Parser                          =
    # =======================================================
    # msgs_log.print_title("Doing Parser")
    # start = time.time()
    parser = Parser(tokens)
    ast = parser.parse()
    # end = time.time()
    # print("Execution time: " + str(end - start) + "ms")

    # =======================================================
    # =                CSharp Code Generation               =
    # =======================================================
Exemple #3
0
import lexer

fileName = input("Enter your file name: ")

if(fileName == 'stdin'):
    while True:
        text = input('magnus > ')
        result, error = lexer.run(fileName, text)
        if error:
            print(error)
        else:
            print("\n".join(map(str, result)))

else:
    with open(fileName, "r") as f:
        text = f.read()
        result, error = lexer.run(fileName, text)
        if error:
            print(error)
        else:
            print("\n".join(map(str, result)))
Exemple #4
0
import lexer

while True:
    text = input('Tekkom8 > ')
    result, error = lexer.run('<stdin>', text)

    if error: print(error.as_string())
    else: print(result)
Exemple #5
0
import lexer
from parser import Parser
from interpreter import Interpreter
from context import Context
while True:
    text = input("Mscript :>>> ")

    tokens, error = lexer.run('<stdin>',text)

    if error :
        print(error.as_string())
        continue

    print(tokens)
    parse = Parser(tokens)
    ast = parse.parse()

    interpreter = Interpreter()
    root_ctx = Context('<main>')
    result = interpreter.visit(ast.node,root_ctx)


    print(result.value, result.error)

    
    
Exemple #6
0
            error(inputString,"Caracter invalido en nombre archivo:"+"'{}'".format(i))



if __name__ == "__main__":
    tableFile = "z80Table.txt"
    if len(sys.argv)==1:
        source = "entrada.asm"
    else:
        source = sys.argv[1]
    ###Validamos las rutas
    try:
        validateInput(source)
        validateInput(tableFile)

        with open(source) as entrada:
            ListaInstrucciones = entrada.readlines()
        ListaInstrucciones = [x.strip("\n") for x in ListaInstrucciones]
        ###Leeer iun archivo, generar lista de instrucciones
        
        ####Codigos, metodo run.
        tokenList,abstractTokenList,simTable=lexer.run(ListaInstrucciones)
        sizeList,tList,opCodeList,Tabla,codigoObjeto=firstPassParser.run(tableFile,tokenList,abstractTokenList,simTable)##Este hace los prints
        strings = toLST(sizeList,opCodeList,tokenList,Tabla)
        for i in strings:
            print(i)
        for i in codigoObjeto:
            print(i)
    except SalidaException as se:
        print(se)
Exemple #7
0
import lexer
import parser_
import Interpreter_
# def printout(*args):
#     for itr in args:
#         if itr: print(itr)

while True:
    text = input("-> ")
    tokens, error = lexer.run("Shell", text)
    print(tokens)
    if error is not None:
        print(error.as_string())
    # Generate Absract Syntax Tree
    else:
        ast = parser_.create_ast(tokens)
        if ast.error:
            print(ast.node, ast.error.as_string())
        else:
            print(ast.node)
            interprrter = Interpreter_.run(ast.node)
            if interprrter.error:
                print(interprrter.error.as_string())
            else:
                print(interprrter.value)
Exemple #8
0
import lexer
import os
import pprint
pp = pprint.PrettyPrinter(indent=4)

program_path = 'program.txt'

program = open(program_path, 'r').read()

result, error = lexer.run(program, program_path)

if error: print(error.as_string())
else:
    pp.pprint(result)
Exemple #9
0
import lexer

while True:
    output = input('command >> ')
    result, error = lexer.run('<stdin>', output)

    if error:
        print(error.as_string())
    else:
        print(result)