69,382
社区成员
发帖
与我相关
我的任务
分享
%{
#include "stdafx.h"
#include "language.tab.h"
extern int yywrap();
%}
ws [ \t]+
line \n
%%
var { return VAR; }
[a-z]+[a-z0-9]* {
strncpy(yylval.string,yytext,sizeof(yylval.string));
return NAME;
}
. { return yytext[0]; }
%%
%union{
char string[1024];
};
%token VAR
%token <string> NAME
// %start value
%%
declare: VAR NAME ';'
;
%%
state 0
0 $accept: . declare $end
VAR shift, and go to state 1
declare go to state 2
state 1
1 declare: VAR . NAME ';'
NAME shift, and go to state 3
state 2
0 $accept: declare . $end
$end shift, and go to state 4
state 3
1 declare: VAR NAME . ';'
';' shift, and go to state 5
state 4
0 $accept: declare $end .
$default accept
state 5
1 declare: VAR NAME ';' .
$default reduce using rule 1 (declare)