














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING VISION AND MISSION OF THE INSTITUTION
To become self-sustainable institution this is recognized for its new age engineering through innovative teaching and learning culture, inculcating research and entrepreneurial ecosystem, and sustainable social impact in the community.
To offer undergraduate and post-graduate programs that is supported through industry relevant curriculum and innovative teaching and learning processes that would help students succeed in their professional careers. To provide necessary support structures for students, this will contribute to their personal and professional growth and enable them to become leaders in their respective fields. To provide faculty and students with an ecosystem that fosters research and development through strategic partnerships with government organisations and collaboration with industries. To contribute to the development of the region by using our technological expertise to work with nearby communities and support them in their social and economic growth. VISION AND MISSION OF CSE DEPARTMENT
To be recognized as a department of excellence by stimulating a learning environment in which students and faculty will thrive and grow to achieve their professional, institutional and societal goals.
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504
PROGRAM SPECIFIC OUTCOMES(PSOS):
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 Course Objectives To provide hands-on experience on web technologies. To develop client-server application using web technologies To introduce server-side programming with Java servlets and JSP To understand the various phases in the design of a compiler To understand the design of top-down and bottom-up parsers. To understand syntax directed translation schemes. To introduce lex and yacc tools. Course Outcomes CO 1: Design and develop interactive and dynamic web applications using HTML, CSS, JavaScript and XML. CO 2:Analyze thelex and yacc tools for developing a scanner and a parser. CO 3:Design and implement LL and LR parsers. CO 4: Apply client-server principles to develop scalable and enterprise web applications
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO 1 PSO 2 PSO 3 CO1 2 - - 1 - - - - - - - - - - - CO2 2 - - 1 - - - - - - - - 1 - - CO3 (^) 2 1 - 1 - - - - - - - - 1 1 - CO4 2 2 2 1 - - - - - - - - 2 2 1 B.TECH CSE- 3 - 2 COMPILER DESIGN LAB S. No List of Experiments
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 { case ' ': ch=fgetc(fp); break; case '\n': ch=fgetc(fp); break; case '\t': ch=fgetc(fp); break; case '/': ch=fgetc(fp); if(ch=='') { while(1) { ch=fgetc(fp); if(ch=='') { ch=fgetc(fp); if(ch=='/') break; } } } break; case '<': ch=fgetc(fp); if(ch=='=') { token=3; lookahead=0; strcpy(n,"less/equal"); } else { token=2; lookahead=1; strcpy(n,"less"); } break; case '>': ch=fgetc(fp); if(ch=='=') { token=5; lookahead=0; strcpy(n,"greater/equal"); } else { token=4; lookahead=1; strcpy(n,"greater");
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 } break; case '=': ch=fgetc(fp); if(ch=='=') { token=7; lookahead=0; strcpy(n,"equalcomp"); } else { token=2; lookahead=1; strcpy(n,"assign"); } break; case '!': ch=fgetc(fp); if(ch=='=') { token=9; lookahead=0; strcpy(n,"notequal"); } else { token=8; lookahead=1; } break; case '+': token=10; lookahead=0; strcpy(n,"plus"); break; case '-': token=11; lookahead=0; strcpy(n,"minus"); break; case '*': token=12; lookahead=0; strcpy(n,"multiply"); break; case ';': token=13; lookahead=0; strcpy(n,"semicolon"); break; case '{': token=14; lookahead=0;
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 token=-1; } } } return token; } int chkkey() { char *keyw; int flag=0; fseek(kfp,0,SEEK_SET); while(!feof(kfp)) { fscanf(kfp,"%s",keyw); if(strcmp(keyw,iden)==0) { flag=1; break; } } return flag; } OUTPUT: create a file with source.c in that write void main() { int a; }next create another file keyword.txt in that write void main int float char now u will get the output as follows keyword main keyword void 16( leftparanthesis
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504
2. Implement Predictive Parsing algorithm #include<stdio.h> #include<ctype.h> #include<string.h> #include<stdlib.h> #define SIZE 128 #define NONE - 1 #define EOS '\0' #define NUM 257 #define KEYWORD 258 #define ID 259 #define DONE 260 #define MAX 999 charlexemes[MAX]; charbuffer[SIZE]; intlastchar=-1; intlastentry=0; inttokenval=DONE; intlineno=1; intlookahead; structentry { charlexptr; inttoken; } symtable[100]; structentry keywords[]= {"if",KEYWORD,"else",KEYWORD,"for",KEYWORD,"int",KEYWORD,"float",KEYWORD, "double",KEYWORD,"char",KEYWORD,"struct",KEYWORD,"ret urn",KEYWORD,0, }; voidError_Message(charm) { fprintf(stderr,"line %d, %s \n",lineno,m); exit(1);
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 if(t==' '||t=='\t'); elseif(t=='\n') lineno=lineno+1; elseif(isdigit(t)) { ungetc(t,stdin); scanf("%d",&tokenval); returnNUM; } elseif(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) ungetc(t,stdin); val=look_up(buffer); if(val==0) val=insert(buffer,ID); tokenval=val; returnsymtable[val].token; } elseif(t==EOF) returnDONE; else { tokenval=NONE; returnt; } } }
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 voidMatch(intt) { if(lookahead==t) lookahead=lexer(); else Error_Message("Syntax error"); } voiddisplay(intt,inttval) { if(t=='+'||t=='-'||t=='*'||t=='/') printf("\nArithmetic Operator: %c",t); elseif(t==NUM) printf("\n Number: %d",tval); elseif(t==ID) printf("\n Identifier: %s",symtable[tval].lexptr); else printf("\n Token %d tokenval %d",t,tokenval); } voidF() { //void E(); switch(lookahead) { case'(': Match('('); E(); Match(')'); break; caseNUM : display(NUM,tokenval); Match(NUM); break; caseID : display(ID,tokenval); Match(ID); break; default:
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 Match(lookahead); T(); display(t,NONE); continue; case'-': t=lookahead; Match(lookahead); T(); display(t,NONE); continue; default: return; } } } voidparser() { lookahead=lexer(); while(lookahead!=DONE) { E(); Match(';'); } } intmain() { charans[10]; printf("\n Program for recursive descent parsing "); printf("\n Enter the expression "); printf("And place ; at the end\n"); printf("Press Ctrl-Z to terminate\n"); parser();
return0; }
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 Output- Program for recursive descent parsing Enter the expression And place ; at the end Press Ctrl-Z to terminate ab+c; Identifier: a Identifier: b Arithmetic Operator: * Identifier: c Arithmetic Operator: + 57; Number: 5 Number: 7 Arithmetic Operator: * *2; line 5, Syntax error
3. Write a C program to generate three address code. Aim:-To generate three address codes. ALGORITHM: Step1: Begin the program Step2 : The expression is read from the file using a file pointer Step3 : Each string is read and the total no. of strings in the file is calculated. Step4: Each string is compared with an operator; if any operator is seen then the previous string and next string are concatenated and stored in a first temporary value and the three address code expression is printed Step5 : Suppose if another operand is seen then the first temporary value is concatenated to the next string using the operator and the expression is printed. Step6 : The final temporary value is replaced to the left operand value. Step7 : End the program. PROGRAM: //program for three address code generation #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> struct three { char data[10],temp[7]; }s[30]; void main() { char d1[7],d2[7]="t"; int i=0,j=1,len=0; FILE f1,f2; clrscr(); f1=fopen("sum.txt","r"); f2=fopen("out.txt","w"); while(fscanf(f1,"%s",s[len].data)!=EOF)
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504
4. Implement SLR(1) Parsing algorithm. Aim:- To implement SLR() parsing algorithm. ALGORITHM / PROCEDURE : SOURCE CODE : #include<stdio.h> char tab[12][9][2]={"S5","N","N","S4","N","N","1","2","3", "N","S6","N","N","N","Z","0","0","0", "N","R2","S7","N","R2","R2","0","0","0", "N","R4","R4","N","R4","R4","0","0","0", "S5","N","N","S4","N","N","8","2","3", "N","R6","R6","N","R6","R6","0","0","0", "S5","N","N","S4","N","N","0","9","3", "S5","N","N","N","S4","N","0","0","X", "N","S6","N","N","SY","N","0","0","0", "N","R1","S7","N","R1","R1","0","0","0", "N","R3","R3","N","R3","R3","0","0","0", "N","R5","R5","N","R5","R5","0","0","0"}; /Z=accept; N->error; X->10; Y->11;/ char prod[7][4]={"0","E+T","T","TF","F","(E)","d"}; char index[12]={'0','1','2','3','4','5','6','7','8','9','X','Y'}; char term[9]={'d','+','','(',')','$','E','T','F'}; introw,col,st_pt=0,ip_pt=0; char input[10], stack[20]; clrscr(); void main() { intj,k; printf("\n enter input string :"); scanf("%s", input); strcat(input,"$"); stack[0]='0'; for(j=0;j<7;j++) strcat(prod[j],"\0"); printf("\n STACK INPUT \n \n"); while(1) { for(k=0;k<=st_pt; k++) printf("%c", stack[k]); printf(" "); for(k=ip_pt;input[k-1]!='$';k++) printf("%c", input[k]); printf("\n"); row=is_index(stack[st_pt]); col=is_term(input[ip_pt]); if(tab[row][col][0]=='S') shift(tab[row][col][1]); else if(tab[row][col][0]=='R') reduce(tab[row][col][1]);
( Approved by AICTE, New Delhi, Affiliated to JNTUH, Hyderabad ) Chilkur (Village), Moinabad (Mandal), R. R Dist, TS- 501504 else if(tab[row][col][0]=='Z') { printf (" \n success"); getch(); exit(0); } else if(tab[row][col][0]=='N') { printf("\n error"); getch(); exit(0); } } } shift(char ch) { st_pt++; stack[st_pt++]=input[ip_pt++]; stack[st_pt]=ch; } reduce(char ch) { intk,prno,prlen,rowno,colno; for(k=1;k<7;k++) if(index[k]==ch) prno=k; prlen=strlen(prod[prno]); for(k=1;k<=2*prlen;k++) st_pt--; st_pt++; if(prno==1||prno==2) stack[st_pt]='E'; else if(prno==3||prno==4) stack[st_pt]='T'; else if(prno==5||prno==6) stack[st_pt]='F'; rowno=is_index(stack[st_pt-1]); colno=is_term(stack[st_pt]); stack[++st_pt]=tab[rowno][colno][0]; } is_index(char ch) { int k; for (k=0;k<=9;k++) if(index[k]==ch) return(k); if(ch=='X') return(10); else