Help with Lexicon Analyzer

0

Good evening everyone. I'm doing the implementation of a parsing lexicon in c / c ++, but I'm having a problem outputting. I was asked to leave the program only 3 variables and 2 operands, in addition to 1 delimiter and 1 equality.

But I tried everything and I can not do that. If I put to print 3 variables only, the program "eats" one of them. Below is the code I've already done. This analyzer will have to deliver tomorrow, so if anyone can help me I will be really grateful.

#include <stdlib.h> 
#include <string.h> 
#include <iostream> 
#include <iomanip> 
using namespace std; // contexto onde estão definidos macros e variáveis.

int main()
{

char frase[50], support[50];
int u=0,ct11=0,ct10=0,ct9=0,ct8=0,ct7=0,ct6=0,ct5=0,ct4=0 ,ct3=0 ,ct2=0,ct1_1=0,ct1=0,ct13=0,ct12=0,ct14=0,ct15=0,ct16=0,ct11_1=0,ct17=0; 
cout << "Digite a expressao: ";
cin.getline (frase,50) ; 
cout << setw(15) <<"Token" << setw(30) << "Lexema";
 for (int x = 0; x < strlen(frase); x ++){
    if (isalpha(frase[x])) {
            if (islower(frase[x])){
                cout<<"\n Identificador minusculo " << ct1;
                cout<<": \t\t"<< frase[x]; 
                ct1++;
            }
            if (isupper(frase[x])){
                cout<<"\n Identificador maisculo " << ct1_1;
                cout<<": \t\t"<< frase[x]; 
                ct1_1++;
            }

    }else if (isdigit(frase[x])){
        cout<<"\n Numero " << ct2;
        cout<<":\t\t\t\t"<< frase[x]; 
        ct2++;
    }
    else if (isspace(frase[x])) {
         cout<<"\n Espaco " <<ct3;
         cout<<":\t\t\t\t"<< frase[x];
         ct3++;
    }
    else if (frase[x] =='*' && frase[x+1] == '*') {
            frase[x] = '^';
            frase[u] = frase[x];
            frase[x+1] = '.';
            support[ct11] = frase[u];
                 cout<<"\n Potenciacao " <<ct11;
                cout<<":\t\t\t\t"<< support[ct11];
                ct11++;
            }
    else if (frase[x] =='!' && frase[x+1] == '=') {
            frase[x] = '\';
            frase[u] = frase[x];
            frase[x+1] = '.';
            support[ct11_1] = frase[u];
                 cout<<"\n Diferenca " <<ct11_1;
                cout<<":\t\t\t\t"<< support[ct11_1];
                ct11_1++;

            }


    else if (ispunct(frase[x])){
        if (frase[x] == '(' || frase[x] == ')'){
            cout<<"\n Ordem de prioridade 1 " <<ct12;
            cout<<":\t\t"<< frase[x];
            ct12++;
        }
        if (frase[x] == '[' || frase[x] == ']'){
            cout<<"\n Ordem de prioridade 2 " <<ct13;
            cout<<":\t\t"<< frase[x];
            ct13++;
        }
        if (frase[x] == '{' || frase[x] == '}'){
            cout<<"\n Ordem de prioridade 3 " <<ct14;
            cout<<":\t\t"<< frase[x];
            ct14++;
        }
        if (frase[x] == '<'){
            cout<<"\n Menor que " <<ct16;
            cout<<":\t\t\t\t"<< frase[x];
            ct16++;
        }
        if (frase[x] == '>'){
            cout<<"\n Maior que " <<ct17;
            cout<<":\t\t\t\t"<< frase[x];
            ct17++;
        }
        if (frase[x] == '='){
            cout<<"\n Igualdade " <<ct4;
            cout<<":\t\t\t\t"<< frase[x];
            ct4++;
        }
        if (frase[x] == '^'){
            cout<<"\n Potenciacao " <<ct5;
            cout<<":\t\t\t\t"<< frase[x];
            ct5++;
        }
        if (frase[x] == '/'){
            cout<<"\n Operador de divisao " <<ct6;
            cout<<":\t\t\t"<< frase[x];
            ct6++;
        }
        if (frase[x] == '*'){
            cout<<"\n Operador de multiplicaco " <<ct7;
            cout<<":\t\t"<< frase[x];
            ct7++;
        }


        if (frase[x] == '+'){
            cout<<"\n Operador de adicao " <<ct8;
            cout<<":\t\t\t"<< frase[x];
            ct8++;  
        }
        if (frase[x] == '-'){
            cout<<"\n Operador de subtracao " <<ct9;
            cout<<":\t\t"<< frase[x];
            ct9++;  
        }
        if (frase[x] == ';') {
            cout<<"\n Delimitador "<<ct10;
            cout<<":\t\t\t\t"<< frase[x];
            ct10++;
        }
    }   



  }
    cout << '\n';
system("pause");
return 0;
}
    
asked by anonymous 25.09.2015 / 03:02

0 answers