Checking of repetition of inputs and basic items FLEX

Flex File 

%{

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *s;
int i=0 ;
int f=0;
char arr[8][8];

%}

Operator [+|*|/|>|<|=]

Parenthsis [(|)]

Quoted [“][a-zA-Z][a-zA-Z_0-9_?_, ]*[“]

Integers [0-9]+

Identifier [a-zA-Z][a-zA-Z_0-9]*

%%

[ \t\n] ;

int|float|decimal|double|array|list printf( “The sentence contains the special DataType = %s\n”, yytext );

if|then|else|endif|print|newline printf( “The sentence contains the special keyword = %s\n”, yytext );

“;” printf( “The sentence contains the special Semicolon = %s\n”, yytext );

“-” printf( “The sentence contains the special operator = %s\n”, yytext );
“=>” printf( “The sentence contains the special operator = %s\n”, yytext );
“>=” printf( “The sentence contains the special operator = %s\n”, yytext );
“<=” printf( “The sentence contains the special operator = %s\n”, yytext );
“=<” printf( “The sentence contains the special operator = %s\n”, yytext );
“==” printf( “The sentence contains the special operator = %s\n”, yytext );
“!=” printf( “The sentence contains the special operator = %s\n”, yytext );

{Parenthsis} printf( “The sentence contains the special Parenthesis = %s\n”, yytext );

{Quoted} s=yytext; s++; s[strlen(s)-1] =”; printf( “The sentence contains the special quote = %s \n”,s);

{Identifier} i=0; for(i;i<8;i++) {if(strcmp(arr[i], yytext)==0){printf(” Identifier Already Exsist = %s \n “,yytext);i=1;break;}} if(i>1){printf(“The sentence contains the special Identifier = %s \n”,yytext);strcpy(arr[f],yytext);++f;};

{Integers} printf(“The sentence contains the special integer = %d \n”,atoi(yytext));

 

{Operator} printf(“The sentence contains the special operator = %s\n”,yytext);

 

 

 

%%

int main(int argc,char* argv[])
{
yyin=fopen(argv[1],”r”);
yylex();

 

 

}

 

 

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