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

📄 myparser.y

📁 自动生成工具lex yacc构造的小计算器
💻 Y
字号:
%{
/****************************************************************************
myparser.y
ParserWizard generated YACC file.

Date: 2007年12月5日
****************************************************************************/

#include <stdio.h>
#include <ctype.h>

#include "mylexer.h"
%}

/////////////////////////////////////////////////////////////////////////////
// declarations section

%token NUMBER
%token LEFT
%token RIGHT
%token PLUS
%token MINUS
%token TIMES

// attribute type
%include {
#ifndef YYSTYPE
#define YYSTYPE int
#endif
}

// place any declarations here

%%

/////////////////////////////////////////////////////////////////////////////
// rules section





// place your YACC rules here (there must be at least one)


command : exp  {printf("%d\n", $1); }
	;
exp     : exp PLUS term  {$$ = $1 + $3;}
        | exp MINUS term  {$$ = $1 - $3; }
        | term {$$ = $1; }
        ;
term    : term TIMES factor {$$ = $1 * $3; }
        | factor {$$ = $1; }
        ;
factor  : NUMBER {$$ = $1; }
        | LEFT exp RIGHT {$$ = $2; }
        ; 


%%

/////////////////////////////////////////////////////////////////////////////
// programs section

int main(void)
{
	return yyparse();
}

⌨️ 快捷键说明

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