7 Obj
*var
; /* index variable */
10 int op
; /* operator */
11 char *str
; /* string to push back */
16 For forstk
[MAXFOR
]; /* stack of for loops */
17 For
*forp
= forstk
; /* pointer to current top */
19 void forloop(Obj
*var
, double from
, double to
, int op
, double by
, char *str
) /* set up a for loop */
21 fprintf(tfd
, "# for %s from %g to %g by %c %g \n",
22 var
->name
, from
, to
, op
, by
);
23 if (++forp
>= forstk
+MAXFOR
)
24 ERROR
"for loop nested too deep" FATAL
;
35 void nextfor(void) /* do one iteration of a for loop */
37 /* BUG: this should depend on op and direction */
38 if (forp
->var
->fval
> SLOP
* forp
->to
) { /* loop is done */
41 ERROR
"forstk popped too far" FATAL
;
42 } else { /* another iteration */
43 pushsrc(String
, "\nEndfor\n");
44 pushsrc(String
, forp
->str
);
48 void endfor(void) /* end one iteration of for loop */
53 forp
->var
->fval
+= forp
->by
;
56 forp
->var
->fval
-= forp
->by
;
59 forp
->var
->fval
*= forp
->by
;
62 forp
->var
->fval
/= forp
->by
;
68 char *ifstat(double expr
, char *thenpart
, char *elsepart
)
70 dprintf("if %g then <%s> else <%s>\n", expr
, thenpart
, elsepart
? elsepart
: "");
73 pushsrc(Free
, thenpart
);
74 pushsrc(String
, thenpart
);
78 return thenpart
; /* to be freed later */
83 pushsrc(Free
, elsepart
);
84 pushsrc(String
, elsepart
);