예제 #1
0
def main():
    global file
    global filename
    try:
        if sys.argv[1] == "console":
            while True:
                code = input()
                interpret(code, 0)
        else:
            file = open(sys.argv[1])
            filename = sys.argv[1]
            setFilename(filename)
            setup(file)
    except OSError:
        print("File does not exist or one isn't specified!")
예제 #2
0
파일: interpretSem.py 프로젝트: Lavui/PBN
def main():
    inter = interpret()
    inter.set_prompt("==>")

    inter.afegeix_ordre("start", start)
    inter.afegeix_ordre("stop", stop)
    inter.afegeix_ordre("emergency", emergency)

    print "Llistat de comandes: ",
    for i in inter.llistar():
        print i + " ",
    print "   surt"

    inter.run()
    ser.close()
예제 #3
0
    def test_compile_no_input_no_output(self) -> None:
        code =  """
                noinputnooutput : -> ;
                stack .
                """
        stack = Stack()
        cont = Continuation(stack)
        cont = cont.execute(interpret(cont, io.StringIO(code)))

        op, found = Type.op("noinputnooutput", cont ) #, "Test")

        assert found
        assert op.sig == TypeSignature([],[])

        op, found = Type.op("not found", cont)
        assert not found
예제 #4
0
파일: main.py 프로젝트: Lavui/PBN
def main():
    interp = interpret()
    interp.set_prompt("->")
    interp.afegeix_ordre("R", run)
    interp.afegeix_ordre("H", halt)
    interp.afegeix_ordre("FA", FA)
    interp.afegeix_ordre("FB", FB)
    interp.afegeix_ordre("?A", stateA)
    interp.afegeix_ordre("?B", stateB)

    print "Port utilitzat: " + ser.name + "\nComandes disponibles: " + str(
        interp.llistar())
    print "Sortir: surt"

    print "Esperant el missatge de START..."
    print ser.readline()[:-1]
    interp.run()
    ser.close()
예제 #5
0
    def test_compile_multi_input_multi_output(self) -> None:
        code =  """
                multiinput : Bool Int Int Int -> Int ;
                + == == .
                False bool 1 int 1 int 1 int
                """
        stack = Stack()
        cont = Continuation(stack)
        cont = cont.execute(interpret(cont, io.StringIO(code)))

        op, found = Type.op("multiinput", cont ) #, "Test")

        assert found
        assert op.sig == TypeSignature([StackObject(stype=TBool),StackObject(stype=TInt),StackObject(stype=TInt),StackObject(stype=TInt)],
                                [StackObject(stype=TInt)])

        op, found = Type.op("not found", cont)
        assert not found

        
예제 #6
0
def setup(filename):
    read_lines = filename.readlines()
    read_lines_stripped = [line.strip("\n") for line in read_lines]
    read_lines_enum = enumerate(read_lines_stripped)
    for count, item in read_lines_enum:
        interpret(item, count)
예제 #7
0
 def execute(self, code) -> Any:
     self.cont.execute(interpret(self.cont, io.StringIO(code)))
     return self.cont.stack.tos().value