1293 |
String nextExpectedChars; ///< According to current parser position: sequence of characters expected next for satisfying this grammar symbol. |
String nextExpectedChars; ///< According to current parser position: sequence of characters expected next for satisfying this grammar symbol. |
1294 |
}; |
}; |
1295 |
|
|
1296 |
|
#if HAVE_BISON_MAJ >= 3 // Bison 3.x or younger ... |
1297 |
|
|
1298 |
|
/** |
1299 |
|
* Must ONLY be called just before a so called "reduce" parser action: |
1300 |
|
* Returns true if the grammar rule, which is just about to be "reduced", is a |
1301 |
|
* terminal symbol (in *our* terms). |
1302 |
|
* |
1303 |
|
* Please note that the term "terminal symbol" is a bit confusingly used in |
1304 |
|
* this source code here around. In Bison's terms, "terminal symbols" are (more |
1305 |
|
* or less) just the numbers returned by the YYLEX function. Since we decided |
1306 |
|
* though to use a convenient solution without a separate lexer, and all its |
1307 |
|
* caveats, all numbers by the yylex() function here are just the ASCII |
1308 |
|
* numbers of the individual characters received. Based on that however, one |
1309 |
|
* single character is not what one would intuitively expect of being a |
1310 |
|
* "terminal symbol", because it is simply too primitive. |
1311 |
|
* |
1312 |
|
* So in this LSCP parser source code a "terminal symbol" rather means a |
1313 |
|
* keyword like "CREATE" or "GET". In the grammal definition above, those are |
1314 |
|
* however defined as grammar rules (non-terminals in Bison's terms). So this |
1315 |
|
* function decides like this: if the given grammar rule just contains |
1316 |
|
* individual characters on the right side of its grammar rule, then it is a |
1317 |
|
* "terminal symbol" in *our* terms. |
1318 |
|
* |
1319 |
|
* @param rule - Bison grammar rule number |
1320 |
|
* @param stack - reflecting current Bison parser state |
1321 |
|
*/ |
1322 |
|
inline static bool _isRuleTerminalSymbol(int rule, const std::vector<YYTYPE_INT16>& stack) { |
1323 |
|
int nrhs = yyr2[rule]; |
1324 |
|
for (int i = 0; i < nrhs; ++i) |
1325 |
|
if (yystos[*(stack.end() - nrhs + i)] >= YYNTOKENS) return false; |
1326 |
|
return true; |
1327 |
|
} |
1328 |
|
|
1329 |
|
/** |
1330 |
|
* Must ONLY be called just before a so called "reduce" parser action: Returns |
1331 |
|
* additional informations to the given grammar rule that is about to be |
1332 |
|
* "reduced". |
1333 |
|
* |
1334 |
|
* @param rule - Bison grammar rule number |
1335 |
|
* @param stack - reflecting current Bison parser state |
1336 |
|
* @param nextExpectedChars - must already be filled with the characters |
1337 |
|
* expected to be coming next |
1338 |
|
*/ |
1339 |
|
inline static BisonSymbolInfo _symbolInfoForRule(int rule, const std::vector<YYTYPE_INT16>& stack, const String& nextExpectedChars) { |
1340 |
|
BisonSymbolInfo info; |
1341 |
|
info.isTerminalSymbol = _isRuleTerminalSymbol(rule, stack); |
1342 |
|
if (info.isTerminalSymbol) info.nextExpectedChars = nextExpectedChars; |
1343 |
|
return info; |
1344 |
|
} |
1345 |
|
|
1346 |
|
#else // Bison 2.x or older ... |
1347 |
|
|
1348 |
/** |
/** |
1349 |
* Returns true if the given grammar @a rule is a terminal symbol (in *our* |
* Returns true if the given grammar @a rule is a terminal symbol (in *our* |
1350 |
* terms). |
* terms). |
1375 |
|
|
1376 |
/** |
/** |
1377 |
* Returns additional informations to the given grammar @a rule. |
* Returns additional informations to the given grammar @a rule. |
1378 |
|
* |
1379 |
|
* @param rule - grammar rule index to retrieve informations about |
1380 |
|
* @param nextExpectedChars - must already be filled with the characters |
1381 |
|
* expected to be coming next |
1382 |
*/ |
*/ |
1383 |
inline static BisonSymbolInfo _symbolInfoForRule(int rule, const String& nextExpectedChars) { |
inline static BisonSymbolInfo _symbolInfoForRule(int rule, const String& nextExpectedChars) { |
1384 |
BisonSymbolInfo info; |
BisonSymbolInfo info; |
1387 |
return info; |
return info; |
1388 |
} |
} |
1389 |
|
|
1390 |
|
#endif // HAVE_BISON_MAJ >= 3 |
1391 |
|
|
1392 |
/** |
/** |
1393 |
* Returns the human readable name of the given @a token. |
* Returns the human readable name of the given @a token. |
1394 |
*/ |
*/ |
1452 |
if (n <= 0 || n >= YYNRULES) return; // no rule, something is wrong |
if (n <= 0 || n >= YYNRULES) return; // no rule, something is wrong |
1453 |
// return the new resolved expected symbol (left-hand symbol of grammar |
// return the new resolved expected symbol (left-hand symbol of grammar |
1454 |
// rule), then we're done in this state |
// rule), then we're done in this state |
1455 |
|
#if HAVE_BISON_MAJ >= 3 |
1456 |
|
expectedSymbols[yytname[yyr1[n]]] = _symbolInfoForRule(n, stack, nextExpectedChars); |
1457 |
|
#else |
1458 |
expectedSymbols[yytname[yyr1[n]]] = _symbolInfoForRule(n, nextExpectedChars); |
expectedSymbols[yytname[yyr1[n]]] = _symbolInfoForRule(n, nextExpectedChars); |
1459 |
|
#endif |
1460 |
return; |
return; |
1461 |
} |
} |
1462 |
if (!(YYPACT_NINF < n && n <= YYLAST)) return; |
if (!(YYPACT_NINF < n && n <= YYLAST)) return; |
1521 |
#endif |
#endif |
1522 |
if (rule == 0 || rule >= YYNRULES) continue; // invalid rule, something is wrong |
if (rule == 0 || rule >= YYNRULES) continue; // invalid rule, something is wrong |
1523 |
// store the left-hand symbol of the grammar rule |
// store the left-hand symbol of the grammar rule |
1524 |
|
#if HAVE_BISON_MAJ >= 3 |
1525 |
|
expectedSymbols[yytname[yyr1[rule]]] = _symbolInfoForRule(rule, stack, nextExpectedChars); |
1526 |
|
#else |
1527 |
expectedSymbols[yytname[yyr1[rule]]] = _symbolInfoForRule(rule, nextExpectedChars); |
expectedSymbols[yytname[yyr1[rule]]] = _symbolInfoForRule(rule, nextExpectedChars); |
1528 |
|
#endif |
1529 |
#if DEBUG_BISON_SYNTAX_ERROR_WALKER |
#if DEBUG_BISON_SYNTAX_ERROR_WALKER |
1530 |
printf(" (SYM %s) ", yytname[yyr1[rule]]); fflush(stdout); |
printf(" (SYM %s) ", yytname[yyr1[rule]]); fflush(stdout); |
1531 |
#endif |
#endif |