miércoles, 13 de enero de 2010

continua lexico

["< rt = TOKEN_INVALIDO;
}

else if(estado == 1) // identificador o constante
{
strcpy(tmp_sim.token,ttok);
tmp_sim.tipo = VARIABLE;

if( ttok[0]=='$') // es variable
{
tmp_sim.id = ID_SIMBOLOS + idSimb;
rt = IDENTIFICADOR;

if(BuscarSimbolo(ttok)==TOKEN_NO_ENCONTRADO )
{
InsertarSimbolo(ttok,tmp_sim.id,VARIABLE);
idSimb++;
}
}
else
{
rt=IDReserv(ttok);

if(rt != TOKEN_NO_ENCONTRADO)
{
tmp_sim.id = rt;
rt = RESERVADA;
}
else
{
tmp_sim.id = ID_SIMBOLOS + idSimb;
rt = CONST_SIMB;
}

if(BuscarSimbolo(ttok)==TOKEN_NO_ENCONTRADO )
{
InsertarSimbolo(ttok,tmp_sim.id,VARIABLE);
idSimb++;
}
}
}

else if( estado==2 || estado==3 || estado==5) rt=CONSTANTE;

else if( estado==4 ) rt=REAL;

strcpy(token,ttok);

break;
}
}

else // caracter raro
{
ttok[ j++ ] = buffer[ i ];
ttok[ j ] = '\0';
estado = 6;
}
}

Bufpos = i-1;

return rt;
}

int BuscarSimbolo(char* token) // regresa el id del simbolo si lo encuentra
{
int i;

for(i=0;i<=simCont;i++)
if( strcmp(tablaSimb[i].token,token)==0) return tablaSimb[i].id;

return TOKEN_NO_ENCONTRADO;
}

int IDReserv(char* token)
{
int i = 0;

for(;i
return TOKEN_NO_ENCONTRADO;
}

int IDOperador( char* token )// regresa el id del operador encaso de encontrarlo
{
int i = 0;

for(;i if(strcmp(Operadores[ i ],token)==0) return i + ID_OPERADORES;

return TOKEN_NO_ENCONTRADO;
}

int InsertarSimbolo(char* token, int id, int tipo)
{
simCont++;

strcpy(tablaSimb[simCont].token,token);
tablaSimb[simCont].id = id;
tablaSimb[simCont].tipo = tipo;

return 0;
}

int ModificaTipo(char* token, int tipo)
{
int i = 0;

for(i=0;i<=simCont;i++)
{
if( strcmp(tablaSimb[i].token,token)==0)
{
tablaSimb[i].tipo = tipo;
return tablaSimb[i].id;
}
}

return TOKEN_NO_ENCONTRADO;
}

int ObtieneTipo(char* token)
{
int i = 0;

for(;i<=simCont;i++)
if( strcmp(tablaSimb[i].token,token)==0) return tablaSimb[i].tipo;

return TOKEN_NO_ENCONTRADO;
}

No hay comentarios:

Publicar un comentario