S
steve
Hello !
I have a special need implementing a lexical parser. I have a C
restricted grammar, in which I accept such operations as (3<3.5) or
(s<"string"). My problem is that I meet some conception problem. I
would like Yacc to simply operate $$=$1+$3 on my following Node
objects. I tryed to overload operators so that NodeInt n1 < NodeLong n2
automatically get the right values with getValue() function but C++
spec forbids template virtual methods.
Could you please advise a design or a track to unlock me please ?
Thanks in advance,
Steve
class Node {
protected:
int type;
public:
Node();
~Node();
virtual int comparison(Node* n2) = 0;
int operator < (Node& n2); // call comparison(n2)
template <typename T>
virtual T getValue();
};
class NodeString : public Node {
private:
char* s;
public:
NodeString(void* p);
~NodeString();
int comparison(Node* n2); /* may operate
* this->getValue() < n2.getValue()
* strcmp(this->getValue(), n2.getValue())
* strcmp(this->getValue(),
* itoa(n2.getValue()))
*/
char* getValue();
};
class NodeLong : public Node {
private:
long l;
public:
NodeLong(void* p);
~NodeLong();
int comparison(Node* n2);
double getValue();
};
I have a special need implementing a lexical parser. I have a C
restricted grammar, in which I accept such operations as (3<3.5) or
(s<"string"). My problem is that I meet some conception problem. I
would like Yacc to simply operate $$=$1+$3 on my following Node
objects. I tryed to overload operators so that NodeInt n1 < NodeLong n2
automatically get the right values with getValue() function but C++
spec forbids template virtual methods.
Could you please advise a design or a track to unlock me please ?
Thanks in advance,
Steve
class Node {
protected:
int type;
public:
Node();
~Node();
virtual int comparison(Node* n2) = 0;
int operator < (Node& n2); // call comparison(n2)
template <typename T>
virtual T getValue();
};
class NodeString : public Node {
private:
char* s;
public:
NodeString(void* p);
~NodeString();
int comparison(Node* n2); /* may operate
* this->getValue() < n2.getValue()
* strcmp(this->getValue(), n2.getValue())
* strcmp(this->getValue(),
* itoa(n2.getValue()))
*/
char* getValue();
};
class NodeLong : public Node {
private:
long l;
public:
NodeLong(void* p);
~NodeLong();
int comparison(Node* n2);
double getValue();
};