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 vyp08 (compiler and interpreter of VYP08 language).
00005  *
00006  * vyp08 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  * vyp08 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 vyp08.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #ifndef SCANNER_H
00021 #define SCANNER_H
00022 
00023 #include "config.h"
00024 
00025 #ifndef BUILDING_DOX
00026 #   include <iostream>
00027 #   include <string>
00028 #endif
00029 
00033 enum EToken {
00034     ETOKEN_NULL = 0,            
00035 
00036     // tokens carrying a value with them
00037     ETOKEN_ID,                  
00038     ETOKEN_NUMBER_INT,          
00039     ETOKEN_NUMBER_DOUBLE,       
00040     ETOKEN_STRING,              
00041 
00042     // operators
00043     ETOKEN_OP_LCBR,             
00044     ETOKEN_OP_RCBR,             
00045     ETOKEN_OP_LPAR,             
00046     ETOKEN_OP_RPAR,             
00047     ETOKEN_OP_STAR,             
00048     ETOKEN_OP_SLASH,            
00049     ETOKEN_OP_PLUS,             
00050     ETOKEN_OP_MINUS,            
00051     ETOKEN_OP_LESS,             
00052     ETOKEN_OP_LESS_EQ,          
00053     ETOKEN_OP_GREATER,          
00054     ETOKEN_OP_GREATER_EQ,       
00055     ETOKEN_OP_ASSIGN,           
00056     ETOKEN_OP_COMMA,            
00057     ETOKEN_OP_SEMICOLON,        
00058 
00059     // keywords
00060     ETOKEN_KW_AND,              
00061     ETOKEN_KW_DIV,              
00062     ETOKEN_KW_DOUBLE,           
00063     ETOKEN_KW_ELSE,             
00064     ETOKEN_KW_EQ,               
00065     ETOKEN_KW_IF,               
00066     ETOKEN_KW_INT,              
00067     ETOKEN_KW_NEQ,              
00068     ETOKEN_KW_NOT,              
00069     ETOKEN_KW_OR,               
00070     ETOKEN_KW_STRING,           
00071     ETOKEN_KW_VAR,              
00072     ETOKEN_KW_VOID,             
00073     ETOKEN_KW_WHILE,            
00074 };
00076 std::ostream& operator<<(std::ostream &, EToken);
00077 
00081 struct Token {
00082     EToken      type;           
00083     int         lineno;         
00084 
00085     int         numberInt;      
00086     double      numberDouble;   
00087     std::string text;           
00088 
00089     Token():
00090         type(ETOKEN_NULL),
00091         lineno(0),
00092         numberInt(0),
00093         numberDouble(0.0)
00094     {
00095     }
00096     Token(EToken type_, int lineno_, int numberInt_, double numberDouble_, const std::string &text_):
00097         type(type_),
00098         lineno(lineno_),
00099         numberInt(numberInt_),
00100         numberDouble(numberDouble_),
00101         text(text_)
00102     {
00103     }
00104 };
00106 std::ostream& operator<<(std::ostream &, const Token &);
00107 
00111 class IErrorSensitive {
00112     public:
00113         virtual ~IErrorSensitive() { }
00117         virtual bool hasError() const = 0;
00118 };
00119 
00123 class IScanner: public IErrorSensitive {
00124     public:
00125         virtual ~IScanner() { }
00131         virtual bool readNext(Token &token) = 0;
00132 };
00133 
00137 class ScannerFactory {
00138     public:
00146         static IScanner* createScanner(std::istream &input, std::string fileName);
00147     private:
00148         ScannerFactory(); 
00149 };
00150 
00151 #endif /* SCANNER_H */

Generated on Sat Jul 4 18:32:59 2009 for vyp08 (compiler and interpreter of VYP08 language) by  doxygen 1.5.4