Aug 23, 2013 at 11:36am UTC
i can't actually understand the error.
can anyone please help me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
#include <iostream>
#include <iomanip>
#include <string>
#include<cstdlib>
using namespace std;
int ns;
int l;
string k[1000];
int count=0;
class genlistnode
{
public :
int flag;
string atom;
genlistnode *next,*down;
};
class Value {
public :
int tag;
float val;
genlistnode* link;
};
class Env {
public :
Value* table[26];
Env* parent;
// the constructor
Env() {
for (int i=0; i<26; i++)
table[i]=NULL;
parent=NULL;
}
};
Value find(char x, Env& e)
{
if (e.table[x-'a' ] != NULL)
{
return *(e.table[x-'a' ]);
}
else {
if (e.parent == NULL) {
cout << "Entry " << x << " not found in symbol table " << endl;
}
else {
cout << " Looking in parent environment " << endl;
return find(x, *(e.parent));
}
}
}
bool is_number(const std::string& s)
{
std::string::const_iterator it = s.begin();
while (it != s.end() && std::isdigit(*it)) ++it;
return !s.empty() && it == s.end();
}
Value evalNode(genlistnode *, Env& );
Value evalList(genlistnode *, Env& );
Value evalNode(genlistnode *u, Env& e) {
if (((u−>atom) =="a" )||((u−>atom)=="b" ))(u−>atom=="c" )||(u−>atom=="d" )||(u−>atom=="e" )||(u−>atom=="f" )||(u−>atom=="g" )||(u−>atom=="h" )||(u−>atom=="i" )||(u−>atom=="j" )||(u−>atom=="u" )||(u−>atom=="t" )||(u−>atom=="s" )||(u−>atom=="r" )||(u−>atom=="q" )||(u−>atom=="p" )||(u−>atom=="o" )||(u−>atom=="n" )||(u−>atom=="m" )||(u−>atom=="l" )||(u−>atom=="k" )||(u−>atom=="v" )||(u−>atom=="w" )||(u−>atom=="x" )||(u−>atom=="y" )||(u−>atom=="z" ))
{return find(x, e);}
else
if (is_number(u->atom))
return (atof(u->atom));
else
if ((u−>flag)==1);
//return(evalList(u− > down, e));
}
This is a part of code,not the complete code.I am working on an evaluator
Last edited on Aug 23, 2013 at 11:49am UTC
Aug 23, 2013 at 12:04pm UTC
Well, if you don't understand it, when you know what the error is, then how can we possibly understand it when you haven't told us what it is!
Aug 23, 2013 at 12:10pm UTC
just run the code,you will know about the error then
Last edited on Aug 23, 2013 at 12:10pm UTC
Aug 23, 2013 at 1:17pm UTC
Yes. Because none of us has anything better to do than spend time compiling and running other posters' code.
HINT: If you want help, help us to help you. Don't make us jump through hoops.
Last edited on Aug 23, 2013 at 1:18pm UTC
Aug 23, 2013 at 2:26pm UTC
#include <cctype>
for std::isdigit
atof(u->atom.c_str() )
not atof(u->atom)
but then you are trying to return the wrong type anyway.
but as MikeyBoy , what is your problem?
Last edited on Aug 23, 2013 at 2:26pm UTC
Aug 23, 2013 at 3:40pm UTC
More visible without fixed-width font:
u−>atom
u->atom
Aug 23, 2013 at 3:44pm UTC
yep, but that spoils the fun. ;0)
Aug 23, 2013 at 3:56pm UTC
In this thread the aim is to help, not to have fun.
Aug 23, 2013 at 4:41pm UTC
Okay LB, whatever.
Last edited on Aug 23, 2013 at 5:15pm UTC
Aug 23, 2013 at 7:53pm UTC
@ Grey Wolf @MikeyBoy @vlad from moscow
I have to submit this assignment by tomorrow.I am actually worried about this.Please help me .. Sorry that I didn't explain about the code.
@Grey Wolf & LB
thanks,you are right
Last edited on Aug 23, 2013 at 8:10pm UTC
Aug 23, 2013 at 8:09pm UTC
If you look at line 73 in the code posted above you have u−>atom when it should be u->atom. it is a very minor looking difference but...
start by deleting the dashes (−) and replacing it with a minus (-) then recompile to see what else is wrong.
Aug 23, 2013 at 8:21pm UTC
And maybe something like if (u->atom.length() == 1 && isalpha(u->atom[0]))
can reduce the length of that if statement?
Edit:
If atom must be lower case try something like this if (u->atom.length() == 1 && isalpha(u->atom[0]) && islower(u->atom[0]))
Last edited on Aug 23, 2013 at 8:28pm UTC
Aug 24, 2013 at 6:06pm UTC
@Grey wolf & naraku9333
Thank you soo much