Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

clarification about the error
Source Link
Sundar R
  • 14.8k
  • 7
  • 57
  • 81
subroutine bfexec(bfprogram)
begin
 Looping through the bfprogram,
 If(current character is '[')
 Find the corresponding ']'
 Store the code between the two brackets in, say, 'subprog'
 Save the value of the current cell in oldval
 Call bfexec recursively with subprog
 Save the value of the current cell in newval
 If(newval >= oldval)
 Raise an 'infinite loop' error and exit
 EndIf
 /* Do other character's processings */
 EndIf
 EndLoop
end
subroutine bfexec(bfprogram)
begin
 Looping through the bfprogram,
 If(current character is '[')
 Find the corresponding ']'
 Store the code between the two brackets in, say, 'subprog'
 Save the value of the current cell in oldval
 Call bfexec recursively with subprog
 Save the value of the current cell in newval
 If(newval >= oldval)
 Raise an error and exit
 EndIf
 /* Do other character's processings */
 EndIf
 EndLoop
end
subroutine bfexec(bfprogram)
begin
 Looping through the bfprogram,
 If(current character is '[')
 Find the corresponding ']'
 Store the code between the two brackets in, say, 'subprog'
 Save the value of the current cell in oldval
 Call bfexec recursively with subprog
 Save the value of the current cell in newval
 If(newval >= oldval)
 Raise an 'infinite loop' error and exit
 EndIf
 /* Do other character's processings */
 EndIf
 EndLoop
end
added pseudo code of 'infinite loop detector'!
Source Link
Sundar R
  • 14.8k
  • 7
  • 57
  • 81

SECOND EDIT: I have written what I purport to be infinite loop detector. It probably misses some edge cases (or less probably, somehow escapes Mr. Turing's clutches), but seems to work for me as of now. In pseudocode form, here it goes:

subroutine bfexec(bfprogram)
begin
 Looping through the bfprogram,
 If(current character is '[')
 Find the corresponding ']'
 Store the code between the two brackets in, say, 'subprog'
 Save the value of the current cell in oldval
 Call bfexec recursively with subprog
 Save the value of the current cell in newval
 If(newval >= oldval)
 Raise an error and exit
 EndIf
 /* Do other character's processings */
 EndIf
 EndLoop
end

SECOND EDIT: I have written what I purport to be infinite loop detector. It probably misses some edge cases (or less probably, somehow escapes Mr. Turing's clutches), but seems to work for me as of now. In pseudocode form, here it goes:

subroutine bfexec(bfprogram)
begin
 Looping through the bfprogram,
 If(current character is '[')
 Find the corresponding ']'
 Store the code between the two brackets in, say, 'subprog'
 Save the value of the current cell in oldval
 Call bfexec recursively with subprog
 Save the value of the current cell in newval
 If(newval >= oldval)
 Raise an error and exit
 EndIf
 /* Do other character's processings */
 EndIf
 EndLoop
end
edited tags
Link
Constantin
  • 28.3k
  • 10
  • 64
  • 79
undecidable ≠ NP-complete
Link
ShreevatsaR
  • 39.4k
  • 17
  • 108
  • 128
Loading
Edited tags.
Link
Eugene Yokota
  • 95.9k
  • 45
  • 219
  • 323
Loading
edited tags
Link
Mihai Limbășan
  • 68.7k
  • 4
  • 52
  • 60
Loading
Halting problem clarification
Source Link
Sundar R
  • 14.8k
  • 7
  • 57
  • 81
Loading
linked to BF, becuase someone's marked it "offensive" :P
Source Link
ShreevatsaR
  • 39.4k
  • 17
  • 108
  • 128
Loading
Source Link
Sundar R
  • 14.8k
  • 7
  • 57
  • 81
Loading

AltStyle によって変換されたページ (->オリジナル) /