English 中文(简体)
• 尽可能增加动力:
原标题:Minimizing boost::spirit compile times

减少推动的任何想法:共同汇编时间?

我刚刚举出一个精彩的教区,以推进:阴谋。 EBNF大约有25条规则。

The result runs well and the runtime performance is fine.

问题是,汇编起来永远不会! 它需要约十分钟,需要几乎一千兆字的记忆。 最初的“法尔”编成几秒。

我正在使用1.44.0版和2008年视觉演播室。


In Joel de Guzman s article 最佳做法

Rules with complex definitions hurt the compiler badly. We’ve seen rules that are more than a hundred lines long and take a couple of minutes to compile

我很早就没有东西了,但我的汇编仍然走过几分钟。

这里是我方言中最复杂的部分。 它是被分成小部分的候选人吗?

rule
    =   (   tok.if_ >> condition  >> tok.then_ >> *sequel  )                            [ bind( &cRuleKit::AddRule, &myRulekit ) ]
    |   (   tok.if_ >> condition  >> tok.and_ >> condition >> tok.then_ >> *sequel  )   [ bind( &cRuleKit::AddRule, &myRulekit ) ]
    ;

condition
    =   ( tok.identifier >> tok.oper_ >> tok.value )                                    [ bind( &cRuleKit::AddCondition, &myRulekit, _pass, _1, _2, _3 ) ]
    |   ( tok.identifier >> tok.between_ >> tok.value >> "," >> tok.value )             [ bind( &cRuleKit::AddConditionBetween, &myRulekit, _pass, _1, _3, _4 ) ]
    ;

sequel
    =   ( tok.priority_ >> tok.high_ )      [ bind( &cRuleKit::setPriority, &myRulekit, 3 ) ]
    |   ( tok.priority_  )                  [ bind( &cRuleKit::setPriority, &myRulekit, 2 ) ]
    |   ( tok.interval_ >> tok.value )      [ bind( &cRuleKit::setInterval, &myRulekit, _2 ) ]
    |   ( tok.mp3_ >> tok.identifier )      [ bind( &cRuleKit::setMP3, &myRulekit, _2 ) ]
    |   ( tok.disable_ )                    [ bind( &cRuleKit::setNextRuleEnable, &myRulekit, false ) ]
    ;

通过对图表部分的评论,我发现,大部分汇编者花时间。

set_reading
    =   tok.set_reading >> +attribute_reading
    ;

attribute_reading
    =   ( tok.name_ >> tok.identifier )
        [ bind( &cPackage::Add, &myReadings, _pass, _2 ) ]
    |   ( tok.nmea_ >> tok.identifier )
        [ bind( &cPackage::setNextNMEA, &myReadings, _2 ) ]
    |   ( tok.column_ >> tok.integer )
        [ bind( &cPackage::setNextColumn, &myReadings, _2 ) ]
    |   ( tok.precision_ >> tok.value )
        [ bind( &cPackage::setNextPrecision, &myReadings, _2 ) ]
    |   ( tok.unit_ >> tok.identifier )
        [ bind( &cPackage::setNextUnit, &myReadings, _2 ) ]
    |   ( tok.value_ >> tok.identifier )
        [ bind( &cPackage::setNextValue, &myReadings, _2 ) ]
    |   ( tok.qualifier_ >> tok.identifier >> tok.qual_col_ >> tok.integer )
        [ bind( &cPackage::setNextQualifier, &myReadings, _2, _4 ) ]
    ;

I wouldn t call it complex, but it is certainly the longest rule. So I thought I would try splitting it up, like this:

set_reading
    =   tok.set_reading >> +attribute_reading
    ;

attribute_reading
    =   attribute_reading_name
    |   attribute_reading_nmea
    |   attribute_reading_col
    |   attribute_reading_precision
    |   attribute_reading_unit
    |   attribute_reading_value
    |   attribute_reading_qualifier
    ;



attribute_reading_name
    =   ( tok.name_ >> tok.identifier )     [ bind( &cPackage::Add, &myReadings, _pass, _2 ) ]
    ;
attribute_reading_nmea
    =   ( tok.nmea_ >> tok.identifier )     [ bind( &cPackage::setNextNMEA, &myReadings, _2 ) ]
    ;
attribute_reading_col
    =   ( tok.column_ >> tok.integer )      [ bind( &cPackage::setNextColumn, &myReadings, _2 ) ]
    ;
attribute_reading_precision
    =   ( tok.precision_ >> tok.value )     [ bind( &cPackage::setNextPrecision, &myReadings, _2 ) ]
    ;
attribute_reading_unit
    =   ( tok.unit_ >> tok.identifier )     [ bind( &cPackage::setNextUnit, &myReadings, _2 ) ]
    ;
attribute_reading_value
    =   ( tok.value_ >> tok.identifier )    [ bind( &cPackage::setNextValue, &myReadings, _2 ) ]
    ;
attribute_reading_qualifier
    =   ( tok.qualifier_ >> tok.identifier >> tok.qual_col_ >> tok.integer ) [ bind( &cPackage::setNextQualifier, &myReadings, _2, _4 ) ]
    ;

这节省了总编辑时间的几分钟!

奇怪的是,顶峰的记忆要求仍然不变,仅仅需要时间较少。

因此,我感到更希望的是,在学习方面,我的所有努力都得到了加强:眼光是值得的。

我确实认为,汇编者需要如此仔细地以这种方式指导,这是很奇怪的。 我想,一位现代的汇编者会注意到,这一规则只是一份独立的其他资源规则清单。


我花了七天最好的学习力:心灵,把一个小但真实的世界从法轮到来。 我的结论是,它行之有效,法典非常可取。 不幸的是,简单地扩大教学法对实际应用的粗略使用,迅速使汇编者负担过重——记忆和汇编所需时间完全不切实际。 显然,存在管理这一问题的技术,但需要的是我没有时间学习的北极知识。 我猜测,我将坚持灵活的做法,这种灵活性可能是ug和老的,但相对简单,而且迅速缓解。

最佳回答

I have to come to the conclusion that boost:spirit, elegant as it is, is not a viable option for many real world parsing problems due to the lengthy compile times that even experts cannot fix.

通常最好坚持像灵活做法这样的东西,这种灵活性可能是ug的,也是老的,但相对简单,迅速缓解。

我在此认为一个真正的世界问题的一个例子是,一部精彩的帽子中最重要的部分的铁路线图在两秒钟内汇编,但加固:眼皮在十分钟后仍然chu。

“entergraph

问题回答

我可以建议把两者的构造者、贵方法和贵方法的汇编分开。 实现这一目标最容易的办法,是只让这些建筑商在自己的影像头档案中宣布其身份,并将这些功能的定义变成单独的翻译单位。 例如:

图表:

template <typename Iterator>
struct grammar : qi::grammar<Iterator>
{
    grammar();   // declaration only
    // ...
};

grammar_def.hpp:

// This file should not contain anything else.
#include "grammar.hpp"

// Definition of constructor.
template <typename Iterator>
grammar<Iterator>::grammar()
{
    // initialize your rules here
}

图表:

// This file should not contain anything else.
#include "grammar_def.hpp"

// Explicitly instantiate the constructor for the iterator type
// you use to invoke the grammar (here, as an example I use 
// std::string::const_iterator).
typedef std::string::const_iterator iterator_type;
template grammar<iterator_type>::grammar();

Do the same thing for the lexer object.

This approach requires a bit more work than the straight method, but it allows to distribute the memory and time requirements for the overall compilation. Another advantage of this approach is that any change in the grammar constructor does not require the recompilation of anything except the file grammar.cpp.

另一种建议是:尽可能减少使用<代码>至ken_def<>的情况。 你们需要使用<条码>,以便标注_def<>,只有当你想在服饰期间获得象征性价值时。 在所有其他情况下,您可删除<代码>lex:string或lex:char_,以界定其标语。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签