1

I'm building a compiler for a custom language. Is it possible for the compiler to detect any infinite looping condition without running the program?

If so how can I implement it?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Ashrith Sheshan
  • 654
  • 4
  • 17
  • See : http://en.wikipedia.org/wiki/Halting_problem Not easy problem. – Martin V. Jun 27 '13 at 03:04
  • Some compilers might detect some looping conditions, but if your loop is based on the value of a variable which is modified during the loop the compiler can't guess what values will be inserted at run time. –  Jun 27 '13 at 03:04
  • Check out total functional programming. – CMCDragonkai Apr 09 '15 at 15:50

1 Answers1

6

You may be able to detect some infinite loops, but in general you can't detect all possible infinite loops (unless your custom language is specifically designed to eliminate general looping constructs). See http://en.wikipedia.org/wiki/Halting_problem.

Kristopher Johnson
  • 81,409
  • 55
  • 245
  • 302