Bonjour,

J'ai le code suivant (une grammar) avec une variable globale :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
size_t								g_pointersSize;
 
struct MyGrammar : public grammar<MyGrammar>
{	// Explicit identifiers to switch properly when evaluating the AST
	typedef enum
	{	noID,
		factorID,
		termID,
		expressionID,
		unaryID,
		variableID,
		numberID,
	} id_type;
 
	// Meta function from scanner type to a proper rule type
	template<typename ScannerT> struct definition
	{	rule<ScannerT, parser_context<>, parser_tag<factorID > >		factor_p;
		rule<ScannerT, parser_context<>, parser_tag<termID > >			term_p;
		rule<ScannerT, parser_context<>, parser_tag<expressionID > >	expression_p;
		rule<ScannerT, parser_context<>, parser_tag<unaryID > >			unary_p;
		rule<ScannerT, parser_context<>, parser_tag<variableID > >		variable_p;
		rule<ScannerT, parser_context<>, parser_tag<numberID > >		number_p;
		rule<ScannerT> start_p;
 
		// Arithmetic expression l_ogrammar:
		definition(const MyGrammar& self)
		{	factor_p		// numbers, variables or parentheticals
				= number_p 
				| variable_p 
				| ( inner_node_d['(' >> expect_expression(start_p) >> expect_close(ch_p(')'))] );
 
			unary_p			// unary operators (right-to-left)
				= (root_node_d[ch_p('-')]) >> expect_expression(unary_p)
				| factor_p;
 
			term_p			// multiplicatives (left-to-right) 
				= unary_p >> *(root_node_d[ch_p('*')|'/'] >> expect_expression(unary_p));
 
			expression_p	// additives       (left-to-right)
				= term_p  >> *(root_node_d[ch_p('+')|'-'] >> expect_expression(term_p));
 
			number_p
				= leaf_node_d[real_p];
 
			variable_p
				= leaf_node_d[ lexeme_d[as_lower_d[chlit<>('m')] >> max_limit_d(g_pointersSize - 1)[uint_p] ] ];
 
			start_p
				= expect_expression(expression_p);
 
			#ifdef BOOST_SPIRIT_DEBUG
			BOOST_SPIRIT_DEBUG_RULE(factor_p);
			BOOST_SPIRIT_DEBUG_RULE(term_p);
			BOOST_SPIRIT_DEBUG_RULE(unary_p);
			BOOST_SPIRIT_DEBUG_RULE(number_p);
			BOOST_SPIRIT_DEBUG_RULE(variable_p);
			BOOST_SPIRIT_DEBUG_RULE(expression_p);
			BOOST_SPIRIT_DEBUG_RULE(start_p);
			#endif
		}
 
		// Specify the starting rule for the parse
		const rule<ScannerT> & start() const { return start_p; }
	};
};
Je dois éliminer cette variable. Je pense donc pouvoir transmettre cette variable en tant que paramètre dans le constructeur de la grammar. Est-ce bien réalisable?

Cela donnerait le code suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
struct MyGrammar : public grammar<MyGrammar>
{	// Explicit identifiers to switch properly when evaluating the AST
	typedef enum
	{	//..
		variableID,
		//..
	} id_type;
 
        static size_t m_pointersSize;
 
        MyGrammar(size_t parametre)
        {
         m_pointersSize=parametre;
        }
 
	// Meta function from scanner type to a proper rule type
	template<typename ScannerT> struct definition
	{	
                //..
                rule<ScannerT, parser_context<>, parser_tag<variableID > >		variable_p;
		//..
 
		// Arithmetic expression l_ogrammar:
		definition(const MyGrammar& self)
		{	
                        //...
 
			variable_p
				= leaf_node_d[ lexeme_d[as_lower_d[chlit<>('m')] >> max_limit_d(m_pointersSize - 1)[uint_p] ] ];
 
                         //...
		}
 
		// Specify the starting rule for the parse
		const rule<ScannerT> & start() const { return start_p; }
	};
};
je précise que si je ne mets pas mon attribut en static, j'ai le droit à un message d'erreur explicite.
Mais cela m'engendre tout de même un message d'erreur :
monfichierclasse.obj : error LNK2019: symbole externe non rÚsolu "
public: static unsigned int MyGrammar::m_pointersSize" (?m_pointersSize@MyGrammar@@2IA) rÚfÚrencÚ dans la fonction "public:
__thiscall MyGrammar
::definition<class boost::spirit::scanner<char const *,struct boost::spirit::scanner_policies<class boost::spirit::skip_parser_iteration_policy<struct boost::spirit::space_parser,struct boost::spirit::iteration_policy>,struct boost::spirit::ast_match_policy<char const *,class boost::spirit::node_val_data_factory<struct boost::spirit::nil_t> >,struct boost::spirit::action_policy> > >
::definition<class boost::spirit::scanner<char const *,struct boost::spirit::scanner_policies<class boost::spirit::skip_parser_iteration_policy<struct boost::spirit::space_parser,struct boost::spirit::iteration_policy>,struct boost::spirit::ast_match_policy<char const *,class boost::spirit::node_val_data_factory<struct boost::spirit::nil_t> >,struct boost::spirit::action_policy> > >
(struct MyGrammar const &)"
(??0?$definition@V?$scanner@PBDU?$scanner_policies@V?$skip_parser_iteration_policy@Uspace_parser@s
pirit@boost@@Uiteration_policy@23@@spirit@boost@@U?$ast_match_policy@PBDV?$node_
val_data_factory@Unil_t@spirit@boost@@@spirit@boost@@@23@Uaction_policy@23@@spir
it@boost@@@spirit@boost@@@MyGrammar@@QAE@ABU1@@Z)
Je sens que c'est encore lié à mon élément static...mais le jargon boost m'est presque inconnu alors, je vous demande de l'aide!
Comment comprendre ce message et comment régler mon problème de paramètre?

Merci d'avance