Thursday, March 28, 2019

Data Sets

 Weather



@relation weather

@attribute matchno numeric

@attribute humidity numeric

@attribute temperature numeric

@attribute weathercondition{sunny,cloudy}

@attribute occuranceofrain{y,n,maybe}

@attribute possibilityofmatch{y,n,maybe}

@data   

1,29,39,sunny,n,y

2,23,35,sunny,n,y

3,12,20,cloudy,y,n

4,22,25,cloudy,maybe,maybe

5,17,23,cloudy,y,n

6,30,45,sunny,n,y

7,15,24,cloudy,maybe,maybe

8,20,29,cloudy,maybe,maybe

9,30,35,sunny,n,y

10,29,35,sunny,n,y

11,29,24,sunny,n,y

12,26,30,sunny,n,y

13,22,24,cloudy,maybe,maybe

14,23,24,cloudy,maybe,maybe

15,30,38,sunny,n,y

16,29,30,sunny,n,y

17,19,21,cloudy,y,n

18,22,24,cloudy,n,y

19,28,30,sunny,n,y

20,31,37,sunny,n,y


 employee







@relation employee
@attribute eid numeric
@attribute ename string
@attribute age {20-29,>30,<22}
@attribute income{20000-30000,>30000,<40000}
@attribute buys{YES,NO}
@data
101,"A",20-29,20000-30000,YES
102,"B",<22,>30000,NO
103,"C",>30,<40000,NO
104,"D",20-29,20000-30000,YES
105,"E",20-29,>30000,NO
106,"F",<22,<40000,NO
107,"G",<22,>30000,NO
108,"H",>30,20000-30000,NO
109,"I",20-29,<40000,NO
110,"J",<22,<40000,NO
111,"K",20-29,20000-30000,NO
112,"L",<22,20000-30000,NO
113,"M",20-29,20000-30000,NO
114,"N",20-29,20000-30000,YES
115,"O",<22,<40000,NO
116,"P",20-29,20000-30000,YES
117,"Q",<22,<40000,NO
118,"R",>30,20000-30000,NO
119,"S",20-29,20000-30000,YES
120,"T",<22,<40000,NO








labour

@relation labour
@attribute lid numeric
@attribute lname string
@attribute age {30-39,45-50}
@attribute workinghours {6-8,8-10}
@attribute income {20000-30000,30000-40000}
@data
101001,"A",30-39,8-10,30000-40000
101002,"B",45-50,6-8,20000-30000
10103,"C",30-39,8-10,30000-40000
10104,"D",45-50,6-8,20000-30000
10105,"E",30-39,8-10,30000-40000
10106,"F",45-50,6-8,20000-30000
10107,"G",45-50,6-8,20000-30000
10108,"H",30-39,8-10,30000-40000
10109,"I",30-39,8-10,30000-40000
101010,"J",45-50,6-8,20000-30000
101011,"K",30-39,8-10,30000-40000
101012,"L",45-50,6-8,20000-30000
101013,"M",45-50,6-8,20000-30000
101014,"N",30-39,8-10,30000-40000
101015,"O",45-50,6-8,20000-30000
101016,"P",45-50,6-8,20000-30000
101017,"Q",30-39,8-10,30000-40000
101018,"R",45-50,6-8,20000-30000
101019,"S",45-50,6-8,20000-30000
101020,"T",30-39,8-10,30000-40000

 student


@relation student
@attribute sid numeric
@attribute name string
@attribute age numeric
@attribute branch {IT}
@attribute percentage {70-80,80-90,90-100}
@attribute grade {C,B,A}
@data
101,"A",19,IT,70-80,C
102,"B",19,IT,90-100,A
103,"C",20,IT,90-100,A
104,"D",18,IT,70-80,C
105,"E",19,IT,80-90,B
106,"F",20,IT,80-90,B
107,"G",20,IT,70-80,C
108,"H",20,IT,80-90,B
109,"I",19,IT,90-100,A
110,"J",18,IT,70-80,C
111,"K",18,IT,80-90,B
112,"L",20,IT,70-80,C
113,"M",19,IT,80-90,B
114,"N",19,IT,80-90,B
115,"O",20,IT,90-100,A
116,"P",20,IT,70-80,C
117,"Q",19,IT,90-100,A
118,"R",20,IT,80-90,B
119,"S",20,IT,90-100,A
120,"T",20,IT,70-80,C














Friday, March 22, 2019

Design LALR Bottom up Parser using YACC.

Design LALR Bottom up Parser.

<parser.l>
%{
#include<stdio.h> #include "y.tab.h"
%}
%%
[0-9]+ {yylval.dval=atof(yytext); return DIGIT;
}
\n|. return yytext[0];
%%
<parser.y>
%{
/*This YACC specification file generates the LALR parser for the program considered in experiment 4.*/
#include<stdio.h>
%}
%union
{
double dval;
}
%token <dval> DIGIT
%type <dval> expr
%type <dval> term
%type <dval> factor
%%
line: expr '\n' { printf("%g\n",$1);
}
;
expr: expr '+' term {$$=$1 + $3 ;}
| term
;
term: term '*' factor {$$=$1 * $3 ;}
| factor
;
factor: '(' expr ')' {$$=$2 ;}
| DIGIT
 
;
%%
int main()
{
yyparse();
}
yyerror(char *s)
{
printf("%s",s);
}
Output:
$lex parser.l
$yacc –d parser.y
$cc lex.yy.c y.tab.c –ll –lm
$./a.out 2+3
5.0000





click here to download

Implement the Lexical Analyzer Using Lex Tool.




/* program name is lexp.l */
%{
/* program to recognize a c program */ int COMMENT=0;
%}
identifier [a-zA-Z][a-zA-Z0-9]*
%%
#.* { printf("\n%s is a PREPROCESSOR DIRECTIVE",yytext);} int |
float | char | double | while | for |
do | if |
break | continue | void | switch | case | long | struct | const | typedef | return | else |
goto {printf("\n\t%s is a KEYWORD",yytext);} "/*" {COMMENT = 1;}
/*{printf("\n\n\t%s is a COMMENT\n",yytext);}*/

"*/" {COMMENT = 0;}
/* printf("\n\n\t%s is a COMMENT\n",yytext);}*/
{identifier}\( {if(!COMMENT)printf("\n\nFUNCTION\n\t%s",yytext);}
\{ {if(!COMMENT) printf("\n BLOCK BEGINS");}
\} {if(!COMMENT) printf("\n BLOCK ENDS");}
{identifier}(\[[0-9]*\])? {if(!COMMENT) printf("\n %s IDENTIFIER",yytext);}
\".*\" {if(!COMMENT) printf("\n\t%s is a STRING",yytext);}
[0-9]+ {if(!COMMENT) printf("\n\t%s is a NUMBER",yytext);}
\)(\;)? {if(!COMMENT) printf("\n\t");ECHO;printf("\n");}
\( ECHO;
= {if(!COMMENT)printf("\n\t%s is an ASSIGNMENT OPERATOR",yytext);}
\<= |
\>= |
\< |
== |
\> {if(!COMMENT) printf("\n\t%s is a RELATIONAL OPERATOR",yytext);}
%%
int main(int argc,char **argv)
{
if (argc > 1)
{
FILE *file;
file = fopen(argv[1],"r"); if(!file)
{
printf("could not open %s \n",argv[1]); exit(0);
}
yyin = file;
}
yylex(); printf("\n\n"); return 0;
} int yywrap()
{
return 0;
}

Input:
$vi var.c #include<stdio.h> main()
{
int a,b;
}

Output:
$lex lex.l
$cc lex.yy.c
$./a.out var.c
#include<stdio.h> is a PREPROCESSOR DIRECTIVE FUNCTION
main (
)
BLOCK BEGINS
int is a KEYWORD a IDENTIFIER
b IDENTIFIER BLOCK ENDS

Saturday, March 16, 2019

sample lex

/*lex program to count number of words*/
%{
#include<stdio.h>
#include<string.h>
int i = 0;
%}

/* Rules Section*/
%%
([a-zA-Z0-9])* {i++;} /* Rule for counting
number of words*/

"\n" {printf("%d\n", i); i = 0;}
%%

int yywrap(void){}

int main()
{
// The function that starts the analysis
yylex();

return 0;
}

 https://meet.google.com/tcg-zgzv-dye