|
关于Basic程序解释器及编译原理的简单化(1)---Basic器的语法分析及主要代码(8) get_exp(&value); /* get initial value */ variables[i.var]=value; get_token(); if (tok != TO) serror(9); /* read an discard the TO */ get_exp(&i.target); /* get target value */ /* if loop can execute at least once, push into on stack */ if (value<=i.target) { i.loc = prog; fpush(i); } else /* otherwise, skip loop code altogether */ while (tok!=NEXT) get_token(); } /* execute a NEXT statement */ void next() { struct for_stack i;
i = fpop(); /*read the loop info */ variables[i.var]++; /* increment control variable */ if (variables[i.var]>i.target) return; /* all done */ fpush(i); /* otherwise,return the info */ prog = i.loc; /* loop */ } /* push function for the FOR stack */ void fpush(struct for_stack i) { if (ftos>FOR_NEST) serror(10); fstack[ftos]=i; ftos++; }
struct for_stack fpop() { ftos--; if (ftos<0) serror(11); return (fstack[ftos]); }
/* exec a simple form of BASIC INPUT command */ void input() { char str[80],var; int i;
get_token(); /* see if prompt string id=s present */ if (token_type == QUOTE) { printf (token); /* if so , print it and check for command */
|