Line data Source code
1 : #include <iostream> 2 : #include <fstream> 3 : #include <sstream> 4 : #include "compiler/cursor.hpp" 5 : 6 5219 : std::ifstream & operator>>(std::ifstream & s, Cursor & x) { 7 2997 : do { 8 5219 : s >>= x; 9 : // открывающие скобки комментариев 10 5219 : if (x == '/') { 11 28 : s >>= x; 12 28 : if (x == '*') { 13 : // комментарий 14 : while (true) { 15 1916 : s >>= x; 16 : // закрывающие скобки комментариев 17 1916 : if (x == '*') { 18 22 : s >>= x; 19 22 : if (x == '/') { 20 18 : s >> x; 21 18 : break; 22 : } 23 : } 24 : } 25 : } else { 26 10 : s.seekg((int)s.tellg() - 2); 27 10 : s >>= x; 28 : } 29 : } 30 : 31 5219 : } while (((x.c == ' ') || (x.c == '\n')) && (!s.eof())); 32 : 33 2222 : return s; 34 : } 35 : 36 21144 : std::ifstream & operator>>=(std::ifstream & s, Cursor & x) { 37 21144 : s.read( &(x.c), sizeof(char)); 38 : #ifdef DEBUG 39 : std::cout << "cursor " << x.c << std::endl; 40 : #endif 41 21144 : if (x.c == '\n') ++(x.line); 42 21144 : ++(x.pos); 43 21144 : return s; 44 : } 45 : 46 19481 : bool Cursor::operator==(char x) const { 47 19481 : return c == x; 48 : } 49 : 50 11734 : bool Cursor::operator!=(char x) const { 51 11734 : return c != x; 52 : } 53 : 54 9987 : bool Cursor::operator<=(char x) const { 55 9987 : return c <= x; 56 : } 57 : 58 16450 : bool Cursor::operator>=(char x) const { 59 16450 : return c >= x; 60 : } 61 : 62 34 : void Cursor::where(void) const { 63 34 : std::cout << "[строка " << line << "]: "; 64 34 : } 65 : 66 4406 : char Cursor::symbol(void) const { 67 4406 : return c; 68 : } 69 : 70 34 : void Cursor::cite(std::ifstream & s) { 71 34 : std::ostringstream os; 72 482 : while ((*this != '\n') && ((int)s.tellg() > 1)) { 73 448 : s.seekg((int)s.tellg() - 2); 74 448 : s >>= *this; 75 : } 76 34 : if ((int)s.tellg() <= 1) os << this->c; 77 34 : int l = 0, r = 0; 78 671 : do { 79 705 : s >>= *this; 80 705 : os << this->c; 81 705 : if (*this == '{') l++; 82 705 : if (*this == '}') r++; 83 705 : } while ((*this != '\n') && (!s.eof())); 84 34 : std::cout << os.str() << std::endl; 85 34 : line -= 2; 86 34 : }