While Accepter Bison and Flex

While.Y

%{

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

%}

%token WHILE BRO BRC CUBRO CUBRC EQUAL ID NUM  INCRE DECRE SEMI

%%
Statement:WHILE BRO E1 BRC CUBRO E2 SEMI E3 CUBRC {printf(“Accept \n”);}

E1:ID EQUAL ID
  |ID EQUAL NUM
  ;
E2:NUM
  |ID
   ;
E3:ID INCRE SEMI
   |ID DECRE SEMI
   |NUM DECRE SEMI
   |NUM INCRE SEMI
;

%%
void yyerror(char *s)
{

{printf(“\n while ghalat”);}

}

int main(void)
{
yyparse();
return 0;
}
While.Flex
%{

#include “while.tab.h”
#include<stdlib.h>

%}

%%
while {return WHILE; }
“(”  {return BRO; }
“)”  {return BRC; }
“{”  {return CUBRO; }
“}”  {return CUBRC; }
“=”  {return EQUAL; }
“;”  {return SEMI; }
“++” {return INCRE;}
“–” {return DECRE;}

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

%%

int yywrap(void)
{
return 1;
}

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