Boost::Spirit 中的字符列解析
我正在为 Fortran 77 的一小部分开发基于 Boost Spirit 2.0 的解析器。我的问题我的问题是 Fortran 77 是面向列的,而我在 Spirit 中找不到任何可以允许其解析器具有列感知能力的内容。有什么办法可以做到这一点吗?
我实际上不必支持完整的晦涩的 Fortran 语法,但它确实需要能够忽略第一列中包含字符的行(Fortran 注释),并将第六列中包含字符的行识别为延续行。
似乎处理批处理文件的人至少会遇到与我相同的第一列问题。 Spirit 似乎有一个行尾解析器,但没有一个行首解析器(当然也不是一个column(x) 解析器)。
I'm working on a Boost Spirit 2.0 based parser for a small subset of Fortran 77. The issue I'm having is that Fortran 77 is column oriented, and I have been unable to find anything in Spirit that can allow its parsers to be column-aware. Is there any way to do this?
I don't really have to support the full arcane Fortran syntax, but it does need to be able to ignore lines that have a character in the first column (Fortran comments), and recognize lines with a character in the sixth column as continuation lines.
It seems like folks dealing with batch files would at least have the same first-column problem as me. Spirit appears to have an end-of-line parser, but not a start-of-line parser (and certianly not a column(x) parser).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,既然我现在有了答案,我想我应该分享它。
Fortran 77 可能像所有其他关心列的语言一样,是一种面向行的语言。这意味着您的解析器必须跟踪 EOL 并在解析中实际使用它。
另一个重要的事实是,就我而言,我并不关心解析 Fortran 可以放入那些早期控制列中的行号。我所需要的只是知道它何时告诉我以不同的方式扫描该行的其余部分。
考虑到这两点,我完全可以使用 Spirit 跳过解析器来处理这个问题。 我写的是
这是代码:
我建议不要盲目地将其用于面向行的 Fortran,因为我忽略行号,并且不同编译器对于有效注释和连续字符有不同的规则。
Well, since I now have an answer to this, I guess I should share it.
Fortran 77, like probably all other languages that care about columns, is a line-oriented language. That means your parser has to keep track of the EOL and actually use it in its parsing.
Another important fact is that in my case, I didn't care about parsing the line numbers that Fortran can put in those early control columns. All I need is to know when it is telling me to scan rest of the line differently.
Given those two things, I could entirely handle this issue with a Spirit skip parser. I wrote mine to
Here's the code:
I would advise against blindly using this yourself for line-oriented Fortran, as I ignore line numbers, and different compilers have different rules for valid comment and continuation characters.