⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lexico.h

📁 Compiler with latex grammar
💻 H
字号:
#ifndef LEXICO_H
#define LEXICO_H
#include "Tabla_Simbolos.h"

#define ERROR 9
#define SIGNO 1
#define DIGITO 2
#define ENTERO 10
#define REAL 20
#define EXP 30
#define ID 7
/* Rucuteniio necesito q trabajes conestos valores POR FAVOR!!!!CARAJO
#define EX      
#define TXT_IMP
#define DOL 
#define RESERV
#define SQRT
#define FRAC
#define STACKREL
#define OPEN_KEY
#define CLOSE_KEY
#define OPEN_BAR
#define CLOSE_BAR

*/
using namespace std;

class Automata
{
private:
	int contadorLineas;
	Tabla_Simbolos *Tokens;

	bool esSimboloVacio( char ptr )
	{
		return ptr=='\n' || ptr=='\t' || ptr=='\0' || ptr==' ';
	}
	bool esNumero( char ptr )
	{	return (ptr>='0' && ptr<='9') ;	}

	bool esDigito( char a )
	{    return (a>='0' && a<='9'); }
	
	void LimpiarEspaciosBlanco( char *contenido, int &pos, const int tamanyo )
	{
		while( pos<tamanyo )
		{
			if( contenido[pos] == '\n' )
				contadorLineas++;
			if( !esSimboloVacio( contenido[pos] ) )
				break;
			pos++;
		}
	}
	
	bool esLetra( char a )
	{    return (a>='a' && a<='z')||(a>='A'&&a<='Z');   }
	

		
public:
	
	Automata()
	{
		contadorLineas = 0;

		Tokens = new Tabla_Simbolos();
	}
	void Trabajar( char* Contenido )
	{
		int tamanyo = strlen( Contenido );
		int val;
		string tmp="";
		int pos=0;
		
		while( pos < tamanyo )
		{
			if( esSimboloVacio( Contenido[pos]) )
				LimpiarEspaciosBlanco( Contenido, pos, tamanyo );
			if( esDigito(Contenido[pos]) )
			{
				while( pos<tamanyo && esDigito( Contenido[pos] ) && Tokens->esSimbolo_Puntuacion(Contenido[pos]) < 0 && !esSimboloVacio( Contenido[pos] ) )
				{
					tmp += Contenido[pos];
					pos++;
				}
				if( Contenido[pos]=='.' )
				{
					tmp += '.';
					pos++;
					while( pos<tamanyo && esDigito( Contenido[pos] ) )
					{
						tmp += Contenido[pos];
						pos++;
					}
					Tokens->Agregar( tmp, REAL, contadorLineas );
					tmp = "";
					continue;
				}
				Tokens->Agregar( tmp, ENTERO, contadorLineas );
				tmp = "";
				continue;
			}
			if( Contenido[pos]=='\\' )
			{
				tmp +=Contenido[pos++];
				while( pos<tamanyo && esLetra( Contenido[pos] ) )
				{
					tmp += Contenido[pos];
					pos++;
				}
				/*
				if( (val=esPalabra_Reservada( tmp ) < 0)
				{
					Tokens->Agregar( tmp.substr(0,1), val, contadorLineas );
					Tokens->Agregar( tmp.substr(1,tmp.length()), val, contadorLineas );
				}
				else
					Tokens->Agregar( tmp, val, contadorLineas );
				*/
				Tokens->Agregar( tmp, Tokens->esPalabra_Reservada( tmp ), contadorLineas );
				tmp = "";
				continue;
			}
			if( esLetra(Contenido[pos] ) )
			{
				while( pos<tamanyo && esLetra( Contenido[pos] ) )
				{
					tmp += Contenido[pos];
					pos++;
				}
				Tokens->Agregar( tmp, ID, contadorLineas );
				tmp = "";
				continue;
			}
			if( (val=Tokens->esSimbolo_Puntuacion(Contenido[pos])) >= 0 )
			{
				tmp+=Contenido[pos++];
				Tokens->Agregar( tmp, val, contadorLineas );
				tmp = "";
				continue;
			}
			/*else
			{
				GENERAR UN ERRROR EN ESTE PUNTO
			}*/
		}
	}
/*
	Tabla_Simbolos* getTabla_Simbolos()
	{
		return this->Tokens;
	}*/
	void Imprimir()
	{
		Tokens->Imprimir();
	}
};
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -