Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- FILE *fp;
- void scan();
- void error();
- void retcheck();
- void name();
- void param();
- int main()
- {
- fp=fopen("newinput.txt","r+");
- scan();
- }
- void scan()
- {
- char ch;
- ch=fgetc(fp);
- if((ch>=65&&ch<=90)||(ch>=97&&ch<=122))
- {
- retcheck();
- }
- else
- {
- error();
- }
- }
- void error()
- {
- printf("\n Error in prototype declaration ");
- fclose(fp);
- }
- void retcheck()
- {
- fseek(fp,-1,SEEK_CUR);
- char ch;
- ch=fgetc(fp);
- if(ch=='i')
- {
- ch=fgetc(fp);
- if(ch=='n')
- {
- ch=fgetc(fp);
- if(ch=='t')
- {
- printf("\n Return Type is int ");
- name();
- }
- else
- {
- error();
- }
- }
- else
- {
- error();
- }
- }
- else if(ch=='f')
- {
- ch=fgetc(fp);
- if(ch=='l')
- {
- ch=fgetc(fp);
- if(ch=='o')
- {
- ch=fgetc(fp);
- if(ch=='a')
- {
- ch=fgetc(fp);
- if(ch=='t')
- {
- printf("\n The return type is float \n");
- name();
- }
- else
- {
- error();
- }
- }
- else
- error();
- }
- else
- error();
- }
- else
- error();
- }
- else if(ch=='s')
- {
- ch=fgetc(fp);
- if(ch=='t')
- {
- ch=fgetc(fp);
- if(ch=='r')
- {
- ch=fgetc(fp);
- if(ch=='u')
- {
- ch=fgetc(fp);
- if(ch=='c')
- {
- ch=fgetc(fp);
- if(ch=='t')
- {
- printf("\n The return type is struct ");
- name();
- }
- else
- {
- error();
- }
- }
- else
- error();
- }
- else
- error();
- }
- else
- error();
- }
- else
- error();
- }
- else
- {
- error();
- }
- }
- void name()
- {
- char ident[10],ch;
- int i=0;
- ch=fgetc(fp);
- if(ch==' '||ch=='\t')
- {
- do
- {
- ident[i]=ch;
- ++i;
- ch=fgetc(fp);
- }while((ch>=65 && ch<=90)||(ch>=97 & ch<=122)||(ch>=48 & ch<=57)); //keep scanning
- ident[i]='\0';
- }
- else
- {
- error();
- }
- printf("\n %s is the function name ",ident);
- fseek(fp,-1,SEEK_CUR);
- param();
- }
- void param()
- {
- char ch;
- ch=fgetc(fp);
- if(ch=='(')
- {
- }
- else
- error();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement