C++ 运算符优先级列表

The operators at the top of this list are evaluated first. Operators within a group have the same precedence. All operators have left-to-right associativity unless otherwise noted.

 

PrecedenceOperatorDescriptionExampleOverloadableAssociativity
1::Scope resolution operatorClass::age = 2;noleft to right
2()Function callprintf(“Hello world/n”);yesleft to right
()Member initalizationc_tor(int x, int y) : _x(x), _y(y * 10) {}yes
[]Array accessarray[4] = 2;yes
->Member access from a pointerptr->age = 34;yes
.Member access from an objectobj.age = 34;no
++Post-incrementfor (int i = 0; i < 10; i++) cout << i;yes
--Post-decrementfor (int i = 10; i > 0; i--) cout << i;yes
dynamic_castRuntime-checked type conversionY& y = dynamic_cast<Y&>(x);no
static_castUnchecked type conversionY& y = static_cast<Y&>(x);no
reinterpret_castReinterpreting type conversionint const* p = reinterpret_cast<int const*>(0x1234);no
const_castCast away/Add constnessint* q = const_cast<int*>(p);no
typeidGet type informationstd::type_info const& t = typeid(x);no
3!Logical negationif (!done) ...yesright to left
notAlternate spelling for !
~Bitwise complementflags = ~flags;yes
complAlternate spelling for ~
++Pre-incrementfor (i = 0; i < 10; ++i) cout << i;yes
--Pre-decrementfor (i = 10; i > 0; --i) cout << i;yes
-Unary minusint i = -1;yes
+Unary plusint i = +1;yes
*Dereferenceint data = *intPtr;yes
&Address ofint *intPtr = &data;yes
sizeofSize (of the type) of the operand in bytessize_t s = sizeof(int);no
newDynamic memory allocationlong* pVar = new long;yes
new []Dynamic memory allocation of arraylong* array = new long[20];yes
deleteDeallocating the memorydelete pVar;yes
delete []Deallocating the memory of arraydelete [] array;yes
(type)Cast to a given typeint i = (int)floatNum;yes
4->*Member pointer selectorptr->*var = 24;yesleft to right
.*Member object selectorobj.*var = 24;no
5*Multiplicationint i = 2 * 4;yesleft to right
/Divisionfloat f = 10.0 / 3.0;yes
%Modulusint rem = 4 % 3;yes
6+Additionint i = 2 + 3;yesleft to right
-Subtractionint i = 5 - 1;yes
7<<Bitwise shift leftint flags = 33 << 1;yesleft to right
>>Bitwise shift rightint flags = 33 >> 1;yes
8<Comparison less-thanif (i < 42) ...yesleft to right
<=Comparison less-than-or-equal-toif (i <= 42) ...yes
>Comparison greater-thanif (i > 42) ...yes
>=Comparison greater-than-or-equal-toif (i >= 42) ...yes
9==Comparison equal-toif (i == 42) ...yesleft to right
eqAlternate spelling for ==
!=Comparison not-equal-toif (i != 42) ...yes
not_eqAlternate spelling for !=
10&Bitwise ANDflags = flags & 42;yesleft to right
bitandAlternate spelling for &
11^Bitwise exclusive OR (XOR)flags = flags ^ 42;yesleft to right
xorAlternate spelling for ^
12|Bitwise inclusive (normal) ORflags = flags | 42;yesleft to right
bitorAlternate spelling for |
13&&Logical ANDif (conditionA && conditionB) ...yesleft to right
andAlternate spelling for &&
14||Logical ORif (conditionA || conditionB) ...yesleft to right
orAlternate spelling for ||
15? :Ternary conditional (if-then-else)int i = a > b ? a : b;noright to left
16=Assignment operatorint a = b;yesright to left
+=Increment and assigna += 3;yes
-=Decrement and assignb -= 4;yes
*=Multiply and assigna *= 5;yes
/=Divide and assigna /= 2;yes
%=Modulo and assigna %= 3;yes
&=Bitwise AND and assignflags &= new_flags;yes
and_eqAlternate spelling for &=
^=Bitwise exclusive or (XOR) and assignflags ^= new_flags;yes
xor_eqAlternate spelling for ^=
|=Bitwise normal OR and assignflags |= new_flags;yes
or_eqAlternate spelling for |=
<<=Bitwise shift left and assignflags <<= 2;yes
>>=Bitwise shift right and assignflags >>= 2;yes
17throwthrow exceptionthrow EClass(“Message”);no 
18,Sequential evaluation operatorfor (i = 0, j = 0; i < 10; i++, j++) ...yesleft to right

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
算符优先分析文法是一种工具,在编译的过程中,隶属于语法分析环节,却又与中间代码的生成息息相关,编译可以分为五个阶段:词法分析、语法分析、语义分析(中间代码的生成)、代码优化、目标代码生成。语法分析是指:在词法分析基础上,将单词符号串转化为语法单位(语法范畴)(短语、子句、句子、程序段、程序),并确定整个输入串是否构成语法上正确的程序。也就是说语法分析是检验输入串的语法是否正确,注意这里的语法正确,只是简单地符合自己定义的规范,而不能检测出运行时错误,比如"X/0",空指针错误,对象未初始化等错误。在这一个实验中,我将通过算符优先分析文法这一个工具,在语法分析的时候,顺便进行语义分析,也就是识别出语法单位,同时简要的将识别出的中间代码进行计算(目标代码的生成+运行),得到相应的结果,来检验自己设计的正确性。可以说题目虽然叫做算符优先分析文法,其实却是一个贯穿了“词法分析+语法分析+语义分析+中间代码优化+目标代码生成+运行”全过程的一个极具概括性的程序。如果能将这个程序得心应手的完成出来,我相信诸位对编译原理的掌握也算是炉火纯青了。时隔将近两年再来整理自己以前写过的实验报告,还是挺有感慨的,对一件东西感兴趣,原来影响还会如此深远,还记得自己当时连续六个小时全神贯注写出的实验报告,现在看看竟然写了五六十页,核心内容也有三四十页,不觉的感慨当年充满热情的时代慢慢的竟走出许久

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值