예제 #1
0
CExpression::arbore CExpression::expresie()
{
	arbore nod;
	arbore arb1 = termen();
	arbore arb2;
	if	(arb1 == NULL) return NULL;  // In caz de eroare terminate
	
	while ((m_definitie[pozitie]=='-') || (m_definitie[pozitie]=='+')){
		nod=new NOD;
		nod->left=arb1;
		nod->operatie=m_definitie[pozitie];
		pozitie++;
		arb2 = termen();
		nod->right=arb2;
		if	(arb2 == NULL){
			elibmem(nod);
			return NULL;  // In caz de eroare terminate
		}
		arb1 = nod;
	}
	return arb1;
}
예제 #2
0
float exp()
{
   float ts, td;
   char c;
   oper o;

   ts= termen();
   if ((x[i+1] == '+') || (x[i+1] == '-'))
   {
      i++;
      if (x[i] == '+')
	 c= '+';
      else
	 c= '-';
      i++;
      td= factor();
      if (c == '+')
	 return ts+td;
      else
	 return ts-td;
   }
   else
      return ts;
}