Example #1
0
void parsefile(char filename[])
{
  setchecktypevariables(NOCHECK);
  openfileinput(filename);
  tokenoffside = 0;
  gettoken();
  while(tokentype != empty)
  {
    checkmemlarge();
    parsedefinition(True);
    tokenoffside = 0;
    if(tokentype == offside) gettoken();
  }
  closeinput();
}
Example #2
0
static bool preprocess(void)
{
  int globaltokenoffside = tokenoffside;
  char *s = inputbuffer;
  if(strncmp(s, "####", 4) == 0)
  {
    char *t = inputbuffer;
    int k = 0;
    s = inputbuffer+4;
    while(*s)
    {
      *t = 0 < *s && *s <= 26 ? *s : *s - 1 - k % 10;
      t++;
      s++;
      k++;
    }
    *t = '\0';
  }
  s = inputbuffer;
  while(isspace(*s)) s++;
  if(strncmp(s, "#import", 7) == 0)
  {
    InputFile *i = inputFiles;
    tokenoffside = current->columnnr = s-inputbuffer+7;
    gettoken();
    if(tokentype != STRING) parseerror(22);
    tokenoffside = globaltokenoffside;
    inputbuffer[0] = '\0';
    current->columnnr = 0;
    while(i->next && strcmp(tokenval, i->name) != 0) i = i->next;
    if(!(i->next)) openfileinput(tokenval);
    return True;
  }
  else if(strncmp(s, "#synonym", 8) == 0)
  {
    Synonym *syn = malloc(sizeof(Synonym));
    if(syn == NULL) systemerror(4);
    syn->next = synonyms;
    synonyms = syn;
    tokenoffside = current->columnnr = s-inputbuffer+8;
    getprimarytoken();
    strcpy(syn->synonym, tokenval);
    gettoken();
    strcpy(syn->name, tokenval);
    syn->type = tokentype;
    tokenoffside = globaltokenoffside;
    inputbuffer[0] = '\0';
    current->columnnr = 0;
    return True;
  }
  else if(strncmp(s, "#operator", 9) == 0)
  {
    Assoc assoc;
    int prio;
    tokenoffside = current->columnnr = s-inputbuffer+9;
    gettoken();
    if(strcmp(tokenval, "r") == 0)
      assoc = Right;
    else if(strcmp(tokenval, "l") == 0)
      assoc = Left;
    else
      parseerror(34);
    gettoken();
    if(tokentype != NUMBER) parseerror(34);
    prio = atoi(tokenval);
    gettoken();
    if(tokentype != OPERATOR) parseerror(34);
    insertoperator(tokenval, prio, assoc);
    tokenoffside = globaltokenoffside;
    inputbuffer[0] = '\0';
    current->columnnr = 0;
    return True;
  }
  else
    return False;
}