📄 yaac.c
字号:
%{
/****************************************************************************
myparser.y
ParserWizard generated YACC file.
Date: 2007年11月29日
****************************************************************************/
#include<stdio.h>
#include<ctype.h>
%}
%token NUMBER
%left '+'
%left '*'
%left '-'
%%
command : exp {printf("%d\n",$1);}
;
exp : exp '+' term {$$ = $1 + $3;}
| exp '-' term {$$ = $1 - $3;}
| term {$$ = $1;}
;
term : term '*' factor { $$ = $1 * $3;}
| factor { $$ = $1;}
;
factor : NUMBER { $$ = $1;}
| '(' exp ')' { $$ = $2;}
;
%%
int main()
{
return yyparse();
}
int yylex(void)
{
int c;
while(( c = getchar())==' ');
if( isdigit(c) ) {
ungetc(c,stdin);
scanf("%d",&yylval);
return (NUMBER);
}
if( c == '\n' ) return 0;
return (c);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -