Example #1
0
int expr() { int mode; int id1; int ixarr; int ids;
  if (istoken(T_CONST)) {doconst(); return 1; }
  mode=typeName(); /*0=V,1=*,2=&*/
  if (token=='(')  {docall1(); goto e1; }
  if (isreg()) goto e1;
  id1=searchname(); gettypes(id1); ids=signi;
  ixarr=0;
  if (istoken('[')) { ixarr=searchname(); expect(T_NAME); expect(']');  
    gettypes(ixarr);
    if (widthi==0) error1("Arrayindex muss int sein"); } 
  if (istoken(T_PLUSPLUS  )) {if(mode)error1("Nur var erlaubt");doinc();goto e1;}
  if (istoken(T_MINUSMINUS)) {if(mode)error1("Nur var erlaubt");dodec();goto e1;}
  if (istoken(T_PLUSASS   )) {compoundass("add", mode); goto e1;}
  if (istoken(T_MINUSASS  )) {compoundass("sub", mode); goto e1;}
  if (istoken(T_ANDASS    )) {compoundass("and", mode); goto e1;}
  if (istoken(T_ORASS     )) {compoundass("or" , mode); goto e1;}    
  if (istoken(T_MULASS    )) {error1("nicht implementiert");}
  if (istoken(T_DIVASS    )) {error1("nicht implementiert");}      
  if (istoken('=')) { isconst=expr(); 
     if (isconst) { if(mode==0) {prs("\n;++++ mov  "); printName(id1); 
       prs(", "); prnum(lexval);  } }
     doassign(mode, id1, ixarr); goto e1;} 
  dovar1(mode, "mov", ixarr, id1);
e1:    if (istoken('+')) rterm("add");
  else if (istoken('-')) rterm("sub" );
  else if (istoken('&')) rterm("and" );
  else if (istoken('|')) rterm("or" );  
  else if (istoken(T_LESSLESS)) rterm("shl");
  else if (istoken(T_GREATGREAT)) rterm("shr");  
  else if (istoken('*')) domul (ids);
  else if (istoken('/')) doidiv(ids);
  else if (istoken('%')) domod (ids);
  if (isrelational()) { rterm("cmp"); cmpneg(ids);}
  return 0;
}
Example #2
0
int  main(void)
{
    docall0();

	p1func = call1;
	docall1();
	if(uchar1 != 3)
		failures++;
	if(uchar0 != 1)
		failures++;

	p1func = call0;
	docall1();
	if(uchar1 != 3)
		failures++;
	if(uchar0 != 4)
		failures++;

	docall2(call0);
	if(uchar1 != 3)
		failures++;
	if(uchar0 != 6)
		failures++;

	docall2(call1);
	if(uchar1 != 5)
		failures++;
	if(uchar0 != 6)
		failures++;

 	pcfunc = call2;
 	uchar2 = (*pcfunc)();
	if(uchar2 != 15)
		failures++;

 	uchar2 += (pcfunc)();
	uchar2 += pcfunc();

	success = failures;
	done();
	printf("failures: %d\n",failures);

	return failures;
}