5 ms·
A valid program in a given programming language has a precise definition.
by Rerarom 8y ago
A valid program in a given programming language has a precise definition.
- vidarh 8y agoYes, but a given string of text does not specify a language. "Is this a valid program?" is syntactically and semantically valid Ruby for example. But in itself it will just throw an error [some might argue this means it is not a valid program, but these errors are part of the normal runtime control flow of Ruby]. Depending on environment, however, it can do something else. E.g. if your environment contains this: def program?; 42; end def valid(arg); arg; end def a(arg); arg; end def this(arg); arg; end def Is(arg); arg; end Then the string Is this a valid program? Will execute and return 42. A lot of random text will be valid programs in any number of existing languages without any intent for them to be so. But any random text can be valid programs in an infinite number of possible languages that does not yet exist. So the question of what is a valid program is very much a philosophical one about whether or not the intent of the author matters in the face of processors that can re-interpret the data in ways it was not intended.