date_type parse_date(const std::string& s, int order_spec = ymd_order_iso) { std::string spec_str(""); if(order_spec == ymd_order_iso) { spec_str = "ymd"; } else if(order_spec == ymd_order_dmy) { spec_str = "dmy"; } else { // (order_spec == ymd_order_us) spec_str = "mdy"; } typedef typename date_type::year_type year_type; typedef typename date_type::month_type month_type; unsigned pos = 0; typename date_type::ymd_type ymd(year_type::min(),1,1); boost::tokenizer<boost::char_delimiters_separator<char> > tok(s); for(boost::tokenizer<>::iterator beg=tok.begin(); beg!=tok.end(), pos < spec_str.size(); ++beg, ++pos) { unsigned short i =0; switch(spec_str.at(pos)) { case 'y': { i = boost::lexical_cast<unsigned short>(*beg); ymd.year = i; break; } case 'm': { ymd.month = month_str_to_ushort<month_type>(*beg); break; } case 'd': { i = boost::lexical_cast<unsigned short>(*beg); ymd.day = i; break; } } //switch } return date_type(ymd); }
/* * init_lex - initialize lexical analyzer. */ void init_lex() { struct sym_entry *sym; int i; static int first_time = 1; if (first_time) { first_time = 0; ident = spec_str(ident); /* install ident in string table */ /* * install C keywords into the symbol table */ sym_add(Auto, spec_str("auto"), OtherDcl, 0); sym_add(Break, spec_str("break"), OtherDcl, 0); sym_add(Case, spec_str("case"), OtherDcl, 0); sym_add(TokChar, spec_str("char"), OtherDcl, 0); sym_add(Const, spec_str("const"), OtherDcl, 0); sym_add(Continue, spec_str("continue"), OtherDcl, 0); sym_add(Default, spec_str("default"), OtherDcl, 0); sym_add(Do, spec_str("do"), OtherDcl, 0); sym_add(Doubl, spec_str("double"), OtherDcl, 0); sym_add(Else, spec_str("else"), OtherDcl, 0); sym_add(TokEnum, spec_str("enum"), OtherDcl, 0); sym_add(Extern, spec_str("extern"), OtherDcl, 0); sym_add(Float, spec_str("float"), OtherDcl, 0); sym_add(For, spec_str("for"), OtherDcl, 0); sym_add(Goto, spec_str("goto"), OtherDcl, 0); sym_add(If, spec_str("if"), OtherDcl, 0); sym_add(Int, spec_str("int"), OtherDcl, 0); sym_add(TokLong, spec_str("long"), OtherDcl, 0); sym_add(TokRegister, spec_str("register"), OtherDcl, 0); sym_add(Return, spec_str("return"), OtherDcl, 0); sym_add(TokShort, spec_str("short"), OtherDcl, 0); sym_add(Signed, spec_str("signed"), OtherDcl, 0); sym_add(Sizeof, spec_str("sizeof"), OtherDcl, 0); sym_add(Static, spec_str("static"), OtherDcl, 0); sym_add(Struct, spec_str("struct"), OtherDcl, 0); sym_add(Switch, spec_str("switch"), OtherDcl, 0); sym_add(Typedef, spec_str("typedef"), OtherDcl, 0); sym_add(Union, spec_str("union"), OtherDcl, 0); sym_add(Unsigned, spec_str("unsigned"), OtherDcl, 0); sym_add(Void, spec_str("void"), OtherDcl, 0); sym_add(Volatile, spec_str("volatile"), OtherDcl, 0); sym_add(While, spec_str("while"), OtherDcl, 0); /* * Install keywords from run-time interface language. */ sym_add(Abstract, spec_str("abstract"), OtherDcl, 0); sym_add(All_fields, spec_str("all_fields"), OtherDcl, 0); sym_add(Any_value, spec_str("any_value"), OtherDcl, 0); sym_add(Arith_case, spec_str("arith_case"), OtherDcl, 0); sym_add(Body, spec_str("body"), OtherDcl, 0); sym_add(C_Double, spec_str("C_double"), OtherDcl, 0); sym_add(C_Integer, spec_str("C_integer"), OtherDcl, 0); sym_add(C_String, spec_str("C_string"), OtherDcl, 0); sym_add(Cnv, spec_str("cnv"), OtherDcl, 0); sym_add(Constant, spec_str("constant"), OtherDcl, 0); sym_add(Declare, spec_str("declare"), OtherDcl, 0); sym_add(Def, spec_str("def"), OtherDcl, 0); sym_add(Empty_type, spec_str("empty_type"), OtherDcl, 0); sym_add(End, spec_str("end"), OtherDcl, 0); sym_add(Errorfail, spec_str("errorfail"), OtherDcl, 0); sym_add(Exact, spec_str("exact"), OtherDcl, 0); sym_add(Fail, spec_str("fail"), OtherDcl, 0); sym_add(TokFunction, spec_str("function"), OtherDcl, 0); sym_add(Inline, spec_str("inline"), OtherDcl, 0); sym_add(Is, spec_str("is"), OtherDcl, 0); sym_add(Keyword, spec_str("keyword"), OtherDcl, 0); sym_add(Len_case, spec_str("len_case"), OtherDcl, 0); sym_add(Named_var, spec_str("named_var"), OtherDcl, 0); sym_add(New, spec_str("new"), OtherDcl, 0); sym_add(Of, spec_str("of"), OtherDcl, 0); sym_add(Operator, spec_str("operator"), OtherDcl, 0); str_rslt = spec_str("result"); sym_add(Runerr, spec_str("runerr"), OtherDcl, 0); sym_add(Store, spec_str("store"), OtherDcl, 0); sym_add(Struct_var, spec_str("struct_var"), OtherDcl, 0); sym_add(Suspend, spec_str("suspend"), OtherDcl, 0); sym_add(Tended, spec_str("tended"), OtherDcl, 0); sym_add(Then, spec_str("then"), OtherDcl, 0); sym_add(Tmp_cset, spec_str("tmp_cset"), OtherDcl, 0); sym_add(Tmp_string, spec_str("tmp_string"), OtherDcl, 0); sym_add(TokType, spec_str("type"), OtherDcl, 0); sym_add(Type_case, spec_str("type_case"), OtherDcl, 0); sym_add(Underef, spec_str("underef"), OtherDcl, 0); sym_add(Variable, spec_str("variable"), OtherDcl, 0); for (i = 0; i < num_typs; ++i) { icontypes[i].id = spec_str(icontypes[i].id); sym = sym_add(IconType, icontypes[i].id, OtherDcl, 0); sym->u.typ_indx = i; } for (i = 0; i < num_cmpnts; ++i) { typecompnt[i].id = spec_str(typecompnt[i].id); sym = sym_add(Component, typecompnt[i].id, OtherDcl, 0); sym->u.typ_indx = i; } } }