Skip to content
Snippets Groups Projects
RegExpFromStringLexer.cpp 1.37 KiB
Newer Older
  • Learn to ignore specific revisions
  • #include "RegExpFromStringLexer.h"
    
    namespace regexp {
    
    RegExpFromStringLexer::RegExpFromStringLexer(const std::string& in) : m_In(in) {
    	this->next();
    }
    
    RegExpFromStringLexer& RegExpFromStringLexer::next() {
    	char character;
      
    L0:
    	character = m_In.get();
    	if(m_In.eof()) {
    		m_Current.type = TEOF;
    		return *this;
    	} else if(character == ' ' || character == '\n' || character == '\t') {
    		goto L0;
    	} else if((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z') || (character >= '0' && character <= '9')) {
    		m_Current.type = SYMBOL;
    		m_Current.value = character;
    		return *this;
    	} else if(character == '(') {
    		m_Current.type = LPAR;
    		return *this;
    	} else if(character == ')') {
    		m_Current.type = RPAR;
    		return *this;
    	} else if(character == '+') {
    		m_Current.type = PLUS;
    		return *this;
    	} else if(character == '*') {
    		m_Current.type = STAR;
    		return *this;
    	} else if(character == '\\') {
    		goto L1;
    	} else {
    		m_In.unget();
    		m_Current.type = ERROR;
    		return *this;
    	}
    L1:
    	character = m_In.get();
    	if(m_In.eof()) {
    		m_Current.type = ERROR;
    		return *this;
    	} else if(character == 'e') {
    		m_Current.type = EPS;
    		return *this;
    	} else if(character == '0') {
    		m_Current.type = EMPTY;
    		return *this;
    	} else {
    		m_In.unget();
    		m_Current.type = ERROR;
    		return *this;
    	}
    }
    
    RegExpFromStringLexer::Token RegExpFromStringLexer::token() {
    	return m_Current;
    }
    
    }