Passenger:
PNR_No
Ticket_No
Name
Age
Sex
PPNO
:
:
:
:
:
:
Reservation:
PNR_No
j_date
No_of_seats
Address
Contact_No
Status
Class
Cancel:
PNR_No
j_date
No_of_seats
Address
Contact_No
Status
: number(9)(foreign key)
: date
: integer(8)
: varchar(50)
: number(9)
: char(2)
Ticket:
Ticket_No
j_date
Age
Sex
Source
Destination
xDep_time
:
:
:
:
:
:
:
number(9)(primary key)
date
int(4)
char(10)
varchar(20)
varchar(20)
varchar(4)
Page No:
Page No:
Source
Destination
J_day
type
Passenger:
Pnr_No
Ticket_no
Name
Age
Sex
PPNO
Reservation:
Pnr_No
Journey_date
No_of_seat
s
Address
Contact_No
Status
Class
Cancel:
Pnr_No
Journey_date
No_of_seats
Address
Contact_N
o
Status
Ticket:
Ticket_N
o
J_date
Age
sex
source
Destinatio
n
Dep_tim
e
Page No:
Step 3: Accept the License Agreement and Choose the setup type that
best suits your needs. For common program features select Typical and its
recommended for general use. To continue, click next.
Page No:
Step 5: The program features you selected are being installed. Please wait
while the setup wizard installs MySQL 5.5. This may take several minutes.
Page No:
Page No:
Step 8: Wizard Completed. Setup has finished installing MySQL 5.5. Check
the configure the MySQL server now to continue. Click Finish to exit the
wizard
Step 9: The configuration wizard will allow you to configure the MySQL
Server 5.5 server instance. To continue, click next.
Page No:
Step 10: Select a standard configuration and this will use a general
purpose configuration for the server that can be tuned manually. To
continue, click next.
Step 11: Check on the install as windows service and include bin
directory in windows path. To continue, click next.
Page No:
Step 12: Please set the security options by entering the root password and
confirm retype the password. To continue, click next.
Page No:
Page No:
CREATE Database:
mysql> create database roadways;
Query OK, 1 row affected (0.00 sec)
mysql>
CREATE Tables
Step 1:
mysql> \r roadways
(or) \u roadways
Connection id: 3
Current database: roadways
Step 2: to create tables:
mysql> create table passenger (pnr_no integer(9) PRIMARY KEY,ticket_no
integer(9), name varchar(20), age int(4), sex char(10), ppno varchar(15));
Query OK, 0 rows affected (0.13 sec)
mysql> desc passenger;
+-----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| pnr_no
| int(9)
| NO
| PRI |
|
|
| ticket_no | int(9)
| YES |
| NULL
|
|
| name
| varchar(20) | YES |
| NULL
|
|
| age
| int(4)
| YES |
| NULL
|
|
| sex
| char(10)
| YES |
| NULL
|
|
| ppno
| varchar(15) | YES |
| NULL
|
|
+-----------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
Page No:
mysql> create table ticket(ticket_no int(9) primary key, age int(3), sex
varchar (2)not null, source varchar(20), destination varchar(20), dep_time
varchar(4));
Query OK, 0 rows affected (0.05 sec)
mysql> desc ticket;
+-------------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| ticket_no
| int(9)
| NO
| PRI |
|
|
| age
| int(3)
| YES |
| NULL
|
|
| sex
| varchar(2) | NO
|
|
|
|
| source
| varchar(20) | YES |
| NULL
|
|
| destination | varchar(20) | YES |
| NULL
|
|
| dep_time
| varchar(4) | YES |
| NULL
|
|
+-------------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
Page No:
ALTER Table
INSERT
Page No:
|
105 | 2011-08-17 |
2 | KHAMMAM
|
261534 | CNF
|
+--------+------------+-------------+-----------------+------------+--------+
5 rows in set (0.00 sec)
1.3
UPDATE Table:
Page No:
+--------+--------+-------------+
| 2233
| GNT
| HYD
|
| 2244
| GNT
| TPTY
|
| 2255
| GNT
| BZA
|
| 2266
| GNT
| VSP
|
+--------+--------+-------------+
Drop table:
Page No:
Page No:
9) Display the
Wednesday
Bus
numbers
that
travel
on
Sunday
and
Page No:
2.
Page No:
4.
Find the number of seats booked in each class where
the number of seats is greater than 1.
mysql> select * from reservation;
+--------+------------+-------------+----------+------------+--------+-------+
| pnr_no | jdate
| no_of_seats | address | contact_no | status | class |
+--------+------------+-------------+----------+------------+--------+-------+
|
101 | 2011-08-07 |
4 | GUNTUR
|
235456 | CNF
| A
|
|
102 | 2011-08-17 |
5 | KODAD
|
325456 | CNF
| A
|
|
103 | 2011-08-17 |
4 | KODAD
|
325478 | CNF
| B
|
|
104 | 2011-08-07 |
4 | GUNTUR
|
3456314 | CNF
| B
|
|
105 | 2011-08-22 |
7 | NALGONDA |
4456314 | CNF
| B
|
|
106 | 2011-08-22 |
7 | KHAMMAM |
4564314 | CNF
| B
|
|
107 | 2011-08-22 |
3 | KHAMMAM |
4614314 | CNF
| A
|
|
108 | 2011-08-22 |
3 | NALGONDA |
4684314 | CNF
| A
|
|
108 | 2011-08-22 |
8 | NALGONDA |
4684314 | CNF
| A
|
|
109 | 2011-08-23 |
1 | NALGONDA |
2684314 | CNF
| C
|
|
110 | 2011-08-23 |
1 | HYD
|
6284314 | CNF
| D
|
|
111 | 2011-08-22 |
2 | HYD
|
6824314 | CNF
| E
|
+--------+------------+-------------+----------+------------+--------+-------+
12 rows in set (0.00 sec)
5.
Page No:
b) INSERT
mysql> insert into male_pass(pnr_no,age,sex) values(201,22,M);
Query OK, 1 row affected (0.01 sec)
mysql> insert into male_pass(pnr_no,age,sex) values(202,25,F);
Query OK, 1 row affected (0.01 sec)
mysql> insert into male_pass(pnr_no,age,sex) values(201,24,F);
Query OK, 1 row affected (0.01 sec)
c) Display VIEW
mysql> SELECT * FROM male_pass;
+--------+------+------+
| pnr_no | age | sex |
+--------+------+------+
|
101 |
28 | M
|
|
102 |
28 | M
|
|
106 |
28 | M
|
|
107 |
16 | M
|
|
108 |
16 | M
|
|
201 |
22 | M
|
+--------+------+------+
6 rows in set (0.00 sec)
d) DROP VIEW
mysql> drop view male_pass;
Query OK, 0 row affected (0.01 sec)
Page No:
mysql> delimiter ;
mysql> SELECT * FROM BUS_LOG;
Empty set (0.00 sec)
mysql> insert into bus values(3355,"RAJ","MAS","MON","AC");
Query OK, 1 row affected (0.03 sec)
mysql> SELECT * FROM BUS_LOG;
+--------+-------+------+--------------+
| bus_no | j_day | type | lastinserted |
+--------+-------+------+--------------+
| 3355
| MON
| AC
| 15:34:34
|
+--------+-------+------+--------------+
1 row in set (0.00 sec)
b) Update trigger:
mysql> select * from ticket;
+-----------+------+-----+--------+-------------+----------+--------+
| ticket_no | age | sex | source | destination | dep_time | b_type |
+-----------+------+-----+--------+-------------+----------+--------+
|
101 |
28 | M
| GNT
| VSP
|
10 | AC
|
|
102 |
28 | M
| GNT
| BZA
|
11 | NAC
|
|
103 |
27 | F
| GNT
| KKD
|
11 | AC
|
|
104 |
22 | F
| GNT
| HYD
|
12 | AC
|
+-----------+------+-----+--------+-------------+----------+--------+
5 rows in set (0.01 sec)
mysql> delimiter $$
Page No:
c) Delete Trigger :
mysql> drop trigger bus_trig;
Query OK, 0 rows affected (0.01 sec)
Page No:
mysql> delimiter $$
mysql> create procedure myproc()
-> BEGIN
-> SELECT count(ticket_no) from ticket where age>=27;
-> END $$
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
Page No:
Page No:
Page No:
mysql> DELIMITER ;
mysql> call male_female_list();
+-------------------------------+
| Male Passenger Names List is: |
+-------------------------------+
| name
|
+-------------------------------+
| Ramakrishna
|
| Ashok
|
| Raghu
|
| alok
|
| revok
|
| Venu
|
+-------------------------------+
6 rows in set (0.02 sec)
+----------------------------------+
| Female Passengers Names List is: |
+----------------------------------+
| name
|
+----------------------------------+
| Bhavani
|
| Jyothi
|
| Saritha
|
| Renu
|
| Aarshitha
|
+----------------------------------+
5 rows in set (0.02 sec)
Query OK, 0 rows affected (0.02 sec)
Page No:
Page No:
c=getc(f1);
while(isdigit(c))
{
tokenvalue*=10+c-'0';
c=getc(f1);
}num[i++]=tokenvalue;
ungetc(c,f1);
}else if(isalpha(c))
{
putc(c,f2);
c=getc(f1);
while(isdigit(c)||isalpha(c)||c=='_'||c=='$')
{
putc(c,f2);
c=getc(f1);
}putc(' ',f2);
ungetc(c,f1);
}else if(c==' '||c=='\t')
printf(" ");
else if(c=='\n')
lineno++;
else
putc(c,f3);
}fclose(f2);
fclose(f3);
fclose(f1);
printf("\nThe no's in the program are");
for(j=0;j<i;j++)
printf("%d",num[j]);
printf("\n");
f2=fopen("identifier","r");
k=0;
printf("The keywords and identifiersare:");
while((c=getc(f2))!=EOF)
Page No:
{
if(c!=' ')str[k++]=c;
else
{
str[k]='\0';
keyword(str);
k=0;
}
}fclose(f2);
f3=fopen("specialchar","r");
printf("\nSpecial characters are");
while((c=getc(f3))!=EOF)
printf("%c",c);
printf("\n");
fclose(f3);
printf("Total no. of lines are:%d",lineno);
getch();
}
Output:
Enter the c program:
a+b*c
d/f
^Z
The no's in the program are
The keywords and identifiersare:
a is an identifier
b is an identifier
c is an identifier
d is an identifier
f is an identifier
Special characters are+*/
Total no. of lines are:2
Page No:
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;
}
Page No:
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
Page No:
if(lastentry+1>=MAX)
Error_Message("Symbpl table is full");
if(lastchar+len+1>=MAX)
Error_Message("Lexemes array is full");
lastentry=lastentry+1;
symtable[lastentry].token=tok;
symtable[lastentry].lexptr=&lexemes[lastchar+1];
lastchar=lastchar+len+1;
strcpy(symtable[lastentry].lexptr,s);
return lastentry;
}/*void Initialize()
{
struct entry *ptr;
for(ptr=keywords;ptr->token;ptr+1)
insert(ptr->lexptr,ptr->token);
}*/
int lexer()
{
int t;
int val,i=0;
while(1)
{
t=getchar();
if(t==' '||t=='\t');
else if(t=='\n')
lineno=lineno+1;
else if(isdigit(t))
{
ungetc(t,stdin);
scanf("%d",&tokenval);
return NUM;
}else if(isalpha(t))
{
while(isalnum(t))
{
buffer[i]=t;
t=getchar();
i=i+1;
if(i>=SIZE)
Error_Message("Compiler error");
}buffer[i]=EOS;
if(t!=EOF)
Page No:
ungetc(t,stdin);
val=look_up(buffer);
if(val==0)
val=insert(buffer,ID);
tokenval=val;
return symtable[val].token;
}else if(t==EOF)
return DONE;
else
{
tokenval=NONE;
return t;
}
}
}void Match(int t)
{
if(lookahead==t)
lookahead=lexer();
else
Error_Message("Syntax error");
}void display(int t,int tval)
{
if(t=='+'||t=='-'||t=='*'||t=='/')
printf("\nArithmetic Operator: %c",t);
else if(t==NUM)
printf("\n Number: %d",tval);
else if(t==ID)
printf("\n Identifier: %s",symtable[tval].lexptr);
else
printf("\n Token %d tokenval %d",t,tokenval);
}void F()
{
//void E();
switch(lookahead)
{
case '(' : Match('(');
E();
Match(')');
break;
Page No:
T();
display(t,NONE);
continue;
default : return;
}
}
}void parser()
{
lookahead=lexer();
while(lookahead!=DONE)
{
E();
Match(';');
}
}main()
{
char ans[10];
printf("\n Program for recursive decent parsing ");
printf("\n Enter the expression ");
printf("And place ; at the end\n");
printf("Press Ctrl-Z to terminate\n");
parser();
}
Output:
Program for recursive decent parsing
Enter the expression And place ; at the end
Press Ctrl-Z to terminate
a+b*c;
Identifier: a
Identifier: b
Identifier: c
Arithmetic Operator: *
Arithmetic Operator: +
2*3;
Number: 2
Number: 3
Arithmetic Operator: *
+3;
line 5,Syntax error
Ctrl-Z
Page No:
Page No:
Page No:
Page No:
Program 5: Convert The BNF rules into Yacc form and write code to
generate abstract syntax tree.
<int.l>
%{#include"y.tab.h"
#include<stdio.h>
#include<string.h>
int LineNo=1;
%}
identifier [a-zA-Z][_a-zA-Z0-9]*
number [0-9]+|([0-9]*\.[0-9]+)
%%
main\(\) return MAIN;
if
return IF;
else
return ELSE;
while
return WHILE;
int |
char |
float
return TYPE;
{identifier} {strcpy(yylval.var,yytext);
return VAR;}
{number}
{strcpy(yylval.var,yytext);
return NUM;}
\< |
\> |
\>= |
\<= |
==
{strcpy(yylval.var,yytext);
return RELOP;}
[ \t] ;
\n LineNo++;
. return yytext[0];
%%
Page No:
<int.y>
%{
#include<string.h>
#include<stdio.h>
struct quad
{
char
char
char
char
op[5];
arg1[10];
arg2[10];
result[10];
}QUAD[30];
struct stack
{
int items[100];
int top;
}stk;
int Index=0,tIndex=0,StNo,Ind,tInd;
extern int LineNo;
%}
%union
{
char var[10];
}%token <var> NUM VAR RELOP
%token MAIN IF ELSE WHILE TYPE
%type <var> EXPR ASSIGNMENT CONDITION IFST ELSEST WHILELOOP
%left '-' '+'
%left '*' '/'
%%
PROGRAM : MAIN BLOCK
;BLOCK: '{' CODE '}'
;CODE: BLOCK
| STATEMENT CODE
| STATEMENT
;STATEMENT: DESCT ';'
| ASSIGNMENT ';'
| CONDST
| WHILEST
;DESCT: TYPE VARLIST
;VARLIST: VAR ',' VARLIST
| VAR
Page No:
;CONDST: IFST{
Ind=pop();
sprintf(QUAD[Ind].result,"%d",Index);
Ind=pop();
sprintf(QUAD[Ind].result,"%d",Index);
}| IFST ELSEST
;IFST: IF '(' CONDITION ')' {
strcpy(QUAD[Index].op,"==");
strcpy(QUAD[Index].arg1,$3);
strcpy(QUAD[Index].arg2,"FALSE");
strcpy(QUAD[Index].result,"-1");
push(Index);
Index++;
}BLOCK {
strcpy(QUAD[Index].op,"GOTO");
strcpy(QUAD[Index].arg1,"");
strcpy(QUAD[Index].arg2,"");
strcpy(QUAD[Index].result,"-1");
push(Index);
Index++;
};ELSEST: ELSE{
tInd=pop();
Ind=pop();
push(tInd);
sprintf(QUAD[Ind].result,"%d",Index);
}BLOCK{
Ind=pop();
sprintf(QUAD[Ind].result,"%d",Index);
};CONDITION: VAR RELOP VAR {AddQuadruple($2,$1,$3,$$);
StNo=Index-1;
Page No:
}| VAR
| NUM
;
WHILEST: WHILELOOP{
Ind=pop();
sprintf(QUAD[Ind].result,"%d",StNo);
Ind=pop();
sprintf(QUAD[Ind].result,"%d",Index);
}
;WHILELOOP: WHILE '(' CONDITION ')' {
strcpy(QUAD[Index].op,"==");
strcpy(QUAD[Index].arg1,$3);
strcpy(QUAD[Index].arg2,"FALSE");
strcpy(QUAD[Index].result,"-1");
push(Index);
Index++;
}
BLOCK {
strcpy(QUAD[Index].op,"GOTO");
strcpy(QUAD[Index].arg1,"");
strcpy(QUAD[Index].arg2,"");
strcpy(QUAD[Index].result,"-1");
push(Index);
Index++;
}
;
%%
extern FILE *yyin;
int main(int argc,char *argv[])
{
FILE *fp;
int i;
if(argc>1)
{
fp=fopen(argv[1],"r");
if(!fp)
{
printf("\n File not found");
exit(0);
}yyin=fp;
}yyparse();
printf("\n\n\t\t----------------------------""\n\t\t Pos Operator Arg1 Arg2 Result"
"\n\t\t--------------------");
for(i=0;i<Index;i++)
{
Page No:
Page No:
Input:
$vi test.c
main()
{
int a,b,c;
if(a<b)
{
a=a+b;
}while(a<b)
{
a=a+b;
}if(a<=b)
{
c=a-b;
}else
{
c=a+b;
}
}
Output:
$lex int.l
$yacc d int.y
$gcc lex.yy.c y.tab.c ll lm
$./a.out test.c
Pos
0
1
2
3
GOTO
5
5
<
a
b
t2
6
==
t2
FALSE
10
7
+
a
Operator
<
==
+
=
Arg1
a
to
a
t1
Arg2
b
FALSE
b
a
Result
to
5
t1
4
Page No:
}switch(op[0])
{
case '*': fscanf(fp1,"%s %s %s",operand1,operand2,result);
fprintf(fp2,"\n \t LOAD",operand1);
fprintf(fp2,"\n \t LOAD %s,R1",operand2);
fprintf(fp2,"\n \t MUL R1,R0");
fprintf(fp2,"\n \t STORE R0,%s",result);
break;
case '+': fscanf(fp1,"%s %s %s",operand1,operand2,result);
fprintf(fp2,"\n \t LOAD %s,R0",operand1);
fprintf(fp2,"\n \t LOAD %s,R1",operand2);
fprintf(fp2,"\n \t ADD R1,R0");
fprintf(fp2,"\n \t STORE R0,%s",result);
break;
case '-': fscanf(fp1,"%s %s %s",operand1,operand2,result);
fprintf(fp2,"\n \t LOAD %s,R0",operand1);
fprintf(fp2,"\n \t LOAD %s,R1",operand2);
fprintf(fp2,"\n \t SUB R1,R0");
fprintf(fp2,"\n \t STORE R0,%s",result);
break;
case '/': fscanf(fp1,"%s %s %s",operand1,operand2,result);
fprintf(fp2,"\n \t LOAD %s,R0",operand1);
fprintf(fp2,"\n \t LOAD %s,R1",operand2);
fprintf(fp2,"\n \t DIV R1,R0");
fprintf(fp2,"\n \t STORE R0,%s",result);
break;
case '%': fscanf(fp1,"%s %s %s",operand1,operand2,result);
fprintf(fp2,"\n \t LOAD %s,R0",operand1);
fprintf(fp2,"\n \t LOAD %s,R1",operand2);
fprintf(fp2,"\n \t DIV R1,R0");
fprintf(fp2,"\n \t STORE R0,%s",result);
break;
case '=': fscanf(fp1,"%s %s",operand1,result);
fprintf(fp2,"\n\t STORE %s %s",operand1,result);
break;
case '>': j++;
fscanf(fp1,"%s %s %s",operand1,operand2,result);
fprintf(fp2,"\n \t LOAD %s,R0",operand1);
fprintf(fp2,"\n\t JGT %s,label#%s",operand2,result);
label[no++]=atoi(result);
break;
case '<': fscanf(fp1,"%s %s %s",operand1,operand2,result);
fprintf(fp2,"\n \t LOAD %s,R0",operand1);
fprintf(fp2,"\n\t JLT %s,label#%d",operand2,result);
label[no++]=atoi(result);
break;
Page No:
}
}fclose(fp2);
fclose(fp1);
fp2=fopen("target.txt","r");
if(fp2==NULL)
{
printf("Error opening the file\n");
exit(0);
}do
{
ch=fgetc(fp2);
printf("%c",ch);
}while(ch!=EOF);
fclose(fp1);
return 0;
}int check_label(int k)
{
int i;
for(i=0;i<no;i++)
{
if(k==label[i])
return 1;
}return 0;
}
Input:
$vi int.txt
=t1 2
[]=a 0 1 []=a 1 2 []=a 2 3 *t1 6 t2
+a[2] t2 t3
-a[2] t1 t2
/t3 t2 t2
uminus t2 t2
print t2
goto t2 t3
=t3 99
uminus 25 t2
*t2 t3 t3
uminus t1 t1
+t1 t3 t4
print t4
Output:
Page No:
t1,2
a[0],1
a[1],2
a[2],3
LOAD t1,R0
LOAD 6,R1
ADD R1,R0
STORE R0,t3
LOAD a[2],R0
LOAD t2,R1
ADD R1,R0
STORE R0,t3
LOAD a[t2],R0
LOAD t1,R1
SUB R1,R0
STORE R0,t2
LOAD t3,R0
LOAD t2,R1
DIV R1,R0
STORE R0,t2
LOAD t2,R1
STORE R1,t2
LOAD t2,R0
JGT 5,label#11
Label#11: OUT t2
JMP t2,label#13
Label#13: STORE t3,99
LOAD 25,R1
STORE R1,t2
LOAD t2,R0
LOAD t3,R1
MUL R1,R0
STORE R0,t3
LOAD t1,R1
STORE R1,t1
LOAD t1,R0
LOAD t3,R1
ADD R1,R0
STORE R0,t4
OUT t4
Page No: