⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scanner.c

📁 The art and science of c_source code!
💻 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);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -