sentence structure bison flex(Salik-Yar-Khan)

TP.FLEX:

%{

#include “TP.tab.h”

#include <stdio.h>

#include <ctype.h>

#include <stdlib.h>

%}

 

 

%%

 

“i”|”they”|we|you                         { return SUBJECT; }

 

“went”|”ate”|”took”|”killed”    { return VERB; }

 

 

[a-z]+                                                    { return OBJECT; }

 

 

[\n]                        { return *yytext; } ;

 

[ \t]                        ;

 

.              yyerror(“invalid character”);

 

 

%%

 

int yywrap(void)

{

return 1;

}TP.Y

%{

#include <stdio.h>

#include <string.h>

void yyerror(const char *s);

%}

 

%token SUBJECT VERB OBJECT

 

%start prog

 

%%

prog : prog S ‘\n’

|

;

 

S              : expr

|

;

 

expr       : SUBJECT VERB OBJECT  {printf(“Accepted!\n”);}

;

 

%%

 

 

void yyerror(const char *s)

{

printf(“%s\n”, s);

}

 

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