inputstream.cpp

来自「用于词法分析的词法分析器」· C++ 代码 · 共 75 行

CPP
75
字号
/*  $Id: InputStream.cpp,v 1.2 1997/02/02 02:10:36 matt Exp $  Input streams class.    Provides higher-level view of an istream-derived object, including  line, column information and meta-state information (word boundary,  line end, etc.)    (c) Jan 96 Matt Phillips.  */#include <ctype.h>#include "InputStream.h"InputStream::InputStream (istream &s, string &fname)  : str (s), filename (fname), current ('\n'), line (0){  get ();			// sets line & col}InputStream::InputStream (istream &s)  : str (s), current ('\n'), line (0){  get ();			// sets line & col}InputStream::InputStream (const InputStream &s) :  str (s.str), line (s.line), col (s.col), filename (s.filename),  current (s.current), prev (s.prev){}void InputStream::get (){  if (!eof ())  {    prev = current;    current = doPeek ();    str.get ();      // update line, col    if (!eof ())    {      if (prev == '\n')      {	line++;	col = 1;      } else	col++;    }  }}unsigned InputStream::getState () const{  unsigned state = InputStream::stClear;  // word boundary  if ((isalnum (prev) != 0) !=      (current != InputStream::EOFChar && isalnum (current) != 0))    state |= InputStream::stWdBoundary;  // end of line  if (current == '\n' || eof ())    state |= stEndLine;  // beginning of line  if (col == 1)    state |= stBegLine;  return state;}

⌨️ 快捷键说明

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