Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <cstdlib>
- #include <string.h>
- using namespace std;
- class Codigo
- {
- char * codigo;
- public:
- Codigo(char * codigo)
- {
- this -> codigo = codigo;
- }
- void analizador()
- {
- char * token;
- char * espacio = " ";
- char * sig = NULL;
- token = strtok_s(codigo, espacio, &sig);
- cout << "\nTokens\t\tSignificado\n";
- while(token)
- {
- if(!esNumero(token))
- {
- if(!esOtro(token))
- {
- cout << token << "\t\t" << "error\n";
- }
- }
- token = strtok_s(NULL, espacio, &sig);
- }
- }
- bool esNumero(char * tok)
- {
- bool ind = true;
- for(int i = 0; tok[i] && ind; i++)
- {
- if(tok[i] != '!')
- ind = false;
- }
- if(ind)
- cout << tok << "\t\t" << "numero\n";
- return ind;
- }
- bool esOtro(char * tok)
- {
- char * tokens[3] = {"con", "sin", "es"};
- char * signif[3] = {"operador +", "operador -", "delimitador"};
- int p = 0;
- bool ind = false;
- while(p < 3 && !ind)
- {
- if(!strcmp(tok, tokens[p]))
- {
- cout << tok << "\t\t" << signif[p] << endl;
- ind = true;
- }
- p++;
- }
- return ind;
- }
- ~Codigo(void)
- {
- }
- };
Add Comment
Please, Sign In to add comment