Пример #1
0
int mpl_read_data(MPL *mpl, char *file)
{     if (mpl->phase != 1)
         fault("mpl_read_data: invalid call sequence");
      if (file == NULL)
         fault("mpl_read_data: no input filename specified");
      /* set up error handler */
      if (setjmp(mpl->jump)) goto done;
      /* process data section */
      mpl->phase = 2;
      print("Reading data section from %s...", file);
      mpl->flag_d = 1;
      open_input(mpl, file);
      /* in this case the keyword 'data' is optional */
      if (is_literal(mpl, "data"))
      {  get_token(mpl /* data */);
         if (mpl->token != T_SEMICOLON)
            error(mpl, "semicolon missing where expected");
         get_token(mpl /* ; */);
      }
      data_section(mpl);
      /* process end statement */
      end_statement(mpl);
      print("%d line%s were read", mpl->line, mpl->line == 1 ? "" : "s")
         ;
      close_input(mpl);
done: /* return to the calling program */
      return mpl->phase;
}
Пример #2
0
/*---------------------------------------------------------------------------*/
static void
statement(void)
{
  int token;

  token = tokenizer_token();

  switch(token) {
  case TOKENIZER_PRINT:
    print_statement();
    break;
  case TOKENIZER_IF:
    if_statement();
    break;
  case TOKENIZER_GOTO:
    goto_statement();
    break;
  case TOKENIZER_GOSUB:
    gosub_statement();
    break;
  case TOKENIZER_RETURN:
    return_statement();
    break;
  case TOKENIZER_FOR:
    for_statement();
    break;
  case TOKENIZER_PEEK:
    peek_statement();
    break;
  case TOKENIZER_POKE:
    poke_statement();
    break;
  case TOKENIZER_NEXT:
    next_statement();
    break;
  case TOKENIZER_END:
    end_statement();
    break;
  case TOKENIZER_LET:
    accept(TOKENIZER_LET);
    /* Fall through. */
  case TOKENIZER_VARIABLE:
    let_statement();
    break;
  default:
    DEBUG_PRINTF("ubasic.c: statement(): not implemented %d\n", token);
    exit(1);
  }
}
Пример #3
0
int mpl_read_model(MPL *mpl, char *file, int skip_data)
{     if (mpl->phase != 0)
         xfault("mpl_read_model: invalid call sequence\n");
      if (file == NULL)
         xfault("mpl_read_model: no input filename specified\n");
      /* set up error handler */
      if (setjmp(mpl->jump)) goto done;
      /* translate model section */
      mpl->phase = 1;
      xprintf("Reading model section from %s...\n", file);
      open_input(mpl, file);
      model_section(mpl);
      if (mpl->model == NULL)
         error(mpl, "empty model section not allowed");
      /* save name of the input text file containing model section for
         error diagnostics during the generation phase */
      mpl->mod_file = xcalloc(strlen(file)+1, sizeof(char));
      strcpy(mpl->mod_file, mpl->in_file);
      /* allocate content arrays for all model objects */
      alloc_content(mpl);
      /* optional data section may begin with the keyword 'data' */
      if (is_keyword(mpl, "data"))
      {  if (skip_data)
         {  warning(mpl, "data section ignored");
            goto skip;
         }
         mpl->flag_d = 1;
         get_token(mpl /* data */);
         if (mpl->token != T_SEMICOLON)
            error(mpl, "semicolon missing where expected");
         get_token(mpl /* ; */);
         /* translate data section */
         mpl->phase = 2;
         xprintf("Reading data section from %s...\n", file);
         data_section(mpl);
      }
      /* process end statement */
      end_statement(mpl);
skip: xprintf("%d line%s were read\n",
         mpl->line, mpl->line == 1 ? "" : "s");
      close_input(mpl);
done: /* return to the calling program */
      return mpl->phase;
}
Пример #4
0
int mpl_read_data(MPL *mpl, char *file)
#if 0 /* 02/X-2008 */
{     if (mpl->phase != 1)
#else
{     if (!(mpl->phase == 1 || mpl->phase == 2))
#endif
         xfault("mpl_read_data: invalid call sequence\n");
      if (file == NULL)
         xfault("mpl_read_data: no input filename specified\n");
      /* set up error handler */
      if (setjmp(mpl->jump)) goto done;
      /* process data section */
      mpl->phase = 2;
      xprintf("Reading data section from %s...\n", file);
      mpl->flag_d = 1;
      open_input(mpl, file);
      /* in this case the keyword 'data' is optional */
      if (is_literal(mpl, "data"))
      {  get_token(mpl /* data */);
         if (mpl->token != T_SEMICOLON)
            error(mpl, "semicolon missing where expected");
         get_token(mpl /* ; */);
      }
      data_section(mpl);
      /* process end statement */
      end_statement(mpl);
      xprintf("%d line%s were read\n",
         mpl->line, mpl->line == 1 ? "" : "s");
      close_input(mpl);
done: /* return to the calling program */
      return mpl->phase;
}

/*----------------------------------------------------------------------
-- mpl_generate - generate model.
--
-- *Synopsis*
--
-- #include "glpmpl.h"
-- int mpl_generate(MPL *mpl, char *file);
--
-- *Description*
--
-- The routine mpl_generate generates the model using its description
-- stored in the translator database. This phase means generating all
-- variables, constraints, and objectives, executing check and display
-- statements, which precede the solve statement (if it is presented),
-- and building the problem instance.
--
-- The character string file specifies the name of output text file, to
-- which output produced by display statements should be written. It is
-- allowed to specify NULL, in which case the output goes to stdout via
-- the routine print.
--
-- This routine should be called once after the routine mpl_read_model
-- or mpl_read_data and if one of the latters returned the code 2.
--
-- *Returns*
--
-- The routine mpl_generate returns one of the following codes:
--
-- 3 - model has been successfully generated. In this case the calling
--     program may call other api routines to obtain components of the
--     problem instance from the translator database.
-- 4 - processing failed due to some errors. In this case the calling
--     program should call the routine mpl_terminate to terminate model
--     processing. */

int mpl_generate(MPL *mpl, char *file)
{     if (!(mpl->phase == 1 || mpl->phase == 2))
         xfault("mpl_generate: invalid call sequence\n");
      /* set up error handler */
      if (setjmp(mpl->jump)) goto done;
      /* generate model */
      mpl->phase = 3;
      open_output(mpl, file);
      generate_model(mpl);
      flush_output(mpl);
      /* build problem instance */
      build_problem(mpl);
      /* generation phase has been finished */
      xprintf("Model has been successfully generated\n");
done: /* return to the calling program */
      return mpl->phase;
}

/*----------------------------------------------------------------------
-- mpl_get_prob_name - obtain problem (model) name.
--
-- *Synopsis*
--
-- #include "glpmpl.h"
-- char *mpl_get_prob_name(MPL *mpl);
--
-- *Returns*
--
-- The routine mpl_get_prob_name returns a pointer to internal buffer,
-- which contains symbolic name of the problem (model).
--
-- *Note*
--
-- Currently MathProg has no feature to assign a symbolic name to the
-- model. Therefore the routine mpl_get_prob_name tries to construct
-- such name using the name of input text file containing model section,
-- although this is not a good idea (due to portability problems). */

char *mpl_get_prob_name(MPL *mpl)
{     char *name = mpl->mpl_buf;
      char *file = mpl->mod_file;
      int k;
      if (mpl->phase != 3)
         xfault("mpl_get_prob_name: invalid call sequence\n");
      for (;;)
      {  if (strchr(file, '/') != NULL)
            file = strchr(file, '/') + 1;
         else if (strchr(file, '\\') != NULL)
            file = strchr(file, '\\') + 1;
         else if (strchr(file, ':') != NULL)
            file = strchr(file, ':') + 1;
         else
            break;
      }
      for (k = 0; ; k++)
      {  if (k == 255) break;
         if (!(isalnum((unsigned char)*file) || *file == '_')) break;
         name[k] = *file++;
      }
      if (k == 0)
         strcpy(name, "Unknown");
      else
         name[k] = '\0';
      xassert(strlen(name) <= 255);
      return name;
}
Пример #5
0
//static void statement(void)
void statement(void)
{
	int token;
	token = tokenizer_token();

	switch(token) {
		case TOKENIZER_PRINT:
			print_statement();
			break;
		case TOKENIZER_IF:
			if_statement();
			break;
		case TOKENIZER_GOTO:
			goto_statement();
			break;
		case TOKENIZER_GOSUB:
			gosub_statement();
			break;
		case TOKENIZER_RETURN:
			return_statement();
			break;
		case TOKENIZER_FOR:
			for_statement();
			break;
		case TOKENIZER_NEXT:
			next_statement();
			break;
		case TOKENIZER_END:
			end_statement();
			break;
		case TOKENIZER_PSET:
			pset_statement();
			break;
		case TOKENIZER_CLS:
			cls_statement();
			break;
		case TOKENIZER_REFRESH:
			refresh_statement();
			break;
		case TOKENIZER_LIST:
			list_statement();
			break;
		case TOKENIZER_LOAD:
			load_statement();
			break;
		case TOKENIZER_SAVE:
			save_statement();
			break;
		case TOKENIZER_FILES:
			files_statement();
			break;
		case TOKENIZER_PEEK:
			peek_statement();
			break;
		case TOKENIZER_POKE:
			poke_statement();
			break;
		case TOKENIZER_WAIT:
			wait_statement();
			break;
		case TOKENIZER_INPUT:
			input_statement();
			break;
		case TOKENIZER_INP:
			inp_statement();
			break;
		case TOKENIZER_INR:
			inr_statement();
			break;
		case TOKENIZER_INA:
			ina_statement();
			break;
		case TOKENIZER_REM:
			rem_statement();
			break;
		case TOKENIZER_RUN:
			run_statement();
			break;
		case TOKENIZER_ERROR:
			tokenizer_error_print();
			ended = 1;
			glcd_DrawCursor();
			break;
		case TOKENIZER_LET:
			accept(TOKENIZER_LET);
			accept(TOKENIZER_VARIABLE);
			accept(TOKENIZER_CR);
			break;
			/* Fall through. */
		case TOKENIZER_VARIABLE:
			let_statement();
			break;
		default:
			exit(1);
	}
}