xc
ExprInfija.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //ExprInfija.h
22 
23 #ifndef EXPR_INFIJA_H
24 #define EXPR_INFIJA_H
25 
26 //#include <iostream>
27 #include "Expresion.h"
28 #include <stack>
29 #include <string>
30 
31 class OpBinario;
32 
33 class ExprInfija: public Expresion
34  {
35  private:
36  std::stack<std::string> op_bin_en_espera;
37 
38  void InsertaPalabra(const std::streampos &pos,Segnal *t);
39  std::streampos EncontrarPalabra(const std::streampos &pos,std::istream &is);
40  std::streampos EncontrarNumero(const std::streampos &pos,std::istream &is);
41  std::streampos EncontrarSimbolo(const std::streampos &pos,std::istream &is,int &cta_parent);
42  bool InsertaOpUnario(const std::streampos &pos,Segnal *t);
43  void InsertaOpBinario(const std::streampos &pos,Segnal *t);
44  protected:
45  Segnal *InsertaNuevaPalabra(const std::streampos &pos,const std::string &palabra);
46  Segnal *InsertaNeg(const std::streampos &pos,char op);
47  void CompruebaParentesis( const std::streampos &pos, int &cta, const Segnal *t);
48  virtual void Traduce(std::istream &is);
49  public:
51  ExprInfija(void)
52  : Expresion(), op_bin_en_espera()
53  {}
55  ExprInfija(const std::string &str)
56  : Expresion(), op_bin_en_espera()
57  { Expresion::operator =(str); }
59  ExprInfija(std::istream &is)
60  : Expresion(), op_bin_en_espera()
61  { Traduce(is); }
63  ExprInfija(const ExprInfija &other)
64  : Expresion(other), op_bin_en_espera(other.op_bin_en_espera) {}
66  ExprInfija &operator=(const std::string &str);
67  };
68 
69 #endif
Expresion & operator=(const Expresion &other)
Operador de asignación.
Definition: Expresion.h:56
ExprInfija(std::istream &is)
Constructor.
Definition: ExprInfija.h:59
ExprInfija(void)
Constructor por defecto.
Definition: ExprInfija.h:51
ExprInfija(const ExprInfija &other)
Constructor de copia.
Definition: ExprInfija.h:63
Segnal * InsertaNeg(const std::streampos &pos, char op)
Inserta la palabra que se pasa como parámetro.
Definition: ExprInfija.cc:98
Definition: Expresion.h:31
Componente elemental de una expresión.
Definition: Segnal.h:60
Segnal * InsertaNuevaPalabra(const std::streampos &pos, const std::string &palabra)
Inserta la palabra que se pasa como parámetro.
Definition: ExprInfija.cc:79
Definition: ExprInfija.h:33
Operador binario.
Definition: OpBinario.h:32
virtual void Traduce(std::istream &is)
Convierte la cadena de caracteres contenida en el istream en una expresión.
Definition: ExprInfija.cc:257
ExprInfija(const std::string &str)
Constructor por defecto.
Definition: ExprInfija.h:55
ExprInfija & operator=(const ExprInfija &)
Operador de asignación.
Definition: ExprInfija.cc:33