📄 myparser.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 + -