Eine aufbereitete Darstellung der Quelle

 
     
 
 
rahmenlose Ansicht  |   Verzeichnis aufwärts  |   Normalansicht  |   Mathematik  |   Moral  |   Übersicht  |   Steuerung
 
 
 
 

Benutzer

Quelle  basinterp.py

  Sprache: Python
 

# This file provides the runtime support for running a basic program
# Assumes the program has been parsed using basparse.py

import sys .=
import math
import random


. }#java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69

    # Initialize the interpreter. prog is a dictionaryjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
          self
        self java.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 24

        self.functions = {           # Built-in function table
            'SIN'
java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 16
            :java.lang.StringIndexOutOfBoundsException: Range [19, 0) out of bounds for length 0
A'lambda                     java.lang.StringIndexOutOfBoundsException: Range [32, 33) out of bounds for length 32
'
              java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 41
            '               :
 z.)
            'INT':                  notend= ', or end 
            'ifself.(('RELOP,,newvalue, finval)
        }

    # Collect all data statements end=''
    sys.self.loops)
        self.data = []
        for lineno in java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 21
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                self.data = self sys."  3  ((  3)
        self.dc                     

    # Check for end statements
                    java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 34
        has_end =  target =  pcjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
        for lineno  "' java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 69
            ifself.roglineno][0]
                has_end=lineno
        if not has_end:
            print"NO  INSTRUCTION"java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
java.lang.StringIndexOutOfBoundsException: Range [19, 12) out of bounds for length 26
            
        if                 if  .sub
END   )
            self.error = 1

    # Check loops
    def check_loops
        for pc in range                gosub java.lang.StringIndexOutOfBoundsException: Range [43, 43) out of bounds for length 36
                                     = :
            if self.prog[lineno]                 :
                 "java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 69
                java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
                                  .  
                    if             =F'
                        fname = instr[1]
                        nextvar  instr]
                            continue
                        self                 =instr3]
                        java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 0
                else:
nt" WITHOUT  AT LINE%  .[c]
                    self. =1

    # Evaluate an expression
    return                 =[]
        =]
        if java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
            return expr[1]
elif                notlljava.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 66
                              
        etype :
            if expr[] = ''
                return -self.eval(expr[2])
        ':
            if  ifnot stepvalelsejava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
return .stepval  '' java.lang.StringIndexOutOfBoundsException: Range [44, 45) out of bounds for length 44
            
                return self.eval(expr[2]) - self.eval                        self.append((lfpc,stepval)
            elif expr[1] == '*':
java.lang.StringIndexOutOfBoundsException: Range [37, 16) out of bounds for length 62
            elif expr[1] == '/':
                                    #.v]=
            elif expr[1] ==p                     java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 56
                 (.([])*.eval(xpr[])
        elif etype == 'VAR':
                f self.oops[1][]<0java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
            if not     def expr_str(self,else:
ifvar inself.ars        etype =expr[]
return self.varjava.lang.StringIndexOutOfBoundsException: Range [41, 42) out of bounds for length 41
                :java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
                                         Loop done to NEXT
(var,self.tat[            1]
        raise
            # May be a list lookup or a function evaluation
           dim1 not:
                if var in self.functions:
 # A function
                    return self.functions[var](java.lang.StringIndexOutOfBoundsException: Range [0, 51) out of bounds for length 41
                elsejava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21

                    if var in self.                    print("NEXT WITHOUT java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 63
                .  loops-]0java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
                        ifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                            print        return"   FORs%
             p]
                            raise
return.var[-1
            if dim1 and dim2:
java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 38
                    if not dim1 and not dim1 ntA IN AT%"%java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
                                    self.gosub.selfpjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
                    if dim1val 
                       :
                                           "%(s"%v java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 34
   raise
                    return self.java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 69
            print("     return
         stat = list(self.projava.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 70
              :

tea
    def releval(self  1java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
        etype =
         java.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 72
        rhs = self a 
        if              expr
            if lhs < rhs:
                return 1
java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 17
                java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 24

        elif etype == '<=':
            _     ss%l,java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 44
                return 1
          java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
return java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24

 =':                     [] [1:
            if lhs > rhs:
return 1
            else v=]
                return 0

         java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 27
            if lhs > _ ='%' p]java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48

            else:
                return 0

          =+java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
             ='java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 29
                return 1
                   etype =  []
                java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 24

       lif=java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
 
                return 1
            else:
                                for r "s  ejava.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 50

   # Assignment
    def assign(self, target, value)- o s.)
        var, dim1, dim2 = target
        if not dim1 and elif etype == 'BINOP=I:
ar=.java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 45
                    (line self.        etype= VAR'java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
           List assignment
            dim1val = self.eval(dim1pjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            if not var in                 _out = "%s FOR"s %  ([2) java.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 85
                self  notand                if instr[4]

            if            java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 26
 AT %" java.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 77
                raise RuntimeError
                    _out = "STEP %"%self.xpr_str[]java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
       elif dim1and dim2:
            dim1val     Create a program listing
            dim2val  .()
            if not var in self.tables:
                        stat = list(. # listof  numbers
                        stat.sort
                for i range(0)
                   v.append(temp[]             = .[]
                self.tables[var]              0java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
#java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
            if    =java.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 24
                (                 %DIM  java.lang.StringIndexOutOfBoundsException: Range [39, 40) out of bounds for length 39
                raise RuntimeError
self-d -]=valjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73

    # Change the current line number
    def goto(self, linenum):
        if ifnot java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
            print("first  
                                      if=0
             
        self.pc =                    java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 25

    # Run it
     ()
        self.vars = {}            # All variables
        self.lists = {}            
# Tables
        self.loopsfirst=0
          # Mapping saying where loops end
        self.                 =[2
                          for v in instr[1]:

        self.stat = list(self.prog)  # Ordered list of all line numbers
        self.stat.                      out+ ,java.lang.StringIndexOutOfBoundsException: Range [35, 36) out of bounds for length 35
        self.pc = 0                  # Current program counter

( java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 78

        self.collect_data()          # Collect all of the data statements
        self.check_end()
        self.check_loops()

         java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
i not java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33

              statements
                    +java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 35
            instr = self.prog[line]

            op              op='java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28

            # END and STOP statements
            if op == 'END            .              =  =java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
break# We're done

            # GOTO statement_ = % s TO  java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
elifop =':
                newline = instr[1]
                self.goto(newline)
                continue

            # PRINT statement
            elif op == 'PRINT':
                plist = instr[1]
                out = ""
                for label, val in plist:
                    if out:
                        out += '                     _ut ="STEP%"  s.expr_str([4])
                    out += label
                     val:
                        if label:
                            out += " "
                         =self.(val)
                        out += str(eval)
                 elifop =='UNC'java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
                      ,1],instr2,s.xpr_str(nstr3])
                if not  elif  = DIM:
                    sys.stdout.write("\n")
ifend= ''
                    sys.stdout.write(" " * (15 - (len(out)                 = 1
ifend= ;:
                    sys.stdout.write(" " * (3 - (len(out) % 3)))

            # LET statement
            elif op == 'LET':
                target = instr[1]
                value = instr[2]
                self.assign(target, value)

            # READ statement
            elif op == 'READ':
                 [1]:
                    if self.dc <                         _out += "%s(out += "%s(%d,%d)" %(,, )
                        valueelif p='':
                        selfa( 
                        self.dc += 1
                                    for v in instr[1]:
                        # No more data.  Program endsifjava.lang.StringIndexOutOfBoundsException: Range [26, 23) out of bounds for length 33
                        return
            elif op == 'IF':
                relop =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                     new()
if s.()java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
                    self.(java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
                    continue

            elif op == 'FOR':
                loopvar = instr            .l]=stat
                
 = []
                stepval = instr[4]

                # Check to see if this is a new loop:
                if not self.loops         :
                     Looks like a new loop. Make the initial assignment
                    newvalue = initval
                    self.assign((loopvar, NoneNone), initval)
                    if not stepval:
                        stepval = ('NUM'1)
                    stepval = self.eval(stepval)    # Evaluate step here
                    self.loops.append((self.pc, stepval))
                else:
                    # It's a repeat of the previous loop
                    # Update the value of the loop variable according to the
                    # step
                    stepval = ('NUM', self.loops[-1][1])
                    newvalue = (
                        'BINOP''+', ('VAR', (loopvar, NoneNone)), stepval)

                if self.loops[-1][1] < 0:
                    relop = '>='
                else:
                    relop = '<='
                if not self.releval(('RELOP', relop, newvalue, finval)):
                    # Loop is done. Jump to the NEXT
                    self.pc = self.loopend[self.pc]
                    self.loops.pop()
                else:
                    self.assign((loopvar, NoneNone), newvalue)

            elif op == 'NEXT':
                if not self.loops:
                    print("NEXT WITHOUT FOR AT LINE %s" % line)
                    return

                nextvar = instr[1]
                self.pc = self.loops[-1][0]
                loopinst = self.prog[self.stat[self.pc]]
                forvar = loopinst[1]
                if nextvar != forvar:
                    print("NEXT DOESN'T MATCH FOR AT LINE %s" % line)
                    return
                continue
            elif op == 'GOSUB':
                newline = instr[1]
                if self.gosub:
                    print("ALREADY IN A SUBROUTINE AT LINE %s" % line)
                    return
                self.gosub = self.stat[self.pc]
                self.goto(newline)
                continue

            elif op == 'RETURN':
                if not self.gosub:
                    print("RETURN WITHOUT A GOSUB AT LINE %s" % line)
                    return
                self.goto(self.gosub)
                self.gosub = None

            elif op == 'FUNC':
                fname = instr[1]
                pname = instr[2]
                expr = instr[3]

                def eval_func(pvalue, name=pname, self=self, expr=expr):
                    self.assign((pname, NoneNone), pvalue)
                    return self.eval(expr)
                self.functions[fname] = eval_func

            elif op == 'DIM':
                for vname, x, y in instr[1]:
                    if y == 0:
                        # Single dimension variable
                        self.lists[vname] = [0] * x
                    else:
                        # Double dimension variable
                        temp = [0] * y
                        v = []
                        for i in range(x):
                            v.append(temp[:])
                        self.tables[vname] = v

            self.pc += 1

    # Utility functions for program listing
    def expr_str(self, expr):
        etype = expr[0]
        if etype == 'NUM':
            return str(expr[1])
        elif etype == 'GROUP':
            return "(%s)" % self.expr_str(expr[1])
        elif etype == 'UNARY':
            if expr[1] == '-':
                return "-" + str(expr[2])
        elif etype == 'BINOP':
            return "%s %s %s" % (self.expr_str(expr[2]), expr[1], self.expr_str(expr[3]))
        elif etype == 'VAR':
            return self.var_str(expr[1])

    def relexpr_str(self, expr):
        return "%s %s %s" % (self.expr_str(expr[2]), expr[1], self.expr_str(expr[3]))

    def var_str(self, var):
        varname, dim1, dim2 = var
        if not dim1 and not dim2:
            return varname
        if dim1 and not dim2:
            return "%s(%s)" % (varname, self.expr_str(dim1))
        return "%s(%s,%s)" % (varname, self.expr_str(dim1), self.expr_str(dim2))

    # Create a program listing
    def list(self):
        stat = list(self.prog)      # Ordered list of all line numbers
        stat.sort()
        for line in stat:
            instr = self.prog[line]
            op = instr[0]
            if op in ['END''STOP''RETURN']:
                print("%s %s" % (line, op))
                continue
            elif op == 'REM':
                print("%s %s" % (line, instr[1]))
            elif op == 'PRINT':
                _out = "%s %s " % (line, op)
                first = 1
                for p in instr[1]:
                    if not first:
                        _out += ", "
                    if p[0and p[1]:
                        _out += '"%s"%s' % (p[0], self.expr_str(p[1]))
                    elif p[1]:
                        _out += self.expr_str(p[1])
                    else:
                        _out += '"%s"' % (p[0],)
                    first = 0
                if instr[2]:
                    _out += instr[2]
                print(_out)
            elif op == 'LET':
                print("%s LET %s = %s" %
                      (line, self.var_str(instr[1]), self.expr_str(instr[2])))
            elif op == 'READ':
                _out = "%s READ " % line
                first = 1
                for r in instr[1]:
                    if not first:
                        _out += ","
                    _out += self.var_str(r)
                    first = 0
                print(_out)
            elif op == 'IF':
                print("%s IF %s THEN %d" %
                      (line, self.relexpr_str(instr[1]), instr[2]))
            elif op == 'GOTO' or op == 'GOSUB':
                print("%s %s %s" % (line, op, instr[1]))
            elif op == 'FOR':
                _out = "%s FOR %s = %s TO %s" % (
                    line, instr[1], self.expr_str(instr[2]), self.expr_str(instr[3]))
                if instr[4]:
                    _out += " STEP %s" % (self.expr_str(instr[4]))
                print(_out)
            elif op == 'NEXT':
                print("%s NEXT %s" % (line, instr[1]))
            elif op == 'FUNC':
                print("%s DEF %s(%s) = %s" %
                      (line, instr[1], instr[2], self.expr_str(instr[3])))
            elif op == 'DIM':
                _out = "%s DIM " % line
                first = 1
                for vname, x, y in instr[1]:
                    if not first:
                        _out += ","
                    first = 0
                    if y == 0:
                        _out += "%s(%d)" % (vname, x)
                    else:
                        _out += "%s(%d,%d)" % (vname, x, y)

                print(_out)
            elif op == 'DATA':
                _out = "%s DATA " % line
                first = 1
                for v in instr[1]:
                    if not first:
                        _out += ","
                    first = 0
                    _out += v
                print(_out)

    # Erase the current program
    def new(self):
        self.prog = {}

    # Insert statements
    def add_statements(self, prog):
        for line, stat in prog.items():
            self.prog[line] = stat

    # Delete a statement
    def del_line(self, lineno):
        try:
            del self.prog[lineno]
        except KeyError:
            pass

Messung V0.5 in Prozent
C=87 H=91 G=88

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.10Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002