2016-11-30 25 views
0

我正在使用flex/bison生成C++扫描程序/解析器的业余爱好项目。因为有大量的解析对象。解析本身是令人尴尬的并行问题。我想集中一些准备运行的扫描器/解析器对象并让它们并行运行。是否生成C++ Bison解析器可重入?

我通过Flex和Bison官方文档阅读并浏览了他们生成的代码。

我可以确认从Flex文档及其代码生成的C++扫描程序是可重入的。

但是,我很难从Bison文件中确认这一点。它确实有文档说明如何在Bison中构建可重入的C语言分析器。但它并没有明确暗示你是否构建了一个C++解析器,它是可重入的。我发现野牛一对夫妇类的静态成员的生成语法分析器头文件,它让我在这个问题上的担忧:

// Tables. 
// YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing 
// STATE-NUM. 
static const short int yypact_[]; 

// YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. 
// Performed when YYTABLE does not specify something else to do. Zero 
// means the default is an error. 
static const unsigned char yydefact_[]; 

// YYPGOTO[NTERM-NUM]. 
static const signed char yypgoto_[]; 

// YYDEFGOTO[NTERM-NUM]. 
static const signed char yydefgoto_[]; 

// YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If 
// positive, shift that token. If negative, reduce the rule whose 
// number is the opposite. If YYTABLE_NINF, syntax error. 
static const short int yytable_[]; 

static const short int yycheck_[]; 

// YYSTOS[STATE-NUM] -- The (internal number of the) accessing 
// symbol of state STATE-NUM. 
static const unsigned char yystos_[]; 

// YYR1[YYN] -- Symbol number of symbol that rule YYN derives. 
static const unsigned char yyr1_[]; 

// YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. 
static const unsigned char yyr2_[]; 

生成C++ Bison分析器重入?

回答

1

这些都是static const这是完全兼容的重入。这些表定义了解析器的转换规则,并且与解析器的可执行代码基本上不同,后者也是静态且不可变的。

+0

非常好的一点!你的意思是数组本身是const还是数组的元素是const?我需要找到一个C++参考来区分这些。 –

+0

C++数组(如C数组)无法调整大小,因此数组为const并且数组的元素为const时没有区别。 – rici

+0

感谢您的回答。我在C++ Primer中评论了const章节。生活在Java世界太久了,我差点忘了这一点。 –

相关问题