生成的C ++ Bison解析器是否可重入?

时间:2016-11-30 21:08:49

标签: c++ bison flex-lexer reentrancy

我正在开发一个使用flex / bison来生成C ++扫描器/解析器的业余爱好项目。因为有大量的解析对象。解析本身就是令人尴尬的并行问题。我想汇集一些准备好运行的扫描程序/解析器对象,让它们并行运行。

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

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

但是,我很难从Bison文件中证实这一点。它确实有文件说明如何在Bison中构建一个可重入的C解析器。但它并没有明确暗示如果你构建一个C ++解析器,它是可重入的。我在Bison中发现了一些静态类成员生成的解析器头文件,这让我对此事感到担忧:

// 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 个答案:

答案 0 :(得分:1)

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

相关问题