Internals: Add parser debug printer.

This commit is contained in:
Wilson Snyder 2020-06-07 14:07:15 -04:00
parent b469feb44b
commit 30482f3eea
2 changed files with 20 additions and 9 deletions

View File

@ -359,7 +359,8 @@ void V3ParseImp::lexToken() {
|| token == ySTATIC__LEX //
|| token == yVIRTUAL__LEX //
|| token == yWITH__LEX //
// Never put yID_* here; below symbol table resolution would break
// Never put yID_* here; below symbol table resolution would break;
// parser will change symbol table affecting how next ID maybe interpreted
) {
if (debugFlex() >= 6) {
cout << " lexToken: reading ahead to find possible strength" << endl;
@ -488,18 +489,26 @@ int V3ParseImp::lexToBison() {
// yylval.scp = NULL; // Symbol table not yet needed - no packages
if (debugFlex() >= 6 || debugBison() >= 6) { // --debugi-flex and --debugi-bison
cout << " {" << yylval.fl->filenameLetters() << yylval.fl->asciiLineCol()
<< "} lexToBison TOKEN=" << yylval.token << " " << tokenName(yylval.token);
if (yylval.token == yaID__ETC //
|| yylval.token == yaID__LEX //
|| yylval.token == yaID__aPACKAGE || yylval.token == yaID__aTYPE) {
cout << " strp='" << *(yylval.strp) << "'";
}
cout << endl;
cout << "lexToBison " << yylval << endl;
}
return yylval.token;
}
//======================================================================
// V3ParseBisonYYSType functions
std::ostream& operator<<(std::ostream& os, const V3ParseBisonYYSType& rhs) {
os << "TOKEN=" << rhs.token << " " << V3ParseImp::tokenName(rhs.token);
os << " {" << rhs.fl->filenameLetters() << rhs.fl->asciiLineCol() << "}";
if (rhs.token == yaID__ETC //
|| rhs.token == yaID__LEX //
|| rhs.token == yaID__aPACKAGE //
|| rhs.token == yaID__aTYPE) {
os << " strp='" << *(rhs.strp) << "'";
}
return os;
}
//======================================================================
// V3Parse functions

View File

@ -92,6 +92,7 @@ struct V3ParseBisonYYSType {
AstVarRef* varrefp;
};
};
std::ostream& operator<<(std::ostream& os, const V3ParseBisonYYSType& rhs);
#define YYSTYPE V3ParseBisonYYSType
@ -189,6 +190,7 @@ public:
// TODO: Many of these functions are the old interface; they'd be better as non-static
// and called as READP->newString(...) etc.
// These can be called by either parser or lexer, as not lex/parser-position aware
string* newString(const string& text) {
// Allocate a string, remembering it so we can reclaim storage at lex end
string* strp = new string(text);