/* * Function: power_monitor_report * Description: report data to power nodes * Input: id --- power radar nodes data struct * fmt -- args from reported devices * Return: -x--failed, 0--success */ int power_monitor_report(unsigned int id, const char *fmt, ...) { va_list args; int ret = -EINVAL; if (!is_id_valid(id)) { pr_err("%s: id %d is invalid!\n", __func__, id); return ret; } va_start(args, fmt); ret = report_handle(id, args, fmt); va_end(args); return ret; }
/*词法分析*/ void MYMICRO::parsetoken(std::vector<TOKEN> & tokens) { tokens.clear(); std::string tokenv ; char ch = 0; int flag = 0; int paras =0; while(input->good()) { *input>>ch; if(ch!='\n'&& isspace(ch)) continue; /*跳过空格*/ input->putback(ch); flag = 0; while(input->good()) { *input>>ch; switch (ch) { case TOKEN::ASSI: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::VAID; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::ASSI; temp.tokenval= '='; tokens.push_back(temp); flag = 1; break; } case TOKEN::MMULT: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::MMULT; temp.tokenval= TOKEN::MMULT; tokens.push_back(temp); flag = 1; break; } case TOKEN::DIV: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::DIV; temp.tokenval= TOKEN::DIV; tokens.push_back(temp); flag = 1; break; } case TOKEN::LINE: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::SEMI; temp.tokenval= TOKEN::SEMI; tokens.push_back(temp); flag = 1; break; } case TOKEN::COMM: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::COMM; temp.tokenval= TOKEN::COMM; tokens.push_back(temp); flag = 1; break; } case TOKEN::LPAR: { //std::cout<<paras<<"\n"; if(paras<0) throw(PAERROR); ++paras; if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::FUNC; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::LPAR; temp.tokenval= TOKEN::LPAR; tokens.push_back(temp); flag = 1; break; } case TOKEN::RPAR: { //std::cout<<paras<<"\n"; if(paras<1) throw(PAERROR); --paras; if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::RPAR; temp.tokenval= TOKEN::RPAR; tokens.push_back(temp); flag = 1; break; } case TOKEN::MINU: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::MINU; temp.tokenval= TOKEN::MINU; tokens.push_back(temp); flag = 1; break; } case TOKEN::PLUS: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::PLUS; temp.tokenval= TOKEN::PLUS; tokens.push_back(temp); flag = 1; break; } case TOKEN::MULT: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::MULT; temp.tokenval= TOKEN::MULT; tokens.push_back(temp); flag = 1; break; } case TOKEN::SEMI: { if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear();/*清空tokenval*/ } TOKEN temp; temp.tokentype= TOKEN::SEMI; temp.tokenval= TOKEN::SEMI; tokens.push_back(temp); flag = 1; break; } default: tokenv.push_back(ch); break; } if(flag = 1) { break; } } } if(paras>0) throw(PAERROR); if(tokenv.size()>0) { TOKEN temp; temp.tokentype= TOKEN::IDNM; temp.tokenval= tokenv; tokens.push_back(temp); tokenv.clear(); } /*判断token正确性*/ for(auto item = tokens.begin();item != tokens.end();++item) { if(item->tokentype == TOKEN::FUNC) { if( ! is_id_valid(item->tokenval)) { throw(IDERROR); } } if(item->tokentype == TOKEN::VAID) { if( ! is_id_valid(item->tokenval)) { throw(IDERROR); } } if(item->tokentype == TOKEN::IDNM) { if(is_id_valid(item->tokenval)) { item->tokentype = TOKEN::VAID; } else if(is_num_valid(item->tokenval)) { item->tokentype = TOKEN::CONSTNUM; } else throw(NUERROR); } if(item != tokens.begin()) { auto titem = item-1; if(item->tokentype == TOKEN::IDNM || item->tokentype == TOKEN::VAID) { if(titem->tokentype == TOKEN::IDNM || titem->tokentype == TOKEN::VAID) { throw(NUERROR); } } } } }