scanner - result.symbol = OPERATOR; result.lexinfo +=...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// $Id: scanner.cc,v 1.2 2010-01-21 18:22:36-08 - - $ #include <iostream> #include <locale> using namespace std; #include "scanner.h" #include "trace.h" scanner::scanner () { seen_eof = false; advance(); } void scanner::advance () { if (! seen_eof) { cin.get (lookahead); if (cin.eof()) seen_eof = true; } } token_t scanner::scan() { token_t result; while (!seen_eof & isspace (lookahead)) advance(); if (seen_eof) { result.symbol = SCANEOF; }else if (lookahead == '_' || isdigit (lookahead)) { result.symbol = NUMBER; do { result.lexinfo += lookahead; advance(); }while (!seen_eof & isdigit (lookahead)); }else {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: result.symbol = OPERATOR; result.lexinfo += lookahead; advance(); } TRACE ('S', result); return result; } ostream &amp;operator&lt;&lt; (ostream &amp;out, const terminal_symbol &amp;token_t) { switch (token_t) { #define CASE_SYMBOL(SYMBOL) case SYMBOL: out &lt;&lt; #SYMBOL; break; CASE_SYMBOL (NUMBER); CASE_SYMBOL (OPERATOR); CASE_SYMBOL (SCANEOF); } return out; } ostream &amp;operator&lt;&lt; (ostream &amp;out, const token_t &amp;result) { out &lt;&lt; result.symbol &lt;&lt; &quot;: \&quot;&quot; &lt;&lt; result.lexinfo &lt;&lt; &quot;\&quot;&quot;; return out; } RCSC(__scanner_cc__, &quot;$Id: scanner.cc,v 1.2 2010-01-21 18:22:36-08 - - $&quot;)...
View Full Document

Ask a homework question - tutors are online