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分析器重入?
非常好的一點!你的意思是數組本身是const還是數組的元素是const?我需要找到一個C++參考來區分這些。 –
C++數組(如C數組)無法調整大小,因此數組爲const並且數組的元素爲const時沒有區別。 – rici
感謝您的回答。我在C++ Primer中評論了const章節。生活在Java世界太久了,我差點忘了這一點。 –