?? scanner.c
字號:
/* * File: scanner.c * --------------- * This file implements the scanner.h interface. */#include <stdio.h>#include <ctype.h>#include "genlib.h"#include "strlib.h"#include "scanner.h"/* * Private variables * ----------------- * buffer -- Private copy of the string passed to InitScanner * buflen -- Length of the buffer, saved for efficiency * cpos -- Current character position in the buffer */static string buffer;static int buflen;static int cpos;/* * Function: InitScanner * --------------------- * All this function has to do is initialize the private * variables used in the package. */void InitScanner(string line){ buffer = line; buflen = StringLength(buffer); cpos = 0;}/* * Function: GetNextToken * ---------------------- * The implementation of GetNextToken follows its behavioral * description as given in the interface: if the next character * is alphanumeric (i.e., a letter or digit), the function * searches to find an unbroken string of such characters and * returns the entire string. If the current character is not * a letter or digit, a one-character string containing that * character is returned. */string GetNextToken(void){ char ch; int start; if (cpos >= buflen) Error("No more tokens"); ch = IthChar(buffer, cpos); if (isalnum(ch)) { start = cpos; while (cpos < buflen && isalnum(IthChar(buffer, cpos))) { cpos++; } return (SubString(buffer, start, cpos - 1)); } else { cpos++; return (CharToString(ch)); }}/* * Function: AtEndOfLine * --------------------- * This implementation compares the current buffer position * against the saved length. */bool AtEndOfLine(void){ return (cpos >= buflen);}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -