所有编程语言都有通用的词汇吗?

发布于 2024-09-11 18:44:36 字数 244 浏览 2 评论 0原文

每种编程语言都有自己的词汇表,这确实很烦人。例如,在 Java 中,我们

if ... {}

在 Bash 脚本中拥有

if ... then ... fi # using "fi" is so insane for me

如果所有编程语言共享相同的词汇表,那就太好了。然后,语言设计者可以定义底层语义。我想知道是否有尝试建立这样的词汇?

It is really annoying that each programming language has its own vocabulary. For example, in Java we have

if ... {}

yet in Bash script we have

if ... then ... fi # using "fi" is so insane for me

It would be really nice if all programming languages shared the same vocabulary. The language designers could then define the underlying semantics. I wonder if there were any attempts to build such a vocabulary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

一片旧的回忆 2024-09-18 18:44:37

不,出于同样的原因,所有人类语言都不共享相同的词汇:词汇和语义服务于特定的利基需求。希伯来语有超过 20 个单词来描述收获(每种水果、谷物和蔬菜都有一个独特的单词!);阿拉伯语中有几十个表示骆驼的词,等等。

计算机语言非常相似。 bash 强调一些特性(例如短命令、立即执行操作系统命令),而Java 则强调其他特性(例如清晰的对象层次结构)。这些强调是通过不同的语义和词汇来具体化的。

有人可能会说,可以有一个自动翻译器,可以将程序从一种语言翻译成另一种语言。尽管理论上这是可能的(对于所有图灵完备语言),但由于它可能非常乏味一种语言中的命令含义与另一种语言中的命令含义之间的细微差别。例如,if 关键字的含义在上述语言之间可能略有不同,特别是在出现错误和意外输入的情况下。

编辑:
评论如下:我又举了一个例子,因为看起来因纽特语言并没有几百个单词来描述雪,只有很多形容词。

No, for the very same reason all human languages don't share the same vocabulary: Vocabulary and semantics serve specific niche needs. Hebrew has more than 20 words to describe harvesting (A unique word for each fruit, cereal and vegetable!); Arabic has a few dozens for camels, and so on.

Computer languages are much alike. bash emphasizes some features (e.g. short commands, immediate execution of os commands) while Java emphasizes other features (e.g. clear object hierarchy). These emphasizes are materialized using different semantics and vocabulary.

One could argue that there can be an automatic translator that would take a program from one language and translate it to another. Although it is theoretically possible (for all turing-complete languages), it might be extremely tedious due to subtle differences between the meaning of a command in one language and its meaning in another. For example, the meaning of the if keyword might vary slightly between the aforementioned languages, especially in case of errors and unexpected input.

EDIT:
Following the comment: I have chosen another example, as it seems that Inuit languages does not exactly have hundreds of words to describe snow, just lots of adjectives.

孤君无依 2024-09-18 18:44:37

嗯,IBM 有一个产品,Visual Age Generator,它有一种通用语言,然后被“编译”为从 UNIX 下的 C 到大型机上的 COBOL 的所有语言。我认为它现在已经停止服务了,可能还有其他尝试,但不会立即浮现在我的脑海中。

然而,具有不同语义的关键是因为语言不同,否则就没有理由选择 Java 而不是 COBOL,或者选择 Ruby 而不是 BCPL。

fi 是一个绝妙的想法。每个结构都有不同的结束词极大地简化了解析器并允许更好的错误检查。换句话说,ifficaseesac。我唯一不喜欢的是 do 使用 done 而不是 od :-)

Well, IBM had a product, Visual Age Generator, which had a common language which was then 'compiled' to everything from C under UNIX to COBOL on the mainframe. I think it's well out of service now and there may have been other attempts that don't spring to mind immediately.

However, the whole point of having different semantics is because languages are different, otherwise there would be no reason to choose Java over COBOL or Ruby over BCPL.

And fi was a brilliant idea. To have a different ending word for each construct greatly eased the parser and allowed greater error checking. In other words, if had fi, case had esac. The only thing I don't like is that do uses done rather than od :-)

被翻牌 2024-09-18 18:44:37

只是很高兴他们都(或大多数)使用拉丁字母,这与人类语言不同。 ;)

Just be glad they all (or large majority) use latin alphabet, unlike human languages. ;)

岁月静好 2024-09-18 18:44:37

即使在像 if 语句这样的简单情况下,它也是不可行的。
例如,某些语言可以使用“statement if condition”子句,这在 bash 中可能不可行。
然后考虑范式特定的语义(类、函数、谓词……),它比词汇更深入。

Even in simple cases like the if statement it would not be viable.
Some languages can use "statement if condition" clauses, for example, that may be not viable in bash.
Consider then pradigm specific sematics (classes, functions, predicates....) it goes deeper than vocabulary.

初与友歌 2024-09-18 18:44:37

有许多语言采用了“C”的约定(C++、C#、Java、Javascript、Verilog 等)。我不知道有任何正式趋同的努力。

如果你看看语言设计/标准化过程陷入困境的那种微小的东西,我认为全行业范围内同质化事物的努力不会有多大效果。

看起来,由一群有思想的聪明人组合而成的现代语言确实试图尽可能多地借鉴他们的遗产。不过,并非所有语言都是这样创建的......

There are many languages which have adopted conventions from 'C' (C++, C#, Java, Javascript, Verilog, etc). I am not aware of any effort at any formal convergence.

If you look at the kind of minute stuff language design/standardisation processes get bogged down in, I don't think that industry-wide efforts to homogenise things would ever come to much.

It does seem that modern languages put together by groups of thoughtful intelligent people try to borrow as much from their heritage as possible. Not all languages are created like this, though...

你是暖光i 2024-09-18 18:44:37

不,但您可以用任何语言创建“Hello World”应用程序。

No, but you can create a 'Hello World' app in any language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文