⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expression2.y

📁 语法分析 语法分析
💻 Y
字号:
%{{*   计算简单的数学表达式的yacc程序   编译:yacc Expression ExpressionY *}unit ExpressionY2;interfaceuses  SysUtils, LexLib, YaccLib, ExpressionL2;{指定不同于整数的类型时,一定要使用%type <Real> expression 指定表达式的类型}{同时要使用 %token <Real> Number来指定token的类型}%}%token NAME%token <Real> NUMBER%type <Real> expression %left '-' '+'%left '*' '/'%nonassoc UMINUS%%statement:	NAME '=' expression	|	expression		{ writeln(format('= %f', [$1])); }	;expression:	expression '+' expression { $$ := $1 + $3; }	|	expression '-' expression { $$ := $1 - $3; }	|	expression '*' expression { $$ := $1 * $3; }	|	expression '/' expression				{	if($3 = 0) then						yyerror('除零错误')					else						$$ := $1 / $3;				}	|	'-' expression %prec UMINUS	{ $$ := -$2; }	|	'(' expression ')'	{ $$ := $2; }	|	NUMBER			{ $$ := $1; }	;%%end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -