/* PURPOSE: * FAKE_SCANNER.C: Fake a Lexical Scanner * HISTORY: * Ian D. Allen idallen@freenet.carleton.ca */ //FIXME-- add system includes here //FIXME-- add your local includes here /* FUNCTION: scanner (fake version) * PURPOSE: * This is a fake scanner function. * It returns a sequence of tokens without actually reading any files * or doing any lexical analysis on input. The tokens are initialized * in an array in the function. * * Students may use this to test their parser if they are worried * that their own scanners don't work. */ Token scanner( /* RET: the next Token from the input stream */ void ){ static int tindex = 0; /* index of next token to return */ static Token array[] = { { TT_ID, "someident", 0 }, { TT_EQUAL, "=", 0 }, { TT_UINT, "123", 0 }, { TT_PLUS, "+", 0 }, { TT_UINT, "456", 0 }, { TT_SEMI, ";", 0 }, { TT_EOF, "", 0 }, }; Token *tp; tp = array + tindex++; /* get next token */ if( tindex >= NEL(array) ) tindex = NEL(array) - 1; /* don't go past end */ tp->lineno = tindex; /* fake line number */ #define SCANNER_DEBUG 1 #ifdef SCANNER_DEBUG /* DEBUG: print the token type, lineno, and the lexeme */ eprintf("", token_name(tp->type), tp->lineno, tp->lexeme); #endif /*SCANNER_DEBUG*/ return *tp; /* returns entire structure */ }