【发布时间】:2021-06-14 19:42:35
【问题描述】:
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 生成的代码?
提前致谢。
【问题讨论】:
-
这就是
location.hh标头的意义所在,您可以根据需要对其进行自定义。请参阅bison manual。 -
@rici 有没有办法防止每次编译bison文件时重置location.hh?
-
我的理解是,如果指定
api.location.type,就不会生成header。 (那么你需要自己包含标题。)