0

Bison 的标准版本通过确保以下四个字段可用,使重新定义位置类型变得非常简单:

customsourcelocation.h

struct CustomSourceLocation
{
  int first_line;
  int first_column;
  int last_line;
  int last_column;
};

解析器.y

...
%define api.location.type {CustomSourceLocation}
...
%code requires {
  #include "customsourcelocation.h"
}
...

然而,C++ 版本的 location 似乎更高级,因为构成 location 类型的结构也由多个position对象组成。

谁能提供一个为 C++ Bison 解析器重新定义位置类型的基本示例,以便位置数据对象独立于 Bison,因此可以从任何文件中包含,而无需同时包含任何 Bison 生成的代码?

提前致谢。

4

1 回答 1

0

感谢 rici 指出答案。使用 %locations 选项时将生成一个 location.hh 文件,可以根据需要对其进行修改和包含。

于 2021-06-14T20:04:55.653 回答