|
关于Basic程序解释器及编译原理的简单化(1)---Basic器的语法分析及主要代码(6) } /* find location of given label. A null is returned if label is not found; ohtherwise a pointer to the position of the label is returned. */ char *find_label(char *s) { register int t; for (t=0;t<NUM_LAB;++t) if (!strcmp(label_table[t].name,s)) return label_table[t].p; return '\0'; /* error condition */ } /* execute a GOTO statement. */ void exec_goto() { char *loc;
get_token(); /* get label to go to */ /* find the location of label */ loc = find_label (token); if (loc=='\0') serror(7); /* label not defined */ else prog=loc; /* start program running at that time */ } /* initialize the array that holds the labels. by convention , a null label name indicates that array posiiton is unused. */ void label_init() { register int t;
for (t=0;t<NUM_LAB;++t) label_table[t].name[0]='\0'; } /* execute an IF statement */ void exec_if() { int x,y,cond; char op;
get_exp(&x); /* get left exapression */ get_token(); /* get the operator */ if (!strcmp("<>",*token)) { serror(0); /* not a leagal oprator */ return; } op = *token; get_exp(&y); /* get right expression */ /* determine the outcome */ cond = 0; switch(op) {
|