我試圖在bison中獲取令牌的值,但似乎我一次獲得多個令牌。 這裏是我的Flex代碼:在flex和bison中獲取字符串令牌值超過預期
%{
#include <stdio.h>
#include "y.tab.h"
//YYSTYPE yylval;
%}
semicolon [;]
var [a-c]
digit [0-9]+
string [a-zA-Z]+
%%
Counter {yylval = yytext; return VAR;}
[a-zA-Z0-9]+ { yylval = yytext; return STRING;}
....
這裏是我的野牛代碼:
%{
#define YYSTYPE char *
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int limit;
int input;
int count=0;
char a[20];
char message[200];
%}
%token DIGIT VAR OPENPAR CLOSEPAR PETIK
%token WRITELN DO FOR BEGINKEY END TO EQUAL
%token SEMICOLON VARKEY COLON TYPE STRING READLN
%start program
%%
program: dlist slist {printf("L3: HALT");}
;
dlist: /* nothing */
| decl dlist
;
decl: VARKEY VAR COLON TYPE SEMICOLON
;
slist: stmt
| stmt slist
| BEGINKEY FOR VAR EQUAL DIGIT TO DIGIT DO slist END
{
printf("\nBeginFunc\n");
printf("t%d = %d;\n",count,$5);
printf("%s = t%d\n",$3,count);
....
所以,問題是,當我輸入writeln( 'for循環');.該程序只能得到forloop,但它會得到forloop'); 但是當我像這樣一行一行地輸入: forloop ' ) ; 僅顯示forloop 什麼可能導致此問題?
小心標記; Flex標籤用於Adobe/Apache UI框架。 – JeffryHouser 2013-04-30 13:12:25