00001 #ifndef __BOOLEANEXPRESSION_H__
00002 #define __BOOLEANEXPRESSION_H__
00003
00004 #pragma once
00005
00006 #include <iostream>
00007 #include <string>
00008 #include <vector>
00009
00010 class BooleanExpression;
00011
00014 std::istream& operator>> (std::istream& in, BooleanExpression& right);
00015
00016 class BooleanExpression{
00017 public:
00020 enum Lexem{
00021 True,
00022 False,
00023 And,
00024 Or,
00025 Xor
00026 };
00027
00028 private:
00029 std::vector<Lexem> expr;
00030
00031 bool lexical_analysis(const std::string& input);
00032 bool semantic_analysis();
00033 bool parse(const std::string& input);
00034 bool valid;
00035
00036 public:
00040 inline bool is_valid(){
00041 return valid;
00042 }
00043
00046 inline void operator<< (const char* input){
00047 parse(std::string(input));
00048 }
00049
00052 inline void operator<< (const std::string& input){
00053 parse(input);
00054 }
00055
00059 inline std::vector<Lexem> to_vector(){
00060 return valid ? expr : std::vector<Lexem>();
00061 }
00062
00063 friend std::istream& operator>> (std::istream& in, BooleanExpression& right);
00064
00067 BooleanExpression() : valid(false) { }
00068 };
00069
00070 #endif
00071