Beispiel #1
0
Ty_tyList makeFormalTyList(S_table tenv, A_fieldList params) {
	A_fieldList ptr = params;
	Ty_tyList ret, ptr2;
	Ty_ty ty;

	ret = NULL; ptr2 = NULL;
	while(ptr != NULL) {
		ty = S_look(tenv, ptr->head->typ);
		if(ty != NULL) {
			if(ret == NULL) {
				ret = Ty_TyList(ty, NULL);
				ptr2 = ret;
			}
			else {
				ptr2->tail = Ty_TyList(ty, NULL);
				ptr2 = ptr2->tail;
			}
		}
		else {
			EM_error(ptr->head->pos, "undefined type %s", S_name(ptr->head->typ));
			exit(1);
		}
		ptr = ptr->tail;
	}
	return ret;
}
Beispiel #2
0
Ty_tyList makeFormalTyList(S_table tenv, A_fieldList afields) {
  Ty_tyList head = Ty_TyList(NULL, NULL), slow = head;
  for (; afields; afields = afields->tail) {
    Ty_tyList fast = Ty_TyList(S_look(tenv, afields->head->typ), NULL);
    slow->tail = fast;
    slow = fast;
  }
  return head->tail;
}
Beispiel #3
0
Ty_tyList makeFormalTyList( S_table tenv, A_fieldList args)
{
  if( args == NULL )
    return NULL;
  A_field arg = args->head;
  Ty_ty ty = S_look( tenv, arg->typ );
  if( ty == NULL )
    EM_error( arg->pos, "wrong ty");
  return Ty_TyList( ty, makeFormalTyList( tenv, args->tail ) );
}
Beispiel #4
0
Ty_tyList makeFormalTyList (S_table tenv, A_fieldList params)
{
  Ty_tyList tList = NULL;
  A_fieldList pList = NULL;

  for (pList = params; pList; pList = pList->tail) {
    Ty_ty ty = S_look (tenv, pList->head->typ);
    tList = Ty_TyList (ty, tList);
  }

  return tList;
}
Beispiel #5
0
Ty_tyList makeFormalTyList(S_table tenv, A_fieldList fieldList)
{
  A_fieldList fl = fieldList;
  Ty_tyList tl = NULL;
  Ty_tyList ret = NULL;
  Ty_ty ty;

  // 从左到右构造参数
  for (; fl; fl = fl->tail) {
    ty = S_look(tenv, fl->head->typ);
    if (ty) {
      if (tl) {
        tl = tl->tail = Ty_TyList(ty, NULL);
      } else {
        ret = tl = Ty_TyList(ty, tl);
      }
    } else {
      EM_error(fl->head->pos, "undefined type %s", S_name(fl->head->typ));
    }
  }

  return ret;
}
Beispiel #6
0
Ty_tyList makeFormalTyList(S_table tenv, A_fieldList params) {
	A_fieldList fl;
	Ty_tyList pTL = NULL;
	Ty_tyList resultTL = NULL;
	for (fl = params; fl; fl = fl->tail) {
		Ty_ty ty = (Ty_ty)S_look(tenv, fl->head->typ);
		if (ty) {
			if (resultTL) {
				pTL->tail = Ty_TyList(ty, NULL);
				pTL = pTL->tail;
			}
			else {
				resultTL = Ty_TyList(ty, NULL);
				pTL = resultTL;
			}
		}
		else {
			EM_error(fl->head->pos, (string)"undefined type '%s'", S_name(fl->head->typ));
			exit(1);
		}
	}
	return resultTL;
}
Beispiel #7
0
S_table E_base_venv(void) {
	S_table t = S_empty();
	S_enter(
    t,
    S_Symbol("print"),
    E_FunEntry(Ty_TyList(Ty_String(), NULL), Ty_Void())
  	);
  S_enter(
    t,
    S_Symbol("flush"),
    E_FunEntry(NULL, Ty_Void())
  	);
  S_enter(
    t,
    S_Symbol("getchar"),
    E_FunEntry(NULL, Ty_String())
  	);
  S_enter(
    t,
    S_Symbol("ord"),
    E_FunEntry(Ty_TyList(Ty_String(), NULL), Ty_Int())
  	);
  S_enter(
    t,
    S_Symbol("chr"),
    E_FunEntry(Ty_TyList(Ty_Int(), NULL), Ty_String())
  	);
  S_enter(
    t,
    S_Symbol("size"),
    E_FunEntry(Ty_TyList(Ty_String(), NULL), Ty_Int())
  	);
  S_enter(
    t,
    S_Symbol("substring"),
    E_FunEntry(Ty_TyList(Ty_String(),
                         Ty_TyList(Ty_Int(),
                                   Ty_TyList(Ty_Int(), NULL))),
    Ty_String())
  	);
  S_enter(
    t,
    S_Symbol("concat"),
    E_FunEntry(Ty_TyList(Ty_String(),
                         Ty_TyList(Ty_String(), NULL)),
    Ty_String())
  	);
  S_enter(
    t,
    S_Symbol("not"),
    E_FunEntry(Ty_TyList(Ty_Int(), NULL), Ty_Int())
  	);
  S_enter(
    t,
    S_Symbol("exit"),
    E_FunEntry(Ty_TyList(Ty_Int(), NULL), Ty_Void())
  	);
	return t;
}