【发布时间】:2015-11-02 17:11:00
【问题描述】:
我一直在使用 Boost 迷你编译器示例。这里是源码的根:http://www.boost.org/doc/libs/1_59_0/libs/spirit/example/qi/compiler_tutorial/mini_c/
我感兴趣的sn-p在statement_def.hpp
我遇到的问题是,如果您附加语义操作,例如这样,
statement_ =
variable_declaration[print_this_declaration]
| assignment
| compound_statement
| if_statement
| while_statement
| return_statement
;
随后在示例程序上运行mini_c 编译器,例如:
int foo(n) {
if (n == 3) { }
return a;
}
int main() {
return foo(10);
}
它会触发“compile.cpp”文件中的“重复函数错误”(使用上面的链接找到)。这是用于快速参考的 sn-p:
if (functions.find(x.function_name.name) != functions.end())
{
error_handler(x.function_name.id, "Duplicate function: " + x.function_name.name);
return false;
}
对于我的一生,我不知道为什么。
我不太确定如何描述这个问题,但似乎以某种方式发送到标准输出的任何内容都被解析器作为有效代码进行解析(但在这种情况下这似乎是不可能的)。
另一种可能性是语义操作以某种方式将外部数据绑定到符号表,在那里它再次被认为是最初解析的输入文件的一部分(当它不应该是时)。
最后一个也是可能的选择是,我可能不完全理解这个例子的细节(或者 Boost),并且指针/引用/迭代器在它应该被转移到另一个内存位置的地方' t(作为 SA 的结果),使整个迷你编译器陷入混乱。
【问题讨论】:
-
用boost 标记您的问题相当于ping @sehe。
-
开始研究这个:livecoding.tv/sehe
-
哦,快。我会在 5 分钟后回到家立即登录。
-
什么是
print_this_declaration?我暂时不做任何操作,但是……看起来它可能是相关的 -
类似 "void print_this_declaration { std::cout
标签: c++ templates boost header boost-spirit-qi