<i id='Zhbtr'><tr id='Zhbtr'><dt id='Zhbtr'><q id='Zhbtr'><span id='Zhbtr'><b id='Zhbtr'><form id='Zhbtr'><ins id='Zhbtr'></ins><ul id='Zhbtr'></ul><sub id='Zhbtr'></sub></form><legend id='Zhbtr'></legend><bdo id='Zhbtr'><pre id='Zhbtr'><center id='Zhbtr'></center></pre></bdo></b><th id='Zhbtr'></th></span></q></dt></tr></i><div id='Zhbtr'><tfoot id='Zhbtr'></tfoot><dl id='Zhbtr'><fieldset id='Zhbtr'></fieldset></dl></div>

    <legend id='Zhbtr'><style id='Zhbtr'><dir id='Zhbtr'><q id='Zhbtr'></q></dir></style></legend>
    • <bdo id='Zhbtr'></bdo><ul id='Zhbtr'></ul>
    <tfoot id='Zhbtr'></tfoot>

    <small id='Zhbtr'></small><noframes id='Zhbtr'>

    1. Boost.Spirit:Lex + Qi 错误报告

      Boost.Spirit: Lex + Qi error reporting(Boost.Spirit:Lex + Qi 错误报告)

      <small id='UBbOd'></small><noframes id='UBbOd'>

        <i id='UBbOd'><tr id='UBbOd'><dt id='UBbOd'><q id='UBbOd'><span id='UBbOd'><b id='UBbOd'><form id='UBbOd'><ins id='UBbOd'></ins><ul id='UBbOd'></ul><sub id='UBbOd'></sub></form><legend id='UBbOd'></legend><bdo id='UBbOd'><pre id='UBbOd'><center id='UBbOd'></center></pre></bdo></b><th id='UBbOd'></th></span></q></dt></tr></i><div id='UBbOd'><tfoot id='UBbOd'></tfoot><dl id='UBbOd'><fieldset id='UBbOd'></fieldset></dl></div>
            <tbody id='UBbOd'></tbody>
              <bdo id='UBbOd'></bdo><ul id='UBbOd'></ul>
              <tfoot id='UBbOd'></tfoot>

                <legend id='UBbOd'><style id='UBbOd'><dir id='UBbOd'><q id='UBbOd'></q></dir></style></legend>
                本文介绍了Boost.Spirit:Lex + Qi 错误报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在为使用缩进等的相当复杂的配置文件编写解析器.我决定使用 Lex 将输入分解为标记,因为它似乎让生活更轻松.问题是我找不到任何使用 Qi 错误报告工具 (on_error) 和解析器的示例,这些解析器对令牌流而不是字符进行操作.

                I am writing a parser for quite complicated config files that make use of indentation etc. I decided to use Lex to break input into tokens as it seems to make life easier. The problem is that I cannot find any examples of using Qi error reporting tools (on_error) with parsers that operate on stream of tokens instead of characters.

                要在 on_error 中使用的错误处理程序需要一些时间才能准确指出错误在输入流中的位置.所有示例都只是从一对迭代器构造 std::string 并打印它们.但是如果使用 Lex,则迭代器是标记序列的迭代器,而不是字符.在我的程序中,这导致在我注意到无效的迭代器类型之前挂在 std::string 构造函数中.

                Error handler to be used in on_error takes some to be able to indicate exactly where the error is in the input stream. All examples just construct std::string from the pair of iterators and print them. But if Lex is used, that iterators are iterators to the sequence of tokens, not characters. In my program this led to hang in std::string constructor before I noticed invalid iterator type.

                据我所知,token 可以将一对迭代器保存到输入流中作为其值.这是默认的属性类型(如果类型类似于 lex::lexertl::token<>).但是,如果我希望我的令牌包含对解析更有用的东西(intstd::string 等),那么这些迭代器就会丢失.

                As I understand token can hold a pair of iterators to the input stream as its value. This is the default attribute type (if type is like lex::lexertl::token<>). But if I want my token to contain something more useful for parsing (int, std::string, etc), those iterators are lost.

                在将 Lex 与 Qi 一起使用时,如何生成人性化的错误消息来指示输入流中的位置?有没有这种用法的例子?

                How can I produce human friendly error messages indicating position in the input stream while using Lex with Qi? Are there any examples of such usage?

                谢谢.

                推荐答案

                抱歉回复晚了,但我花了一些时间来准备一个体面的示例来说明您要实现的目标.我现在向 Spirit 添加了一个新的词法分析器示例:conjure_lexer.它是 conjure (Qi) 示例的修改版本,实现了一种小型编程语言.主要区别在于它使用词法分析器而不是纯粹的 Qi 语法.

                Sorry for the late reply, but it took me some time to prepare a decent example of what you're trying to achieve. I now added a new lexer example to Spirit: conjure_lexer. It is a modified version of the conjure (Qi) example implementing a small programming language. The main difference is that it is using a lexer instead of a pure Qi grammar.

                新的 conjure_lexer 示例演示了几件事:a) 它使用了一个新的 position_token 类,它扩展了现有的 token 类型.它始终存储指向相应匹配输入序列的迭代器对(除了通常的信息,如令牌 ID、令牌值等).b) 它使用这个位置信息来报告错误c) 顺着思路,它演示了如何使用词法分析器来简化语法.

                The new conjure_lexer example demonstrates several things: a) it is using a new position_token class, which extends the existing token type. It always stores the pair of iterators pointing to the corresponding matched input sequence (in addition to the usual information like token id, token value, etc.). b) it is using this positional information for error reporting c) and along the lines, it demonstrates how using a lexer can simplify the grammar.

                新示例位于 SVN(主干)中,并将在 Boost V1.47(即将发布)中提供.它在这个目录中:$BOOST_ROOT/libs/spirit/example/qi/compiler-tutorial/conjure_lexer.

                The new example is in SVN (trunk) and will be available in Boost V1.47 (to be released soon). It's in this directory: $BOOST_ROOT/libs/spirit/example/qi/compiler-tutorial/conjure_lexer.

                这篇关于Boost.Spirit:Lex + Qi 错误报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                Delay Loading DLLs(延迟加载 DLL)
                Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                Loading a dll from a dll?(从 dll 加载 dll?)

                1. <tfoot id='HXMVZ'></tfoot>

                    <tbody id='HXMVZ'></tbody>
                2. <legend id='HXMVZ'><style id='HXMVZ'><dir id='HXMVZ'><q id='HXMVZ'></q></dir></style></legend>

                    <i id='HXMVZ'><tr id='HXMVZ'><dt id='HXMVZ'><q id='HXMVZ'><span id='HXMVZ'><b id='HXMVZ'><form id='HXMVZ'><ins id='HXMVZ'></ins><ul id='HXMVZ'></ul><sub id='HXMVZ'></sub></form><legend id='HXMVZ'></legend><bdo id='HXMVZ'><pre id='HXMVZ'><center id='HXMVZ'></center></pre></bdo></b><th id='HXMVZ'></th></span></q></dt></tr></i><div id='HXMVZ'><tfoot id='HXMVZ'></tfoot><dl id='HXMVZ'><fieldset id='HXMVZ'></fieldset></dl></div>

                        <bdo id='HXMVZ'></bdo><ul id='HXMVZ'></ul>
                        • <small id='HXMVZ'></small><noframes id='HXMVZ'>