コード例 #1
0
ファイル: pdr_parse.c プロジェクト: ManfredHerrmann/proview
static void
def_program(definition *defp)
{
	token tok;
	version_list *vlist;
	version_list **vtailp;
	proc_list *plist;
	proc_list **ptailp;

	defp->def_kind = DEF_PROGRAM;
	scan(TOK_IDENT, &tok);
	defp->def_name = tok.str;
	scan(TOK_LBRACE, &tok);
	vtailp = &defp->def.pr.versions;
	scan(TOK_VERSION, &tok);
	do {
		scan(TOK_IDENT, &tok);
		vlist = ALLOC(version_list);
		vlist->vers_name = tok.str;
		scan(TOK_LBRACE, &tok);
		ptailp = &vlist->procs;
		do {
			plist = ALLOC(proc_list);
			plist->next = NULL;
			get_type(&plist->res_prefix, &plist->res_type, DEF_PROGRAM);
			if (streq(plist->res_type, "opaque")) {
				error("illegal result type");
			}
			scan(TOK_IDENT, &tok);
			plist->proc_name = tok.str;
			scan(TOK_LPAREN, &tok);
			get_type(&plist->arg_prefix, &plist->arg_type, DEF_PROGRAM);
			if (streq(plist->arg_type, "opaque")) {
				error("illegal argument type");
			}
			scan(TOK_RPAREN, &tok);
			scan(TOK_EQUAL, &tok);
			scan_num(&tok);
			scan(TOK_SEMICOLON, &tok);
			plist->proc_num = tok.str;
			*ptailp = plist;
			ptailp = &plist->next;
			peek(&tok);
		} while (tok.kind != TOK_RBRACE);
		*vtailp = vlist;
		vtailp = &vlist->next;
		scan(TOK_RBRACE, &tok);
		scan(TOK_EQUAL, &tok);
		scan_num(&tok);
		vlist->vers_num = tok.str;
		scan(TOK_SEMICOLON, &tok);
		scan2(TOK_VERSION, TOK_RBRACE, &tok);
	} while (tok.kind == TOK_VERSION);
	scan(TOK_EQUAL, &tok);
	scan_num(&tok);
	defp->def.pr.prog_num = tok.str;
	*vtailp = NULL;
}
コード例 #2
0
static void
get_declaration(declaration *dec, defkind dkind)
{
	token tok;

	get_type(&dec->prefix, &dec->type, dkind);
	dec->rel = REL_ALIAS;
	if (streq(dec->type, "void")) {
		return;
	}

	check_type_name(dec->type, 0);
	scan2(TOK_STAR, TOK_IDENT, &tok);
	if (tok.kind == TOK_STAR) {
		dec->rel = REL_POINTER;
		scan(TOK_IDENT, &tok);
	}
	dec->name = tok.str;
	if (peekscan(TOK_LBRACKET, &tok)) {
		if (dec->rel == REL_POINTER) {
			error("no array-of-pointer declarations -- use typedef");
		}
		dec->rel = REL_VECTOR;
		scan_num(&tok);
		dec->array_max = tok.str;
		scan(TOK_RBRACKET, &tok);
	} else if (peekscan(TOK_LANGLE, &tok)) {
		if (dec->rel == REL_POINTER) {
			error("no array-of-pointer declarations -- use typedef");
		}
		dec->rel = REL_ARRAY;
		if (peekscan(TOK_RANGLE, &tok)) {
			dec->array_max = "~0";	/* unspecified size, use max */
		} else {
			scan_num(&tok);
			dec->array_max = tok.str;
			scan(TOK_RANGLE, &tok);
		}
	}
	if (streq(dec->type, "opaque")) {
		if (dec->rel != REL_ARRAY && dec->rel != REL_VECTOR) {
			error("array declaration expected");
		}
	} else if (streq(dec->type, "string")) {
		if (dec->rel != REL_ARRAY) {
			error("variable-length array declaration expected");
		}
	}
}
コード例 #3
0
ファイル: rpc_parse.c プロジェクト: Lind-Project/Lind-GlibC
static void
def_enum (definition * defp)
{
  token tok;
  enumval_list *elist;
  enumval_list **tailp;

  defp->def_kind = DEF_ENUM;
  scan (TOK_IDENT, &tok);
  defp->def_name = tok.str;
  scan (TOK_LBRACE, &tok);
  tailp = &defp->def.en.vals;
  do
    {
      scan (TOK_IDENT, &tok);
      elist = ALLOC (enumval_list);
      elist->name = tok.str;
      elist->assignment = NULL;
      scan3 (TOK_COMMA, TOK_RBRACE, TOK_EQUAL, &tok);
      if (tok.kind == TOK_EQUAL)
	{
	  scan_num (&tok);
	  elist->assignment = tok.str;
	  scan2 (TOK_COMMA, TOK_RBRACE, &tok);
	}
      *tailp = elist;
      tailp = &elist->next;
    }
  while (tok.kind != TOK_RBRACE);
  *tailp = NULL;
}
コード例 #4
0
//TODO: ADD ERROR LINE
static void output_func_wait_for_option(fsm_t* fsm){
	int option = -1;
	nevera_fsm_t* nevera = (nevera_fsm_t*) fsm;
	display_options_menu();
	while(1){
		option = scan_num();
		if(option > 0 && option < 5){
			break;
		}
		display_options_error();
		display_options_menu();
	}

	nevera->option_selected = option;
}
コード例 #5
0
//OUTPUT FUNCTIONS
//TODO: SCAN_CHAIN NO BORRA
static void output_func_wait_for_user(fsm_t* fsm){
		nevera_fsm_t* nevera = (nevera_fsm_t*) fsm;
		int id = 0;
		while(1){
			display_user_menu();
			id = scan_num();
			nevera->user_selected = usuario_list_search(nevera->lista_usuarios,id);
			if(nevera->user_selected != NULL)
				break;
			display_user_error();
		}
		nevera->option_selected = -1;
		nevera->intro = "";
		display_user_selected(nevera->user_selected->nombre);
}
コード例 #6
0
ファイル: flatten.c プロジェクト: OS2World/APP-EDITOR-Flatten
static const char *skim_char(const char *from, int *to)
	{
	if ( *from == TERM )
		{
		*to = DELIM;
		from++;
		}
	else if ( *from != '\\' )
		*to = *from++;
	else
		{
		unsigned ch;
		from = scan_num(++from, &ch) + 1;
		*to = (int) ch;
		}
	return from;
	}
コード例 #7
0
ファイル: rpc_parse.c プロジェクト: Lind-Project/Lind-GlibC
static void
get_prog_declaration (declaration * dec, defkind dkind, int num /* arg number */ )
{
  token tok;
  char name[10];		/* argument name */

  if (dkind == DEF_PROGRAM)
    {
      peek (&tok);
      if (tok.kind == TOK_RPAREN)
	{			/* no arguments */
	  dec->rel = REL_ALIAS;
	  dec->type = "void";
	  dec->prefix = NULL;
	  dec->name = NULL;
	  return;
	}
    }
  get_type (&dec->prefix, &dec->type, dkind);
  dec->rel = REL_ALIAS;
  if (peekscan (TOK_IDENT, &tok))	/* optional name of argument */
    strcpy (name, tok.str);
  else
    sprintf (name, "%s%d", ARGNAME, num);	/* default name of argument */

  dec->name = (char *) strdup (name);

  if (streq (dec->type, "void"))
    {
      return;
    }

  if (streq (dec->type, "opaque"))
    {
      error ("opaque -- illegal argument type");
    }
  if (peekscan (TOK_STAR, &tok))
    {
      if (streq (dec->type, "string"))
	{
	  error ("pointer to string not allowed in program arguments\n");
	}
      dec->rel = REL_POINTER;
      if (peekscan (TOK_IDENT, &tok))	/* optional name of argument */
	dec->name = strdup (tok.str);
    }
  if (peekscan (TOK_LANGLE, &tok))
    {
      if (!streq (dec->type, "string"))
	{
	  error ("arrays cannot be declared as arguments to procedures -- use typedef");
	}
      dec->rel = REL_ARRAY;
      if (peekscan (TOK_RANGLE, &tok))
	{
	  dec->array_max = "~0";	/* unspecified size, use max */
	}
      else
	{
	  scan_num (&tok);
	  dec->array_max = tok.str;
	  scan (TOK_RANGLE, &tok);
	}
    }
  if (streq (dec->type, "string"))
    {
      if (dec->rel != REL_ARRAY)
	{			/* .x specifies just string as
				 * type of argument
				 * - make it string<>
				 */
	  dec->rel = REL_ARRAY;
	  dec->array_max = "~0";	/* unspecified size, use max */
	}
    }
}
コード例 #8
0
ファイル: rpc_parse.c プロジェクト: Lind-Project/Lind-GlibC
static void
def_program (definition * defp)
{
  token tok;
  declaration dec;
  decl_list *decls;
  decl_list **tailp;
  version_list *vlist;
  version_list **vtailp;
  proc_list *plist;
  proc_list **ptailp;
  int num_args;
  bool_t isvoid = FALSE;	/* whether first argument is void */
  defp->def_kind = DEF_PROGRAM;
  scan (TOK_IDENT, &tok);
  defp->def_name = tok.str;
  scan (TOK_LBRACE, &tok);
  vtailp = &defp->def.pr.versions;
  tailp = &defp->def.st.decls;
  scan (TOK_VERSION, &tok);
  do
    {
      scan (TOK_IDENT, &tok);
      vlist = ALLOC (version_list);
      vlist->vers_name = tok.str;
      scan (TOK_LBRACE, &tok);
      ptailp = &vlist->procs;
      do
	{
	  /* get result type */
	  plist = ALLOC (proc_list);
	  get_type (&plist->res_prefix, &plist->res_type,
		    DEF_PROGRAM);
	  if (streq (plist->res_type, "opaque"))
	    {
	      error ("illegal result type");
	    }
	  scan (TOK_IDENT, &tok);
	  plist->proc_name = tok.str;
	  scan (TOK_LPAREN, &tok);
	  /* get args - first one */
	  num_args = 1;
	  isvoid = FALSE;
	  /* type of DEF_PROGRAM in the first
	   * get_prog_declaration and DEF_STURCT in the next
	   * allows void as argument if it is the only argument
	   */
	  get_prog_declaration (&dec, DEF_PROGRAM, num_args);
	  if (streq (dec.type, "void"))
	    isvoid = TRUE;
	  decls = ALLOC (decl_list);
	  plist->args.decls = decls;
	  decls->decl = dec;
	  tailp = &decls->next;
	  /* get args */
	  while (peekscan (TOK_COMMA, &tok))
	    {
	      num_args++;
	      get_prog_declaration (&dec, DEF_STRUCT,
				    num_args);
	      decls = ALLOC (decl_list);
	      decls->decl = dec;
	      *tailp = decls;
	      if (streq (dec.type, "void"))
		isvoid = TRUE;
	      tailp = &decls->next;
	    }
	  /* multiple arguments are only allowed in newstyle */
	  if (!newstyle && num_args > 1)
	    {
	      error ("only one argument is allowed");
	    }
	  if (isvoid && num_args > 1)
	    {
	      error ("illegal use of void in program definition");
	    }
	  *tailp = NULL;
	  scan (TOK_RPAREN, &tok);
	  scan (TOK_EQUAL, &tok);
	  scan_num (&tok);
	  scan (TOK_SEMICOLON, &tok);
	  plist->proc_num = tok.str;
	  plist->arg_num = num_args;
	  *ptailp = plist;
	  ptailp = &plist->next;
	  peek (&tok);
	}
      while (tok.kind != TOK_RBRACE);
      *ptailp = NULL;
      *vtailp = vlist;
      vtailp = &vlist->next;
      scan (TOK_RBRACE, &tok);
      scan (TOK_EQUAL, &tok);
      scan_num (&tok);
      vlist->vers_num = tok.str;
      /* make the argument structure name for each arg */
      for (plist = vlist->procs; plist != NULL;
	   plist = plist->next)
	{
	  plist->args.argname = make_argname (plist->proc_name,
					      vlist->vers_num);
	  /* free the memory ?? */
	}
      scan (TOK_SEMICOLON, &tok);
      scan2 (TOK_VERSION, TOK_RBRACE, &tok);
    }
  while (tok.kind == TOK_VERSION);
  scan (TOK_EQUAL, &tok);
  scan_num (&tok);
  defp->def.pr.prog_num = tok.str;
  *vtailp = NULL;
}
コード例 #9
0
ファイル: flatten.c プロジェクト: OS2World/APP-EDITOR-Flatten
static const char *skim_num(const char *from, unsigned *to)
	{
	return scan_num(from, to) + 1;
	}
コード例 #10
0
int main()
{
    /// INICIO DE VARIASBLES.
    int number1 = 0;
    int number2 = 0;
    int result;
    // variables  validacion de carga de datos.
    int flag1 = 0;
    int flag2 = 0;

    // variable para seleccion de operacion a realizar.
    int option = 0;

   // variable para nimeros complejos cco los resultados de la devisio
    float divisionResult;

    //bloque de codigo que encierra la presentacion de pnes de usuario y el bloque de pciones.
    do
    {
    system("cls");

    ///Panel opciones para el usuario.
    printf("**************(((CALCULATOR 1.0 (TP) NRO 1   Matias.H.Alvarez)))****************");

    printf("\n\nElija entre las siguientes operaciones.\n\n\n");

    printf("[1]INGRESO EL PRIMER VALOR A CALCULAR :\n\n");
    printf("[2]INGRESE EL SEGUNDO VALOR A CALCULAR :");
    TOLBAR

    printf("\nValor actual PRIMERO :%d\n",number1);
    printf("\nValor actual SEGUNDO :%d",number2);
    TOL

    printf("\n[3]SUMA.");
    printf("[4]RESTA.");
    TOL


    printf("\n[5]MUTIPLICACION.");
    printf("[6]DIVISION.");
    TOL


    printf("\n[7]FACTORIAL");
    TOL


    printf("\n[8]TODOS LOS CALCULOS EN UNO");
    TOL

    printf("\n\n\nO ingrese ((9 para SALIR)) del programa.\t//_:");
    scanf("%d",& option);

    ///bloque switch de opciones a realizar
    switch (option)
    {
    case 1:
        system("cls");
        number1 = scan_num();
        flag1 = 1;

    //quiebro bloque switch po final de case.
    break;

    case 2:
        system("cls");
        number2 = scan_num();

        flag2 = 1;

    //quiebro bloque switch po final de case.
    break;

    case 3:
        system("cls");
        option = valiD_Charge( flag1, flag2);
        result = addition_num( number1, number2);
        printf("SUMA =\t:%d\n\n",result);
        system("pause");

    //quiebro bloque switch po final de case.
    break;


    case 4:
        system("cls");
        option = valiD_Charge( flag1, flag2);
        result = diminish_num( number1, number2);
        printf("RESTA =\t%d\n\n",result);
        system("pause");

    //quiebro bloque switch po final de case.
    break;

    case 5:
        system("cls");
        option = valiD_Charge( flag1, flag2);
        result = multiplcation( number1, number2);
        printf("MULTIPLICACION = \t%d\n\n",result);
        system("pause");

    //quiebro bloque switch po final de case.
    break;


    case 6:
        system("cls");
        option = valiD_Charge( flag1, flag2);
        divisionResult = division_num( number1, number2);
        printf("DIVISION =\t%.2f\n\n", divisionResult);
        system("pause");

    //quiebro bloque switch po final de case.
    break;


    case 7:
        system("cls");
        if(flag1 == 0 )
        {
            printf("ERROR!");
            printf(" el VALOR es INVALIDO\n\n reingrese el valor ");
        }
        else
        {
            result = factorial(number1 );
            printf("FACTORIAL = \t%d\n\n",result);
        }
            system("pause");

        //quiebro bloque switch po final de case.
        break;


    case 8:
        system("cls");
        option = valiD_Charge( flag1, flag2);
        all_In_One(number1 ,number2 );

    //quiebro bloque switch po final de case.
    break;


    case 9:
        //opcion de salida: si opcion es = 9 finaliza el programa por code la iteracion.


        //lipio la pantalla.
        system("cls");

        //muestro mesaje de despedida que anuncia cierre del programa.
        printf("\n\n\n\n\n\n\n\n\n                     ___________<<<<<HASTA LUEGO>>>>>___________\n\n\n\n\n\n\n\n\n");
    //quiebro bloque switch po final de case.
    break;

    default:
        system("cls");

        printf("\n\n\n\nERROR OPCION INEXISTENTE INTENETE NUEVAMENTE\n\n\n\n\n\n\n\n\n\n\n\n\n.");
        system("pause");
    }


    }while( option != 9 );


    return 0;
}// fin de funcion main.