示例#1
0
static void parseabstype(void)
{
  Cell *head, *abstype;
  int globaltokenoffside;

  gettoken();
  parselefthandside();
  abstype = pop();
  while(abstype->tag == APPLY) abstype = abstype->left;
  if(abstype->tag != UNDEFINED && abstype->tag != FUNC) parseerror(13);
  if(!insertabstype(getfunction(abstype->value)->name, abstype)) parseerror(12);
  if(tokentype != WITH) parseerror(14);
  globaltokenoffside = tokenoffside;
  tokenoffside = tokenindent + 1;
  gettoken();
  while(tokentype == IDENTIFIER || tokentype == OPERATOR || tokentype == LPAR)
  {
    int temptokenoffside = tokenoffside;
    parselefthandside();
    tokenoffside = tokenindent + 1;
    if(tokentype != COLONS) parseerror(15);
    head = pop();
    if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(13);
    gettoken();
    parsetype(TYPEEXPR);
    if(!inserttypeexpr(getfunction(head->value)->name, pop()))
      parseerror(12);
    if(!insertabstype(getfunction(head->value)->name, abstype))
      parseerror(12);
    while(tokentype == SEP) gettoken();
    tokenoffside = temptokenoffside;
    if(tokentype == offside) gettoken();
  }
  tokenoffside = globaltokenoffside;
  if(tokentype == offside) gettoken();
}
示例#2
0
/********************************************************************
  initialisation of hashtable with system functions
*********************************************************************/
static void initsyslib(void)
{
  Cell *obj = gettemplate("objecttype");
  inserttypestring("object", "[char] -> objecttype");
  insertabstype("object", obj);
  parsetypeexpr("(*, [char] -> [[char]] -> * -> (*, [[char]]))");
  makeconstant(FUNC, obj->value);
  makecompound(STRUCT, 1);
  make(TYPESYNONYM);
  inserttypeexpr("objecttype", pop());
  insertabstype("objecttype", obj);

  insert("_section", 3, FUNC      , NULL, apply_SECTION);
  insert("if"      , 3, FUNC      , NULL, applyIF);
  insert("^"       , 2, FUNC      , NULL, applyPOWER);
  insert("neg"     , 1, FUNC      , NULL, applyNEG);
  insert("*"       , 2, FUNC      , NULL, applyTIMES);
  insert("/"       , 2, FUNC      , NULL, applyDIV);
  insert("//"      , 2, FUNC      , NULL, applyDIVIDE);
  insert("%"       , 2, FUNC      , NULL, applyMOD);
  insert("+"       , 2, FUNC      , NULL, applyPLUS);
  insert("-"       , 2, FUNC      , NULL, applyMINUS);
  insert("="       , 2, FUNC      , NULL, applyEQ);
  insert("~="      , 2, FUNC      , NULL, applyNE);
  insert("<"       , 2, FUNC      , NULL, applyLT);
  insert("<="      , 2, FUNC      , NULL, applyLE);
  insert(">"       , 2, FUNC      , NULL, applyGT);
  insert(">="      , 2, FUNC      , NULL, applyGE);
  insert("&"       , 2, FUNC      , NULL, applyUPDATE);
  insert("True"    , 0, BOOLEAN   , NULL, NULL);
  insert("False"   , 0, BOOLEAN   , NULL, NULL);
  insert("pi"      , 0, REAL      , NULL, NULL);
  insert("Nil"     , 0, NIL       , NULL, NULL);
  insert(""        , 1, FUNC      , NULL, NULL);
  insert("strict"  , 2, FUNC      , NULL, applySTRICT);

  inserttypestring("_section"  , "(* -> ** -> ***) -> ** -> * -> ***");
  inserttypestring("if"        , "bool -> * -> * -> *");
  inserttypestring("^"         , "num -> num -> num");
  inserttypestring("neg"       , "num -> num");
  inserttypestring("*"         , "num -> num -> num");
  inserttypestring("/"         , "num -> num -> num");
  inserttypestring("//"        , "num -> num -> num");
  inserttypestring("%"         , "num -> num -> num");
  inserttypestring("+"         , "num -> num -> num");
  inserttypestring("-"         , "num -> num -> num");
  inserttypestring("="         , "* -> * -> bool");
  inserttypestring("~="        , "* -> * -> bool");
  inserttypestring("<"         , "* -> * -> bool");
  inserttypestring("<="        , "* -> * -> bool");
  inserttypestring(">"         , "* -> * -> bool");
  inserttypestring(">="        , "* -> * -> bool");
  inserttypestring("&"         , "* -> * -> *");
  inserttypestring("True"      , "bool");
  inserttypestring("False"     , "bool");
  inserttypestring("pi"        , "num");
  inserttypestring("Nil"       , "[*]");
  inserttypestring("strict"    , "(* -> **) -> * -> **");

  insertsys("strict");
  insertsys("^");
  insertsys("neg");
  insertsys("*");
  insertsys("/");
  insertsys("//");
  insertsys("%");
  insertsys("+");
  insertsys("-");
  insertsys("=");
  insertsys("~=");
  insertsys("<");
  insertsys("<=");
  insertsys(">");
  insertsys(">=");

  insertoperator("."   , 1, Right);
  insertoperator(":"   , 1, Right);
  insertoperator("&"   , 1, Left);
  insertoperator("!"   , 2, Left);
  insertoperator("^"   , 2, Right);
  insertoperator("*"   , 3, Left);
  insertoperator("/"   , 3, Left);
  insertoperator("//"  , 3, Left);
  insertoperator("%"   , 3, Left);
  insertoperator("++"  , 4, Right);
  insertoperator("--"  , 4, Left);
  insertoperator("+"   , 4, Left);
  insertoperator("-"   , 4, Left);
  insertoperator("="   , 5, Right);
  insertoperator("~="  , 5, Left);
  insertoperator("<"   , 5, Left);
  insertoperator("<="  , 5, Left);
  insertoperator(">"   , 5, Left);
  insertoperator(">="  , 5, Left);
  insertoperator("/\\" , 6, Right);
  insertoperator("\\/" , 7, Right);

  template_divide = gettemplate("//");
  template_div    = gettemplate("/");
  template_mod    = gettemplate("%");
  template_power  = gettemplate("^");
  template_update = gettemplate("&");
}