// ($ sym|lst lst . prg) -> any any doTrace(any x) { any foo, body; outFile *oSave; void (*putSave)(int); cell c1; x = cdr(x); if (isNil(val(Dbg))) return prog(cddr(x)); oSave = OutFile, putSave = Env.put; OutFile = OutFiles[STDERR_FILENO], Env.put = putStdout; foo = car(x); x = cdr(x), body = cdr(x); traceIndent(++Env.trace, foo, " :"); for (x = car(x); isCell(x); x = cdr(x)) space(), print(val(car(x))); if (!isNil(x)) { if (x != At) space(), print(val(x)); else { int i = Env.next; while (--i >= 0) space(), print(data(Env.arg[i])); } } newline(); Env.put = putSave, OutFile = oSave; Push(c1, prog(body)); OutFile = OutFiles[STDERR_FILENO], Env.put = putStdout; traceIndent(Env.trace--, foo, " = "), print(data(c1)); newline(); Env.put = putSave, OutFile = oSave; return Pop(c1); }
void LLkParser::trace(const char* ee, const char* rname) { traceIndent(); cout << ee << rname << ((inputState->guessing>0)?"; [guessing]":"; "); for (int i = 1; i <= k; i++) { if (i != 1) { cout << ", "; } cout << "LA(" << i << ")=="; string temp; try { temp = LT(i)->getText().c_str(); } catch( ANTLRException& ae ) { temp = "[error: "; temp += ae.toString(); temp += ']'; } cout << temp; } cout << endl; }
/**Make sure current lookahead symbol matches token type <tt>t</tt>. * Throw an exception upon mismatch, which is catch by either the * error handler or by the syntactic predicate. */ void Parser::match(int t) { if ( DEBUG_PARSER ) { traceIndent(); ANTLR_USE_NAMESPACE(std)cout << "enter match(" << t << ") with LA(1)=" << LA(1) << ANTLR_USE_NAMESPACE(std)endl; } if ( LA(1)!=t ) { if ( DEBUG_PARSER ) { traceIndent(); ANTLR_USE_NAMESPACE(std)cout << "token mismatch: " << LA(1) << "!=" << t << ANTLR_USE_NAMESPACE(std)endl; } throw MismatchedTokenException(getTokenNames(), getNumTokens(), LT(1), t, false, getFilename()); } else { // mark token as consumed -- fetch next token deferred until LA/LT consume(); } }
/**Make sure current lookahead symbol matches the given set * Throw an exception upon mismatch, which is catch by either the * error handler or by the syntactic predicate. */ void Parser::match(const BitSet& b) { if ( DEBUG_PARSER ) { traceIndent(); ANTLR_USE_NAMESPACE(std)cout << "enter match(" << "bitset" /*b.toString()*/ << ") with LA(1)=" << LA(1) << ANTLR_USE_NAMESPACE(std)endl; } if ( !b.member(LA(1)) ) { if ( DEBUG_PARSER ) { traceIndent(); ANTLR_USE_NAMESPACE(std)cout << "token mismatch: " << LA(1) << " not member of " << "bitset" /*b.toString()*/ << ANTLR_USE_NAMESPACE(std)endl; } throw MismatchedTokenException(getTokenNames(), getNumTokens(), LT(1), b, false, getFilename()); } else { // mark token as consumed -- fetch next token deferred until LA/LT consume(); } }
void LLkParser::trace(const char* ee, const char* rname) { // only show non-guessing (production) calls if(inputState->guessing>0) return; traceIndent(); cout << ee << rname << ((inputState->guessing>0)?"; ?: ":"; <: "); for (int i = 1; i <= k+3; i++) { if (i != 1) { //cout << ", "; cout << " "; } //cout << "LA(" << i << ")=="; string temp; try { temp = LT(i)->getText().c_str(); } catch( ANTLRException& ae ) { temp = "[error: "; temp += ae.toString(); temp += ']'; } if( temp == "\n") cout << "\\n"; else cout << temp; } cout << endl; }