Question:

Token separation source code in c?

by Guest117  |  earlier

0 LIKES UnLike

 Tags:

   Report

1 ANSWERS


  1. #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    #include<iostream.h>

    int key = 0;
    char expr[100];
    char cont[][20]={"CONTROLS","for","do","while","NULL",};
    char cond[][20]={"CONDITION","if","then","NULL"};
    char oprt[][20]={"OPERATOR","+","-","*","/","%","<","<=",">",">=","=","(",")","NULL"};
    char branch[][20]={"BRANCHING","goto","jump" ,"NULL"};
    void checking(char[],char[][20]);
    void main()
    {
    int i,j,l,k,m,n;
    char sbexpr[50],txt[3];
    clrscr();
    cout<<"Enter the expression:";
    gets(expr);
    for(i=0;expr[i]!=NULL;i++)
    {
    key=0;
    for(j=i,k=0;expr[j]!=32 && expr[j]!=NULL;i++,j++,k++)
    sbexpr[k]=expr[j];
    sbexpr[k]=NULL;
    if(key==0) checking(sbexpr,cond);
    if(key==0) checking(sbexpr,cont);
    if(key==0) checking(sbexpr,branch);
    if(key==0)
    {
    for(m=0;sbexpr[m]!=NULL;m++)
    {
    key=0;
    txt[0]= sbexpr[m];
    txt[1] = NULL;
    if(key==0) checking(txt,oprt);
    if((key==0) || ((sbexpr[m]>=97 && sbexpr[m]<=122) || (sbexpr[m]>=65 && sbexpr[m]<=90)))
    {
    cout<<"\n"<<sbexpr[m]<<"------->"<<"Identifier\n";
    key = 1;
    }
    }
    }
    if(key == 0)
    {
    cout<<"\n"<<sbexpr<<"------->"<<"Address\n";
    key = 1;
    }
    }

    getch();
    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.