编程语言语法中尾随逗号的历史 [英] History of trailing comma in programming language grammars

查看:118
本文介绍了编程语言语法中尾随逗号的历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多编程语言都允许在语法中在列表的最后一项之后加上逗号.据说这样做是为了简化自动代码生成,这是可以理解的.

Many programming languages allow trailing commas in their grammar following the last item in a list. Supposedly this was done to simplify automatic code generation, which is understandable.

作为示例,以下是Java中完全合法的数组初始化( JLS 10.6数组初始化程序):

As an example, the following is a perfectly legal array initialization in Java (JLS 10.6 Array Initializers):

int[] a = { 1, 2, 3, };

我很好奇,如果有人知道哪种语言最先允许使用诸如此类的结尾逗号.显然C早在1985年就拥有 .

I'm curious if anyone knows which language was first to allow trailing commas such as these. Apparently C had it as far back as 1985.

此外,如果有人知道现代编程语言的其他语法特殊性",那么我也将非常有兴趣听说这些语法.我读到Perl和Python例如在语法的其他部分允许尾随逗号时更为自由.

Also, if anybody knows other grammar "peculiarities" of modern programming languages, I'd be very interested in hearing about those also. I read that Perl and Python for example are even more liberal in allowing trailing commas in other parts of their grammar.

推荐答案

我不是逗号专家,但是我知道标准Pascal对于分号被用作 separators 语句非常坚持. ,而不是终止符.这意味着如果您不想被编译器大喊大叫,则必须非常小心地放置一个.

I'm not an expert on the commas, but I know that standard Pascal was very persnickity about semi-colons being statement separators, not terminators. That meant you had to be very very careful about where you put one if you didn't want to get yelled at by the compiler.

后来的Pascal风格的语言(C,Modula-2,Ada等)的标准被编写为接受奇数多余的分号,而不会像您刚刚在蛋糕混合物中撒粉一样.

Later Pascal-esque languages (C, Modula-2, Ada, etc.) had their standards written to accept the odd extra semicolon without behaving like you'd just peed in the cake mix.

这篇关于编程语言语法中尾随逗号的历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆