C编程语言的运算符优先级表 [英] Operator precedence table for the C programming language

查看:69
本文介绍了C编程语言的运算符优先级表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以C语言列出所有运算符的正确运算符优先级表会是什么样?

What would a correct operator precedence table that lists all operators in the C language look like?

我在网络上进行了广泛的搜索,发现了许多这样的优先级表. las,我还没有一个满足这些要求的人:

I have made extensive searches on the web, and found many such precedence tables. Alas, I haven't found a single one filling these requirements:

  • 使用ISO 9899:2011中定义的C语言列出 all 运算符,而不混用任何C ++运算符.
  • 完整和正确优先级顺序列出运算符.
  • Lists all operators in the C language as defined in ISO 9899:2011, without mixing in any C++ operators.
  • Lists the operators in the complete and correct priority order.

推荐答案

说明

Prec.表示运算符优先级,其中组1的优先级最高,而组17的优先级最低.

Prec. denotes operator precedence, where group 1 has the highest precedence and group 17 the lowest.

Assoc.表示 操作员关联性 ,如果适用的话.关联性可以是从左到右或从右到左.

Assoc. denotes operator associativity, where such is applicable. Associativity can be either left-to-right or right-to-left.

来源

我的目标是在Stack Overflow现场提供一个运算符优先级表,这是正确且规范的.此运算符优先级表直接对应于ISO 9899:2011的6.5章,我们可以在其中阅读(6.5/3):

My ambition with this post is to provide a operator precedence table on-site at Stack Overflow, which is correct and canonical. This operator precedence table corresponds directly to chapter 6.5 of ISO 9899:2011, where we can read (6.5/3):

运算符和操作数的分组由语法指示. 85)

The grouping of operators and operands is indicated by the syntax. 85)

然后,在内容丰富(非规范性)的脚注中作为注释:

And then as a comment, in the informative (not normative) foot note:

85)语法指定了运算符在表达式求值中的优先级,该优先级与此子节的主要子节的顺序相同,从最高优先级开始. /-/

85) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same as the order of the major subclauses of this subclause, highest precedence first. /--/

在每个主要小节中,运算符具有相同的优先级.在每个小节中,左或右关联性由其中讨论的表达式的语法指示.

Within each major subclause, the operators have the same precedence. Left- or right-associativity is indicated in each subclause by the syntax for the expressions discussed therein.

表中的所有正式运算符名称均取自第6.5章,该名称可在规范文本中找到.非正式名称包含在程序员社区可能比标准提供的名称更熟悉的情况下.

All formal operator names from the table are taken from chapter 6.5, where such a name could be found in normative text. Informal names were included in the cases where the programmer community might be more familiar with another name than the one given in the standard.

这篇关于C编程语言的运算符优先级表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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