LEX & YACC 写的一个表达式计算程序
来源:互联网 发布:动漫二维码制作软件 编辑:程序博客网 时间:2024/06/06 09:39
前两天觉得LEX和YACC挺强大的,稍微写了一个处理表达式的程序
LEX文件:
YACC文件:
编译并运行:
lex expr.l && yacc -d expr.y && gcc lex.yy.c y.tab.c -o expr -ll && echo "OK" && ./expr
附表达式的优先级表:
http://www.cppreference.com/wiki/operator_precedence
::
Scope resolution operatorClass::age = 2;nonone2()
()
[]
->
.
++
--
const_cast
dynamic_cast
static_cast
reinterpret_cast
typeid
Function callMember initalization
Array access
Member access from a pointer
Member access from an object
Post-increment
Post-decrement
Special cast
Special cast
Special cast
Special cast
Runtime type informationisdigit('1')
c_tor(int x, int y) : _x(x), _y(y*10){};
array[4] = 2;
ptr->age = 34;
obj.age = 34;
for( int i = 0; i < 10; i++ ) cout << i;
for( int i = 10; i > 0; i-- ) cout << i;
const_cast<type_to>(type_from);
dynamic_cast<type_to>(type_from);
static_cast<type_to>(type_from);
reinterpret_cast<type_to>(type_from);
cout « typeid(type).name();yes
yes
yes
yes
no
yes
yes
no
no
no
no
noleft to right3
!
not
~
compl
++
--
-
+
*
&
new
new []
delete
delete []
(type)
sizeof
Logical negationAlternate spelling for !
Bitwise complement
Alternate spelling for ~
Pre-increment
Pre-decrement
Unary minus
Unary plus
Dereference
Address of
Dynamic memory allocation
Dynamic memory allocation of array
Deallocating the memory
Deallocating the memory of array
Cast to a given type
Return size of an object or typeif( !done ) …
flags = ~flags;
for( i = 0; i < 10; ++i ) cout << i;
for( i = 10; i > 0; --i ) cout << i;
int i = -1;
int i = +1;
int data = *intPtr;
int *intPtr = &data;
long *pVar = new long;
MyClass *ptr = new MyClass(args);
delete pVar;
delete [] array;
int i = (int) floatNum;//int size = sizeof(float);yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
noright to left4
->*
.*
Member pointer selectorMember object selectorptr->*var = 24;
obj.*var = 24;yes
noleft to right5
*
/
%
MultiplicationDivision
Modulusint i = 2 * 4;
float f = 10.0 / 3.0;
int rem = 4 % 3;yes
yes
yesleft to right6
+
-
AdditionSubtractionint i = 2 + 3;
int i = 5 - 1;yes
yesleft to right7
<<
>>
Bitwise shift leftBitwise shift rightint flags = 33 << 1;
int flags = 33 >> 1;yes
yesleft to right8
<
<=
>
>=
Comparison less-thanComparison less-than-or-equal-to
Comparison greater-than
Comparison greater-than-or-equal-toif( i < 42 ) …
if( i <= 42 ) ...
if( i > 42 ) …
if( i >= 42 ) ...yes
yes
yes
yesleft to right9
==
eq
!=
not_eq
Comparison equal-toAlternate spelling for ==
Comparison not-equal-to
Alternate spelling for != if( i == 42 ) ...
if( i != 42 ) …
yes
-
yes
left to right10
&
bitand
Bitwise ANDAlternate spelling for & flags = flags & 42;
yes
left to right11
^
xor
Bitwise exclusive OR (XOR)Alternate spelling for ^ flags = flags ^ 42;
yes
left to right12
|
bitor
Bitwise inclusive (normal) ORAlternate spelling for |flags = flags | 42;
yes
left to right13
&&
and
Logical ANDAlternate spelling for && if( conditionA && conditionB ) …
yes
left to right14
||
or
Logical ORAlternate spelling for ||if( conditionA || conditionB ) ...
yes
left to right15
? :
Ternary conditional (if-then-else)int i = (a > b) ? a : b;noright to left16=
+=
-=
*=
/=
%=
&=
and_eq
^=
xor_eq
|=
or_eq
<<=
>>=
Assignment operatorIncrement and assign
Decrement and assign
Multiply and assign
Divide and assign
Modulo and assign
Bitwise AND and assign
Alternate spelling for &=
Bitwise exclusive or (XOR) and assign
Alternate spelling for ^=
Bitwise normal OR and assign
Alternate spelling for |=
Bitwise shift left and assign
Bitwise shift right and assignint a = b;
a += 3;
b -= 4;
a *= 5;
a /= 2;
a %= 3;
flags &= new_flags;
flags ^= new_flags;
flags |= new_flags;
flags <<= 2;
flags >>= 2;yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yesright to left17
throw
throw exceptionthrow EClass(“Message”);no18,
Sequential evaluation operatorfor( i = 0, j = 0; i < 10; i++, j++ ) …yesleft to right
- LEX & YACC 写的一个表达式计算程序
- Lex和Yacc从入门到精通(3)--一个极其简单的lex和yacc程序
- Lex和Yacc从入门到精通(3)--一个极其简单的lex和yacc程序
- LineCalc,一个基于Lex&Yacc的简单行计算工具
- 逆波兰式(后缀表达式)的运用-计算四则表达式并用lex,Yacc拓展
- 一个Lex/Yacc完整的示例(转)
- 编译器是怎么工作的?使用yacc 和lex 写一个计算器(1)
- 编译器是怎样工作的?用lex和yacc 写一个计算器(2)
- Lex和Yacc从入门到精通(5)-开发Lex和Yacc程序的一般步骤
- Lex和Yacc从入门到精通(5)-开发Lex和Yacc程序的一般步骤
- yacc&lex-命名正则表达式
- 用Lex(flex)和yacc(bison)写的简单计算器
- 使用LEX&YACC设计一个计算器的例子
- 一个Lex/Yacc完整的示例(可使用C++)
- 一个Lex/Yacc完整的示例(可使用C++)
- Lex与Yacc的结合
- Lex与Yacc的结合
- Lex与Yacc的使用
- 有谁做过Sametime与OA待办事宜的例子吗?
- 【连载】优秀程序员的 45 个习惯之习惯33
- 随想
- 电锯惊魂6果然让我失望了
- 表结构设计器EZDML1.5发布
- LEX & YACC 写的一个表达式计算程序
- 【OS】PV操作-理发师问题-VC++多线程模拟实现
- 关于win7下不能够使用arcmap 9.3破解的解决方法。
- asp.net(vs2005)使用updatepanel控件详解
- MySQL 存储过程
- 【OS】PV操作-哲学家问题-VC++多线程模拟实现
- mysql 5.0存储过程学习总结http://www.ccvita.com/100.html
- 没心情了
- js- 引用和复制(传值和传址)