Scanner.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
00003  *
00004  * This file is part of fss (Fast SAT Solver).
00005  *
00006  * fss is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * any later version.
00010  *
00011  * fss is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with fss.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #ifndef SCANNER_H
00021 #define SCANNER_H
00022 
00031 # include <iostream>
00032 
00033 namespace FastSatSolver {
00034   class VariableContainer;
00035   class FormulaContainer;
00036 
00044   enum EToken {
00045     T_VARIABLE,           
00046     T_FALSE,              
00047     T_TRUE,               
00048     T_NOT,                
00049     T_AND,                
00050     T_OR,                 
00051     T_XOR,                
00052     T_LPAR,               
00053     T_RPAR,               
00054     T_DELIM,              
00055     T_EOF,                
00056     T_STRING,             
00057 
00058     T_STACK_BOTTOM,       
00059     T_PARSER_EXPR,        
00060     T_PARSER_EQ,          
00061     T_PARSER_LT,          
00062     T_PARSER_GT,          
00063     T_PARSER_INV,         
00064     T_ERR_LEX = -1,       
00065     T_ERR_EXPR = -2,
00066     T_ERR_PARSE = -3
00067   };
00068 
00069 
00074   struct Token {
00075     int           m_line;         
00076 
00077     EToken        m_token;        
00078     int           m_ext_number;   
00079     std::string   m_ext_text;     
00080 
00085     Token() { }
00086 
00091     Token(EToken e): m_line(0), m_token(e), m_ext_number(0) { }
00092   };
00093 
00094   // For debugging and/or error reporting purposes
00095   inline std::ostream& operator<< (std::ostream &stream, EToken e) {
00096     switch (e) {
00097       case T_EOF:         stream << "T_EOF";          break;
00098       case T_FALSE:       stream << "T_FALSE";        break;
00099       case T_TRUE:        stream << "T_TRUE";         break;
00100       case T_NOT:         stream << "T_NOT";          break;
00101       case T_AND:         stream << "T_AND";          break;
00102       case T_OR:          stream << "T_OR";           break;
00103       case T_XOR:         stream << "T_XOR";          break;
00104       case T_LPAR:        stream << "T_LPAR";         break;
00105       case T_RPAR:        stream << "T_RPAR";         break;
00106       case T_DELIM:       stream << "T_DELIM";        break;
00107       case T_STRING:      stream << "T_STRING";       break;
00108       case T_VARIABLE:    stream << "T_VARIABLE";     break;
00109       case T_STACK_BOTTOM:stream << "T_STACK_BOTTOM"; break;
00110       case T_PARSER_EXPR: stream << "T_PARSER_EXPR";  break;
00111       case T_PARSER_EQ:   stream << "T_PARSER_EQ";    break;
00112       case T_PARSER_LT:   stream << "T_PARSER_LT";    break;
00113       case T_PARSER_GT:   stream << "T_PARSER_GT";    break;
00114       case T_PARSER_INV:  stream << "T_PARSER_INV";   break;
00115       case T_ERR_LEX:     stream << "T_ERR_LEX";      break;
00116       case T_ERR_EXPR:    stream << "T_ERR_EXPR";     break;
00117       case T_ERR_PARSE:   stream << "T_ERR_PARSE";    break;
00118       default:            stream << e;                break;
00119     }
00120     return stream;
00121   }
00122 
00123   // For debugging and/or error reporting purposes
00124   inline std::ostream& operator<< (std::ostream &stream, Token token) {
00125     stream << "Token: " << token.m_token << std::endl;
00126     if (token.m_line)
00127       stream << "       At line: " << token.m_line  << std::endl;
00128     if (T_VARIABLE == token.m_token) {
00129       stream << " Variable name: " << token.m_ext_text << std::endl;
00130       stream << "   Vairable id: " << token.m_ext_number << std::endl;
00131     }
00132     return stream;
00133   }
00134 
00141   class IScanner
00142   {
00143     public:
00144       virtual ~IScanner() { }
00145 
00151       virtual int readNext (Token* token ) = 0;
00152   };
00153 
00159   class RawScanner : public IScanner
00160   {
00161     public:
00165       RawScanner (FILE* fd );
00166       virtual ~RawScanner();
00167       
00168       // see IScanner dox
00169       virtual int readNext (Token* token );
00170 
00171     private:
00172       struct Private;
00173       Private *d;
00174   };
00175 
00181   class ScannerStringHandler : public IScanner
00182   {
00183     public:
00188       ScannerStringHandler (IScanner *scanner, VariableContainer *vc );
00189       virtual ~ScannerStringHandler();
00190 
00191       // see IScanner dox
00192       virtual int readNext (Token* token );
00193 
00194     private:
00195       struct Private;
00196       Private *d;
00197   };
00198 
00205   class ScannerFormulaHandler : public IScanner
00206   {
00207     public:
00212       ScannerFormulaHandler (IScanner *scanner, FormulaContainer *fc );
00213       virtual ~ScannerFormulaHandler();
00214 
00215       // see IScanner dox
00216       virtual int readNext (Token* token );
00217 
00218     private:
00219       struct Private;
00220       Private *d;
00221   };
00222 
00223 } // namespace FastSatSolver
00224 
00225 
00226 #endif // SCANNER_H

Generated on Wed Nov 5 22:30:22 2008 for Fast SAT Solver by  doxygen 1.5.4