开发者

Syntaxless programming language [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_Python百科 Closed 11 years ago.

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.


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.


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.


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.


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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜