Login
CStdioFile - bad ptr (Visual C++)
612 просмотров
Перейти к просмотру всей ветки
scorpi_ скептик
in Antwort JacksonB 15.05.06 16:39
Есть ещё такая прикольная штучка как Spirit http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit/index.html
Вот примерчик для затравки:
Ausgabe:
Object name: Name
Object attribute name: type
Object attribute value: int
Object attribute name: xdm
Object attribute value: 3
Object attribute name: ydm
Object attribute value: 2
Object attribute name: model
Object attribute value: KMO_2
Object name: Name2
Object attribute name: type
Object attribute value: uint
Вот примерчик для затравки:
В ответ на:
#include <boost/spirit/core.hpp>
#include <iostream>
#include <string>
#include <map>
using namespace std;
using namespace boost::spirit;
void set_object_name( char const* first, char const* last )
{
cout << "Object name: " << string(first, last) << endl;
}
void set_object_attr_name( char const* first, char const* last )
{
cout << "Object attribute name: " << string(first, last) << endl;
}
void set_object_attr_value( char const* first, char const* last )
{
cout << "Object attribute value: " << string(first, last) << endl;
}
struct object_parser : public grammar< object_parser >
{
template <typename ScannerT>
struct definition
{
definition( object_parser const& /*self*/ )
{
expression = str_p( "#define" )
>> word [ &set_object_name ]
>> *attr
;
attr = word [ &set_object_attr_name ]
>> '='
>> word [ &set_object_attr_value ]
;
word = lexeme_d[ +(alnum_p | '_') ];
}
rule<ScannerT> expression, attr, attr_value, word;
rule<ScannerT> const& start() const { return expression; }
};
};
int main()
{
object_parser parser;
parse_info<> info = parse( "#define Name type=int xdm=3 ydm=2 model=KMO_2", parser, space_p );
if ( ! info.full )
cout << "Parsing failed at: " << info.stop << endl;
info = parse( "#define Name2 type=uint", parser, space_p );
if ( ! info.full )
cout << "Parsing failed at: " << info.stop << endl;
}
Ausgabe:
Object name: Name
Object attribute name: type
Object attribute value: int
Object attribute name: xdm
Object attribute value: 3
Object attribute name: ydm
Object attribute value: 2
Object attribute name: model
Object attribute value: KMO_2
Object name: Name2
Object attribute name: type
Object attribute value: uint