4

This is probably a very strange question, and it definitely is. I'm not too familiar on how programming languages are made with conventional methods, so I'm wondering, is it possible to design a syntaxless programming language? This means that any input will be valid and perform a certain calculation , and the same input will always do the same thing. There will be no syntax error (logic and runtime errors are allowed, the program can crash, do random calculations etc).

I thought of this because genetics are basically, to my understanding, like that.

Edit: I think there are some misunderstandings. Syntaxless simply means that all input will compute, that the interpreter/compiled program will follow that specific set of instructions, however random it maybe.

Also it has to match the fact that every input has 1 and only 1 output. Having something such as the syntax error violates that rule.

Edit 2 Many people are getting Hung up on the syntax part. Forget about the syntax, focus on the fact that ANY input will produce an UNIQUE output.

Pwnna
  • 9,178
  • 21
  • 65
  • 91
  • 4
    Perl, of course! (I kid, I kid.) – icktoofay May 08 '11 at 04:19
  • 1
    Is any (and all) machine code valid? Or will some get spit back with a "does not compute". Keep in mind runtime and logic errors differ from syntax error. – Pwnna May 08 '11 at 04:29
  • 1
    @ultimatebuster: who would give that "does not compute" error? there's no underlying layer below machine code. well, except the CPU microcode, but it will go on doing anything (even weird things) for any input. – Javier May 08 '11 at 05:02
  • I see where you're coming from with the requirement of unique output for each unique input, but it's too restrictive: in a complete language, there are infinitely many ways to compute a given result. I'm not entirely sure how to elucidate the real requirement, though. – Jon Purdy May 08 '11 at 05:06
  • 1
    People are getting "hung up" on the syntax part because *that's what you asked about*! Yes, there are ways to map inputs to outputs s.t. each input has a unique output, and each output corresponds to a particular input. Such mappings are called _[bijective functions](http://tinyurl.com/2akwn6)_ or just _bijections_. That feature, however, is neither necessary nor sufficient to call something a "language." – Caleb May 08 '11 at 05:22
  • @Javier, are you saying that every possible byte/word/long is a valid instruction? What a processor does when it encounters an invalid instruction depends on the particular processor, but usually it causes some sort of interrupt or exception that ends processing of the current set of instructions and jumps back to a supervisory program. The fact that it doesn't usually stop doesn't mean that there's not an error, though stopping is also an option. – Caleb May 08 '11 at 05:52
  • @Caleb: of course there are lots of 'stop conditions' or invalid operations in machine language, but they stop not because of syntax but because of semantics. besides, i don't know of any that stops dead the processor; usually cause some context switch or resets the current execution context. these could be seen as an 'intended effect', or a syntactically valid way of killing a process. – Javier May 08 '11 at 11:59
  • Yeah i have to say, the question wasn't worded the best. – Pwnna May 08 '11 at 13:20
  • @Javier, the question isn't whether the processor stops, it's whether the processor stops working on the input/program in question. Most processors don't accept any possible bit pattern as a valid opcode, so there are some bit patterns that aren't valid. When the processor encounters one of these as an instruction, it'll generate some sort of invalid instruction exception, stopping the current program. This is the equivalent of a syntax error -- the instruction is of the wrong form. – Caleb May 08 '11 at 19:11
  • One can easily devise a state machine that accepts random bits as input and changes states as a result. It's a little tricky (though not impossible) to devise one of any size and complexity that can't get "caught in a loop" with the wrong input sequence, though. – Hot Licks May 17 '11 at 02:30
  • I have a language that accepts any possible file and running it with the same file will result on the same output consistently. Here's the implementation in shell script: `echo 1`. Save that to a file and run the interpreter with `./interpreter [file]`. – André Paramés Oct 08 '11 at 19:29

7 Answers7

8

Kind of.

Syntax refers to the ordering of input, so if you have a language whose meaning does not depend on order, such that a meaningful "sentence" can be constructed regardless of the form of the input, then yes, you can have a syntaxless language. Such a language would have to be somehow case-inflected, or simply define a meaning for every possible separable item (token, character, etc.) of input. You couldn't depend on the order of such items, but you could depend on their number, so that's something.

In all, it'd be pretty esoteric, since operational semantics typically depend on syntax, and it's not immediately obvious to most people that that dependence isn't strictly necessary. Here's a non–Turing-complete syntaxless language:

  • Count the a characters.
  • Count the b characters.
  • Ignore everything else.
  • Produce the quotient of the two counts.

And here's a Turing-complete one:

  • Count the a characters.
  • Count the b characters.
  • Ignore everything else.
  • Take the binary representation of the count of a characters.
  • Prefix that with a number of zeros equal to the count of b characters.
  • Evaluate the result as a Jot program.

Then again, how deep does the rabbit-hole go? What is the fundamental unit of your input? If it's bytes, or characters, then you've got a vast array of possible input tokens to work with. If however you admit that there's a fundamental ordering to the bits within a character, then you have to reduce the problem further, and depend solely on the number of 0 bits and the number of 1 bits, which, granted, is still more than enough information from which to construct a meaningful program. Take my Turing-complete example and substitute a and b with "clear bits" and "set bits" respectively.

Of course, it's also been argued that Lisp is syntaxless in a way, since its syntax is a direct representation of the abstract structure of the program, not to mention the whole program-as-data thing. Really it's not that Lisp and its derivatives are strictly syntaxless so much as they have one-to-one correspondence between syntax and meaning. Just like an integer literal, a Lisp program is effectively just one great big code literal.

Jon Purdy
  • 53,300
  • 8
  • 96
  • 166
  • i think you and I are thinking of the same thing. Syntax as in the order, and every possible input item has a meaning. Different order/amount might do drastically different things, or little different things. – Pwnna May 08 '11 at 04:50
3

If the same input always does "the same thing," then there are rules that govern how the input is to be used. Those rules are the syntax. Without syntax, there's no structure. So, no, not possible.

If you're wondering whether it's possible to create a language that has no syntax errors, then sure... All you have to do is have the compiler (or interpreter, or whatever) emit some fixed output for any input that doesn't have a more useful structure. You could output 1, or 0, or "Thank you for your input." Of course, you might choose something more descriptive, like "syntax error."

I don't think there's an exact parallel between computer code and genetic code. However, if you consider the process of translating DNA to proteins to be like compilation, then you have to remember that only a very small percentage of human DNA actually codes for proteins. Most of our DNA is non-coding, and probably chock full of the genetic version of syntax errors.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 2
    Operational semantics (what a given input means) are separate from syntax (how the input is structured in order to mean what it does). But +1 for "syntax error", as that's a "defined output", and whether it's an error depends entirely on the user interpretation. As a compiler, I could produce "unicorns and daisies" when I get a syntax error, and is the program then still an erroneous one, or just a unicorns-and-daisies-invoking one? – Jon Purdy May 08 '11 at 04:36
  • Syntaxless programming language might be a poor choice of words. Updated to describe it better. – Pwnna May 08 '11 at 04:47
  • @Jon Purdy: You're right -- I changed a few words to stay away from semantics. – Caleb May 08 '11 at 04:50
  • @ultimatebuster, I think you still need to clarify. The additional constraints you added don't really change much, and don't help your question. Rot13 gives you a different output for every input and accepts all strings, but you wouldn't call it a language. At the same time, any non-trivial language should be able to produce the same output for several inputs, like "2+2" and "1+3" and "8/2". – Caleb May 08 '11 at 04:55
  • Yeah it might be beneficial to startover with a new question. I'll do that in the morning as I need to go to bed now. – Pwnna May 08 '11 at 05:03
3

I'm thinking that reverse Polish would meet your definition. At least until you get to the end of the input stream no error would be detected if you entered a random string of values (all of the same type) and binary operators.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
  • (Well, now that I think about it I suppose there could be a syntax error, if too many operators are entered, consuming all the values in the stack.) – Hot Licks May 08 '11 at 04:42
  • 1
    Interesting interpretation. You can get around the empty-stack issue by by having a lazy stack that produces, say, zero if popped while empty. – Jon Purdy May 08 '11 at 05:09
3

You can make a program language in which you define a input character set (for example, [a-z0-9]) and every string of characters in that set is a valid program. For example, take this language (where ? represents any character).

a? : add one to register ? if ? is a numeral, nop otherwise
b? : subtract one to register ? is a numeral, nop otherwise
p? : print register ?

Any other two character sequence is a nop. If you have an extra character at the end of the string, it's a nop.

This meets your requirements. It would not be hard to make it Turing-complete (j? means jump to address held in register ?, s? means store contents of register 0 in address ?).

However, I don't know how different this is between having a C compiler just generate executable code that does a nop in the case of a syntax error.

tkerwin
  • 9,559
  • 1
  • 31
  • 47
2

A language completely depends on how do you interpret them. There has to be a syntax it might be very complicated but it has to be. Like the question you have done was in English, and that had a proper grammatical syntax, and that is why i understood it. If we can make such a programming language which would detect natural languages and derive their commands based on them like "hey why don't you make me a calculator" and the computer makes for you a calculator. Without syntax means with syntax which is less strict. For example if you speak in German i would not understand a word, that means i could not detect the syntax with which i should have interpreted and reacted, instead i have some other reaction "what the heck this guy is speaking" or "is this guy speaking German?" so the interpretation becomes different. Syntax less probably means a syntax which the system generates dynamically by learning from the environment and circumstances. There needs to be actually a protocol between two to convey how it should be interpreted, and that is the syntax.

phoxis
  • 60,131
  • 14
  • 81
  • 117
1

Even genetic code will error out when introduced with code it can't compute (mutation, missing limbs, etc).

Mikecito
  • 2,053
  • 11
  • 17
  • 2
    mutations still is an output. It's simply a logic/runtime error in terms of computers. – Pwnna May 08 '11 at 04:27
  • If the genetic code is damaged badly enough, the DNA molecule won't be able to clone itself, or won't yield a cell that lives long enough to divide again, so the result will be dead organic soup. You might *think* that every combination of DNA yields some output, but that's only because the non-working combinations weed themselves out before you ever see the results. Biology weeds out the failed DNA just as effectively as compilers weed out syntax errors (though biology's diagnostic messages are less helpful). – Joe White May 08 '11 at 07:18
  • Sure. A program in this case will, instead of saying syntax error, simply encounter many logic and runtime errors, and fail, but there's an attempt to run (without a syntax error) anyway. – Pwnna May 08 '11 at 13:18
-1

No. At some point, the processor has to know what to do with that random crap you put on the hard drive, however arbitrary that may be. Even if it varies from system to system, that's still syntax.

Maxpm
  • 24,113
  • 33
  • 111
  • 170
  • 1
    You're confusing syntax with semantics. Semantics is what the code means, what actions the machine executes. Syntax is the formal structure of the code. Although, you could argue that simply having a string of bits is some sort of minimal syntax, rather than the absence of syntax. – tkerwin May 08 '11 at 05:09