5th Sem SS lab progs

download 5th Sem SS lab progs

If you can't read please download the document

description

5th Sem SS lab programs

Transcript of 5th Sem SS lab progs

  • 1. SS &os Progs 1a %{ #include int sc=0,lc=0,wc=0,cc=0; %} %% [^ t n]+ {wc++;cc+=yyleng;} n {lc++;} " " {sc++;} .; %% yywrap() { return 1; } main() { yyin=fopen("nag.txt","r"); yylex(); fclose(yyin); printf("character count=%dn",cc); printf("word count=%dn",wc); printf("space count=%dn",sc); printf("line count=%dn",lc); } ============================output================================== nag.txt ------nagarjun atria coll 5th sem lex lab student ------------------------------------------------------------------yadavakings@ubuntu:~$ vi 1a.l yadavakings@ubuntu:~$ lex 1a.l yadavakings@ubuntu:~$ cc lex.yy.c yadavakings@ubuntu:~$ ./a.out character count=36 word count=8 space count=3 line count=51b. Nagarjun.E, Atria institute of echnology,Ananadnagar-24Page 24

2. %{ #include int flag=0,n=0,cmt=0; %} %% "//".* {cmt++;} "/*".*"*/" {cmt++;} "/*".* {flag=1;n++;} "n" {if (flag==1)n++;else echo;} .*"*/"{if(flag==1) {cmt+=n;flag=0;n=0;}} . {if (flag==0)ECHO;} %% yywrap() { return 1; } main() { yyin=fopen("nag.c","r"); yyout=fopen("out.txt","w"); yylex(); fclose(yyin); fclose(yyout); printf("number of comment lines= %d",cmt); } =============================output========================================== ========== nag.c ---#include //nagarjun /*atria collstudent*/ /*5th sem*/ int a,b,c; a=b+c; -------------------------------------------------------------------------yadavakings@ubuntu:~$ vi 1b.l yadavakings@ubuntu:~$ lex 1b.l yadavakings@ubuntu:~$ cc lex.yy.c yadavakings@ubuntu:~$ ./a.out number of comment lines= 3 out.txt ------#include int a,b,c; a=b+c;2a. Nagarjun.E, Atria institute of echnology,Ananadnagar-24Page 24 3. %{#include int id=0,op=0,bc=0,i=0,j=0,x,flag=0; char opa[10]; int ida[10];%} %% "(" {bc++;flag=1;} ")" {if(flag==1) {bc--;flag=0;} else bc--;} "+"|"-"|"*"|"/" {op++;opa[i++]=*yytext;} [0-9]+ {id++;ida[j++]=atoi(yytext);} . ; %% yywrap() { return 1; } main() { printf("enter the expression"); yylex(); if((flag!=0)||(bcfile2 if cmp file1 file2 then echo "common permissions" else echo "different permissions" echo "$1 permissions" cat file1 echo "$2 permissions"Nagarjun.E, Atria institute of echnology,Ananadnagar-24Page 24 13. cat file2 fi ================================output============================== yadavakings@ubuntu:~$ vi 8a.sh yadavakings@ubuntu:~$ sh 8a.sh common permissions yadavakings@ubuntu:~$ chmod 222 file2 yadavakings@ubuntu:~$ sh 8a.sh cmp: file2: Permission denied different permissions permissions total 100 -rwx------rw-------rwx------rw-------rw-r--r--rw-r--r--rw-------rw-r--r--rw-r--r--rw-r--r--rw-------rw-------rwxr-xr-x drwxr-xr-x drwxr-xr-x -rw-r--r--rwxrwxrwx --w--w--wdrwxr-xr-x -rw-r--r--rw-r--r--rw-r--r-drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x permissions cat: file2: Permission denied8b. #include #include #include #include int main() { char *cmd = "vi 8b.txt"; char *fname = "8b.txt";Nagarjun.E, Atria institute of echnology,Ananadnagar-24Page 24 14. char *s1 = "ABCDEFGHIJKLMNOP"; char *s2 = "abcdefghijklmnop"; int fd; fd = creat(fname, s.IREAD | s.IWRITE); if(fd==-1) { printf("error in file"); exit(1); } if(write(fd,s1,16)!=16) printf("error"); lseek(fd,48,SEEK_SET); if(write(fd,s2,16)!=16) { printf("error"); } printf("contents of the file aren"); system(cmd); } ====================================output=================================== ===== yadavakings@ubuntu:~$ vi 8b.c yadavakings@ubuntu:~$ cc 8b.c 8b.c: In function main: 8b.c:12: error: s undeclared (first use in this function) 8b.c:12: error: (Each undeclared identifier is reported only once 8b.c:12: error: for each function it appears in.) sorry no output for this..... check and text me....!9a. for i do { echo "echo $i" echo "cat>$iout.sh yadavakings@ubuntu:~$ cat out.sh echo 1.txt cat>1.txt2.txt1.txt2.txt #include #include #include int main() { pid_t ppid,mpid,pid,status=0; pid=fork(); if(pid10 p2->10 p3->10 p4->5 p5->10 p1->5 p2->10 p3->10 p5->10 p2->5Nagarjun.E, Atria institute of echnology,Ananadnagar-24Page 24 18. p3->10 total estimated time10.sjrf #include struct proc { int id, arrival,burst,rem,wait,finish,turnaround; float ratio; } process[10]; struct proc temp; int no; int chkprocess(int); int nextprocess(); void srtf(int); main() { int n; printf("nn enter the number of the processes");Nagarjun.E, Atria institute of echnology,Ananadnagar-24Page 24 19. scanf("%d",&n); srtf(n); } int chkprocess(int s) { int i; for(i=1;i