Exemplo n.º 1
0
int Anasin::Sentencia(){
	Lexema nextLexema = this->_symTab->lookAheadLexema();
	if(nextLexema._tipo == "Id"){
		// 02) Sentencia ->	Operacion Sentencia 
		if(!Operacion()) return 0;
		if(!Sentencia()) return 0;
	}else if(nextLexema._tipo == "Output"){
		// 04) Sentencia ->	Impresión Sentencia
		if(!Impresion()) return 0;
		if(!Sentencia()) return 0;
	}else if(nextLexema._tipo == "Reserved" && (nextLexema._valor == "while" || nextLexema._valor == "if")){
		// 01) Sentencia ->	EControl Sentencia
		if(!EControl()) return 0;
		if(!Sentencia()) return 0;	
	}else if(nextLexema._tipo == "Reserved" && (nextLexema._valor == "arr" || nextLexema._valor == "count")){
		// 03) Sentencia ->	Declaracion Sentencia
		if(!Declaracion()) return 0;
		if(!Sentencia()) return 0;
	}else if(nextLexema._tipo == "Agrupation" && nextLexema._valor == "}"){
		// Es la derivación a nada
	}else if(nextLexema._tipo == "$"){
		// Ya terminé :)
	}else{
		std::cout << "Error sintáctico, se esperaba : Id,},output,while,if,arr,count,$ y se obtuvo: " << nextLexema._tipo << " ("<< nextLexema._valor <<")["<< this->_symTab->getOffset() <<"]" << std::endl;
		return 0;
	}
	return 1;
}
Exemplo n.º 2
0
ArbolSA* Lista_Prototipos_Reservados()
{
	ArbolSA* actual, *actual_tipo, *actual_nombre, *actual_parametros, *actual_declaracion;

	if (Prototipos_Reservados==NULL)
	{
	  Prototipos_Reservados=Lista_Prototipos_Vacia();

	  /* void WriteI(integer e); */
	  actual_tipo = Tipo_Nulo();
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("WriteI");
	  actual_declaracion = Declaracion(Crear_Tipo(_TIPO_ENTERO),Ident(),Expr_Nula());
      Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("e");
	  actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion));
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);

	  /* void WriteR(real r); */
	  actual_tipo = Tipo_Nulo();
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("WriteR");
	  actual_declaracion = Declaracion(Crear_Tipo(_TIPO_REAL),Ident(),Expr_Nula());
      Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("r");
	  actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion));
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);

	  /* void WriteC(character c); */
	  actual_tipo = Tipo_Nulo();
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("WriteC");
	  actual_declaracion = Declaracion(Crear_Tipo(_TIPO_CARACTER),Ident(),Expr_Nula());
      Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("c");
	  actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion));
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);

	  /* void WriteS(string s); */
	  actual_tipo = Tipo_Nulo();
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("WriteS");
	  actual_declaracion = Declaracion(Crear_Tipo(_TIPO_CADENA),Ident(),Expr_Nula());
      Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("s");
	  actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion));
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);

	  /* void WriteL(boolean l); */
	  actual_tipo = Tipo_Nulo();
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("WriteL");
	  actual_declaracion = Declaracion(Crear_Tipo(_TIPO_LOGICO),Ident(),Expr_Nula());
      Ident_Info_Lex(Declaracion_nombre(actual_declaracion)) = String2Lex("l");
	  actual_parametros = Lista_Parametros(Lista_Parametros_Vacia(),Parametro(Solo_Lectura(),actual_declaracion));
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);



	  /* integer ReadI(); */
	  actual_tipo = Crear_Tipo(_TIPO_ENTERO);
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("ReadI");
	  actual_parametros = Lista_Parametros_Vacia();
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);
	  /* real ReadR(); */
	  actual_tipo = Crear_Tipo(_TIPO_REAL);
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("ReadR");
	  actual_parametros = Lista_Parametros_Vacia();
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);
	  /* character ReadC(); */
	  actual_tipo = Crear_Tipo(_TIPO_CARACTER);
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("ReadC");
	  actual_parametros = Lista_Parametros_Vacia();
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);
	  /* string ReadS(); */
	  actual_tipo = Crear_Tipo(_TIPO_CADENA);
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("ReadS");
	  actual_parametros = Lista_Parametros_Vacia();
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);
	  /* boolean ReadL(); */
	  actual_tipo = Crear_Tipo(_TIPO_LOGICO);
	  actual_nombre = Ident();
      Ident_Info_Lex(actual_nombre) = String2Lex("ReadB");
	  actual_parametros = Lista_Parametros_Vacia();
	  actual = Prototipo(actual_tipo, actual_nombre, actual_parametros);
	  Prototipos_Reservados=Lista_Prototipos(Prototipos_Reservados,actual);
	};

   return Prototipos_Reservados;
};