C PROGRAM TO IMPLEMENT LEXICAL ANALYZER


C PROGRAM TO IMPLEMENT LEXICAL ANALYZER
#include<stdio.h>
#include<ctype.h>
#include<string.h>
void keyw(char *p);
int i=0,id=0,kw=0,num=0,op=0;
char keys[32][10]={"auto","break","case","char","const","continue","default",
"do","double","else","enum","extern","float","for","goto",
"if","int","long","register","return","short","signed",
"sizeof","static","struct","switch","typedef","union",
"unsigned","void","volatile","while"};
main()


    {
     char ch,str[25],seps[15]=" \t\n,;(){}[]#\"<>",oper[]="!%^&*-+=~|.<>/?";
     int j;
     char fname[50];
     FILE *f1;
     //clrscr();
    printf("enter file path (drive:\\fold\\filename)\n");
    scanf("%s",fname);
    f1 = fopen(fname,"r");
    //f1 = fopen("Input","r");
     if(f1==NULL)


         {
          printf("file not found");
          exit(0);
         }
         while((ch=fgetc(f1))!=EOF)


             {
            for(j=0;j<=14;j++)


                {
                if(ch==oper[j])


                    {
                    printf("%c is an operator\n",ch);
                    op++;
                    str[i]='\0';
                    keyw(str);
                }
            }
            for(j=0;j<=14;j++)


                {
                if(i==-1)
                break;
                if(ch==seps[j])


                    {
                    if(ch=='#')


                        {
                        while(ch!='>')


                            {
                            printf("%c",ch);
                            ch=fgetc(f1);
                        }
                        printf("%c is a header file\n",ch);
                        i=-1;
                        break;
                    }
                    if(ch=='"')


                        {
                        do


                            {
                            ch=fgetc(f1);
                            printf("%c",ch);
                        }while(ch!='"');
                        printf("\b is an argument\n");
                        i=-1;
                        break;
                    }
                    str[i]='\0';
                    keyw(str);
                }
            }
            if(i!=-1)


                {
                str[i]=ch;
                i++;
            }
            else
            i=0;
             }
            printf("Keywords: %d\nIdentifiers: %d\nOperators: %d\nNumbers: %d\n",kw,id,op,num);
            //getch();
        }
        void keyw(char *p)


            {
            int k,flag=0;
            for(k=0;k<=31;k++)


                {
                if(strcmp(keys[k],p)==0)


                    {
                    printf("%s is a keyword\n",p);
                    kw++;
                    flag=1;
                    break;
                }
            }
            if(flag==0)


                {
                if(isdigit(p[0]))


                    {
                    printf("%s is a number\n",p);
                    num++;
                }
                else


                    {
                    //if(p[0]!=13&&p[0]!=10)
                    if(p[0]!='\0')


                        {
                        printf("%s is an identifier\n",p);
                        id++;
                    }
                }
            }
            i=-1;
        }
output


23 comments:

  1. thankyou! you are a savior!

    ReplyDelete
  2. code toh chal ta nahi hai bhai kyu uplaod karta hai bsdk

    ReplyDelete
  3. maderchood waaale kaand maar lenge jab program nhi chalta to us program ko kaahe choodne mei jutaa hai. Saaale aagr mil gyaa naa lund thod ke teri hi gaand mei ghused dunga, betichood, bosdik

    ReplyDelete
  4. You really make it look so natural with your exhibition however I discover this issue to be really something which I figure I could never appreciate. It appears to be excessively confounded and amazingly wide for me. I'm searching forward for your next post, I'll attempt to get its hang! situs kimak

    ReplyDelete
  5. Hi I am so charmed I found your blog, I truly found you unintentionally, while I was watching on google for something different, Anyways I am here now and could simply prefer to state thank for a colossal post and an overall engaging site. Kindly keep up the incredible work. situs kontol

    ReplyDelete
  6. Set aside me effort to see the entirety of the remarks, yet I genuinely appreciated the review. It demonstrated being truly useful to me and Im positive to the entirety of the analysts here! Its continually pleasant when you can not exclusively be educated, yet in addition engaged! I am sure you had agreeable composing this review. situs penipu

    ReplyDelete
  7. The material and aggregation is excellent and telltale as comfortably. deriv auto trader

    ReplyDelete
  8. The material and aggregation is excellent and telltale as comfortably. dewibola

    ReplyDelete
  9. The material and aggregation is excellent and telltale as comfortably. دانلود آهنگ شاه از شاهین نجفی

    ReplyDelete
  10. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this.. alexistogel terpercaya

    ReplyDelete
  11. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. togel online terpercaya

    ReplyDelete
  12. 乐鱼体育 ( https://vipleyu.com ) 是全球首家独特综合娱乐平台,将流畅与精湛操作融为一体。从丰富多彩的体育赛事到顶尖电竞比赛,再到真实而刺激的娱乐体验、彩票投注和电子游戏,无一不尽在我们的平台中,尽在您的指尖。只需扫码下载乐鱼体育app,尽享畅快体验,立刻开启!

    而且,在欢乐鱼体育,我们提供业界最高的赔率!不仅覆盖世界各地的精彩赛事,还有多种竞猜选择:从赛果预测、大小猜测、半全场预测,到波胆猜想、单双预测、总入球统计,甚至是连串过关玩法,应有尽有。此外,我们还为您提供动画直播,让您不仅可以轻松畅谈比赛,还能尽情享受娱乐投注的乐趣,一举两得!

    #乐鱼 #乐鱼体育 #乐鱼体育APP #乐鱼体育官网

    ReplyDelete
  13. Cool stuff you have and you keep overhaul every one of us slot gacor

    ReplyDelete
  14. Cool stuff you have and you keep overhaul every one of us rajabandot login alternatif

    ReplyDelete
  15. You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog. Best and quality Inverters in Nigeria

    ReplyDelete
  16. slot online
    I seen your blog post yesterday morning and i also are actually analyzing this item on a normal schedule. You’ve substantial amount of tips correct here so i take pleasure in your thing of an web presence absurdly. Maintain the actual great jobs!

    ReplyDelete
  17. Cashing out small payments is one of the most useful ways to get cash when you need it. However, you should choose a safe company and be careful of excessive fees or illegal activities. Use it with caution. 소액결제현금화

    ReplyDelete
  18. 토닥이는 전용 모바일 앱과 웹사이트를 통해 손쉽게 예약할 수 있습니다. 24시간 실시간 예약 및 상담이 가능하며, 고객의 일정에 맞춘 유연한 서비스 제공으로 바쁜 현대 여성들에게 큰 호응을 얻고 있습니다. 토닥이

    ReplyDelete
  19. You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog. 구리룸싸롱

    ReplyDelete
  20. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. mel bet

    ReplyDelete
  21. Wow i can say that this is another great article as expected of this blog.Bookmarked this site.. وطن گیم

    ReplyDelete
  22. When you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. daftar pas4d

    ReplyDelete
  23. 토닥이는 여성 고객을 위한 프리미엄 마사지 서비스입니다. 스웨디시, 아로마, 타이 마사지 등 다양한 마사지 코스를 안전하고 편안한 여성 전용 환경에서 경험하세요. 토닥이

    ReplyDelete