Example #1
0
static void next_sym(prolog_obj_t *o)
{ again: switch(o->ch)
        { case ' ': case '\t': next_ch(o); goto again;
          case '\n': o->lc++; next_ch(o); goto again;
          case '\0': case EOF: o->sym = EOI; break;
          case '#': comment(o); next_ch(o); goto again;
          case '(': o->sym = LPAR;    next_ch(o); break;
          case ')': o->sym = RPAR;    next_ch(o); break;
          case '[': o->sym = LSPAR;   next_ch(o); break;
          case ']': o->sym = RSPAR;   next_ch(o); break;
          case '.': o->sym = PERIOD;  next_ch(o); break;
          case ',': o->sym = COMMA;   next_ch(o); break;
          case '?': next_ch(o); 
                    if(o->ch != '-') RECOVER(o,"expected '-'"); 
                    o->sym = QUERY;
                    next_ch(o);
                    break;
          case ':': next_ch(o); 
                    if(o->ch != '-') RECOVER(o, "expected '-'"); 
                    o->sym = ASSIGN;
                    next_ch(o);
                    break;
          default:
                if(isdigit(o->ch)) { /*integer*/
                        o->ival = 0;
                        while(isdigit(o->ch)) {
                                o->ival = o->ival*10 + (o->ch - '0'); 
                                next_ch(o);
                        }
                        o->sym = INT;
                } else if(isalpha(o->ch)) { /*variable, atom or keyword*/
                        size_t i = 0;
                        while(isalnum(o->ch)) {
                                if(i > ID_MAX) RECOVER(o, "identifier too longer");
                                o->id[i++] = o->ch;
                                next_ch(o);
                        }
                        o->id[i] = '\0';
                        if(isupper(o->id[0])) { /*variable*/
                                o->sym = VARLEX;
                                break;
                        } else { /*id or keyword*/
                                o->sym = 0;
                                while(words[o->sym] && strcmp(words[o->sym], o->id))
                                        o->sym++;
                                if(!words[o->sym]) /*id*/
                                        o->sym = ID;
                                break;
                        }
                } else {
                        RECOVER(o, "invalid char"); 
                }
                break;
        }
}
Example #2
0
void extractLoci() {
  const int LINE_LENGTH = 256;
  char line[LINE_LENGTH];

  std::ifstream tempmloci("tempmloci.out");
  if(tempmloci.fail()) {
    PROBLEM "The file tempmloci.out cannot be opened for reading.\nextractLoci.cpp key 27\n"
      RECOVER(NULL_ENTRY);
  }

  std::ofstream loci("loci.out");
  if(loci.fail()) {
    PROBLEM "The file loci.out cannot be opened for reading.\nextractLoci.cpp key 35\n"
      RECOVER(NULL_ENTRY);
  }

  // Copy the first line, the narrative line naming the (m)ibd file that
  // created it.
  tempmloci.getline(line, LINE_LENGTH);
  // If tempmloci is already bad, that means that it is empty.
  if(tempmloci.fail()) {
    tempmloci.close();
    loci.close();
    return;
  } 

  loci << line << std::endl;

  // Stop copying when we find '#' or the end of file.
  tempmloci.getline(line, LINE_LENGTH);
  while(tempmloci.good() && line[0] != '#') {
    loci << line << std::endl;
    tempmloci.getline(line, LINE_LENGTH);
  }

  loci.close();

  // Now copy the rest of the file to a temp file.
  std::ofstream deleteThisFile("deleteThisFile");

  while(tempmloci.good()) {
    // line still holds the line of text beginning with '#'
    deleteThisFile << line << std::endl;
    tempmloci.getline(line, LINE_LENGTH);  
  }

  deleteThisFile.close();
  tempmloci.close();

  // Update temploci.out and remove deleteThisFile at the same time
  system("mv deleteThisFile tempmloci.out");
}
void ObjectEntryList :: InitObjEntry (BinSArrayObjEntry *obj_entry, uint64 entry_index )
{
  EB_Number           ebsnum(entry_index);
  acb                 acbenty(ebsnum.ToPIF(root_base->IsPIF()),0,CUR_VERSION);
  logical     term = NO;
BEGINSEQ
//  if ( statistics )
//    locate_stats.Start();
  
  ((ObjectEntry *)obj_entry)->stsrerr();;
  term = !root_base->getEBI(&acbenty);

  ((ObjectEntry *)obj_entry)->Free(instance_pool);
  BinArray::InitObjEntry(obj_entry,entry_index);

  ((ObjectEntry *)obj_entry)->Initialize(&acbenty);

  if ( term )                                        ERROR
    
//  if ( statistics )
//    locate_stats.Stop();

RECOVER
  ((ObjectEntry *)obj_entry)->stsserr();
ENDSEQ

}
Example #4
0
static void errmsg(char *string){

  /* Function to emulate "stop" of S+ - see page 134, S Programing, by
     Venables and Ripley */

   PROBLEM "%s", string RECOVER(NULL_ENTRY);
}
Example #5
0
static node *rule(prolog_obj_t *o)
{       node *x = new_node(o, RULE);
        PDEBUG(x->type, "rule");
        x->o1 = term(o);
        if(o->sym == PERIOD)
                return x;
        if(o->sym == ASSIGN) { 
                next_sym(o);
                x->o2 = terms(o);
                if(o->sym != PERIOD) 
                        RECOVER(o, "expected '.'");
                return x;
        }
        RECOVER(o, "expected ':-' or '.'");
        return x;
}
Example #6
0
static node *program(prolog_obj_t *o)
{       node *x = new_node(o, PROG);
        PDEBUG(x->type, "program");
        next_sym(o); 
        x->o1 = queryorrule(o); 
        if(o->sym != EOI)
                RECOVER(o, "expected EOI");
        return x;
}
Example #7
0
/*****************************
Class name: InitValue_par
Method name: convertPrecision
Description: Given a string representation of how an initial value is to be
             used, return the appropriate interger representation.
Input: char *precision - A string specifying how an initial value will be
                         fixed, estimated, or constrained.
Output: int - This int is the integer representation of a variable's desired
              use.
Side Effects: If precision is not of the correct form, an error message is
              printed to standard error and the program exits with an error
              level of 1.
Author: Eric Lunde, 6-12-03
******************************/
int InitValue_par::convertPrecision(char *precision) {
  if(strcmp(precision, "F")==0 || strcmp(precision, "f")==0 ) {
    return FIXED;
  }else if(strcmp(precision, "E")==0 || strcmp(precision, "e")==0 ) {
    return ESTIMATE;
  }else if(strcmp(precision, "C")==0 || strcmp(precision, "c")==0 ) {
    return CONSTRAINT;
  }else {
    PROBLEM "%s%s%s%s%s%s%s%s",
      "Error in InitValue_par::GetInitValues.\n",
      "Precision values must be F, f, E, e, C, or c.\n",
      "Your precision was ", precision, "\n",
      "If you cannot fix the problem, contact programmer ",
      "Eric Lunde @ 507-284-5630",
      "InitValue_par.cpp line 277\n"
      RECOVER(NULL_ENTRY);
    // Adding a return -1; makes the compiler happy.
    return -1;
  }
}
Example #8
0
static node *new_node(prolog_obj_t *o, int type)
{       node *x = calloc(1, sizeof(node));
        if(!x) RECOVER(o, "allocation failed"); 
        x->type = type;
        return x;
}