Do-While Accepter Bison and Flex

Do.Flex

%{
#include “do.tab.h”
#include<stdlib.h>
%}

%%
[ \t\n]
do    {return DO;}
while {return WHILE;}
“(”     {return BRO;}
“)”     {return BRC; }
“{”     {return CUBRO; }
“}”     {return CUBRC; }
“=”     {return EQUAL; }
“;”     {return SEMI; }

[0-9]+ {yylval=*yytext;return NUM;}
[a-zA-Z]+ {yylval=*yytext;return ID;}

.
%%

int yywrap(void)
{
return 1;
}

 

Do.Y

%{

#include<stdio.h>
void yyerror(char *s);

%}

%token DO WHILE BRO BRC CUBRO CUBRC EQUAL ID NUM SEMI

%%

S: Statment {printf(“Accept \n”);}

Statment:DO CUBRO E2 CUBRC WHILE BRO E1 BRC SEMI

E1:ID EQUAL ID
  |ID EQUAL NUM

E2:
  |ID SEMI
   

 

%%
void yyerror(char *s)
{
 
{printf(“\n do-while is wrong”);}

}

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s