Value expression::eval(Value &ret) { ValueStack valstack; String str_oper; str_oper="oper"; POSITION pos=m_postfix.get_top_position(); for(; pos; pos=m_postfix.get_next(pos)){ const char*s=m_postfix.get(pos); if(s[0]=='%' || isalpha(s[0]) ) { //ValueRef vref(getworld()->var_get(s)); valstack.add(getworld()->var_get(s)); } else if (isdigit(s[0])){ valstack.add()=str_to_real(s); } else { _oper* p; if(s[0]=='\'') p=getworld()->oper_get(s+1); else p=getworld()->oper_get(str_oper+s); p->eval(valstack) ; } } ret=valstack.get_last(); valstack.remove(); return ret; }
tokenInfo getNextToken( DFA *d) { char lxm[100]; tokenInfo t; int cur_state = d->start_state, lxm_size = 0; int started = 0, comment =0; //cur_state = -1 represents invalid state char c; while(cur_state>=0 && !d->is_final[cur_state]) { if(buf_pointer == chars_in_buf) { if(chars_in_buf<BUF_SIZE){ //EOF reached strcpy(t.lxme,"$"); strcpy(t.token,"$"); return t; } else{ buf_pointer = 0; fp = getStream(fp, buf, BUF_SIZE); } } c = buf[buf_pointer++]; if(!comment && c>128){ cur_state = -1; break; } //ignore comments and whitespaces if(!started){ if(c>32 && c!='#' && !comment){ started = 1; } else{ if(c=='#') comment = 1; if(c=='\n'){ comment = 0; cur_line++; } continue; } } cur_state = d->transitions[cur_state][c]; lxm[lxm_size++] = c; } t.line_no = cur_line; if(cur_state==-1) { if(is_unknown( c)){ printf("Unknown symbol '%c' at line %d.\n",c,cur_line); } else{ printf("Unknown pattern %s at line %d.\n",lxm,cur_line); } strcpy(t.token,"INVALID"); strncpy(t.lxme,lxm,25); return t; } else{ //in Final state if(d->to_backtrack[cur_state]) { buf_pointer--; lxm_size--; } lxm[lxm_size++] = '\0'; if(!strcmp(d->tok[cur_state],"ID")){ if(lxm_size > 20){ printf("Identifier %s at line %d is longer than the prescribed length of 20 characters\n",lxm,cur_line); } } if(!strcmp(d->tok[cur_state],"STR")){ if(lxm_size > 22){ printf("String %s at line %d is longer than the prescribed length of 20 characters\n",lxm,cur_line); } } strcpy(t.token,d->tok[cur_state]); fflush(stdout); if(!strcmp(t.token,"NUM")) t.i_val = str_to_int(lxm); if(!strcmp(t.token,"RNUM")) t.r_val = str_to_real(lxm); strncpy(t.lxme,lxm,25); t.lxme[25] = '\0'; fflush(stdout); return t; } }