progs/bf/bfi.sc
changeset 743 6acabeecdf75
parent 742 b5b5583a3a08
child 825 dca072e2bb7d
equal deleted inserted replaced
742:b5b5583a3a08 743:6acabeecdf75
    45       case '>' => (pc + 1, mp + 1, mem)
    45       case '>' => (pc + 1, mp + 1, mem)
    46       case '<' => (pc + 1, mp - 1, mem)
    46       case '<' => (pc + 1, mp - 1, mem)
    47       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
    47       case '+' => (pc + 1, mp, write(mem, mp, sread(mem, mp) + 1))
    48       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
    48       case '-' => (pc + 1, mp, write(mem, mp, sread(mem, mp) - 1))
    49       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
    49       case '.' => { print(sread(mem, mp).toChar); (pc + 1, mp, mem) }
    50       case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))
    50       case ',' => (pc + 1, mp, write(mem, mp, Console.in.read().toByte))   //scala.io.StdIn.readLine()
    51       case '['  => if (sread(mem, mp) == 0) 
    51       case '['  => if (sread(mem, mp) == 0) 
    52                       (jumpRight(prog, pc + 1, 0), mp, mem) 
    52                       (jumpRight(prog, pc + 1, 0), mp, mem) 
    53                    else (pc + 1, mp, mem) 
    53                    else (pc + 1, mp, mem) 
    54       case ']'  => if (sread(mem, mp) != 0) 
    54       case ']'  => if (sread(mem, mp) != 0) 
    55                       (jumpLeft(prog, pc - 1, 0), mp, mem) 
    55                       (jumpLeft(prog, pc - 1, 0), mp, mem)