Tuesday, 20 August 2013

passing a substring to a function

passing a substring to a function

I am working on building the LISP interpreter. The problem I am stuck at
is where I need to send the entire substring to a function as soon as I
encounter a "(". For example, if I have,
( begin ( set x 2 ) (set y 3 ) )
then I need to pass
begin ( set x 2 ) (set y 3 ) )
and when I encounter "(" again I need to pass
set x 2 ) (set y 3 ) )
then
set y 3 ) )
I tried doing so with substr by calculating length, but that didn't quite
work. If anyone could help, that'd be great.
Requested code
int a=0;
listnode *makelist(string t) //t is the substring
{
//some code
istringstream iss(t);
string word;
while(iss>>word)
if(word=="(")//I used strcmp here. Just for the sake for time
saving I wrote this
//some operations
int x=word.size();
a=a+x;
word=word.substr(a);
p->down=makelist(word);//function called again and word here should
be the substring
}

No comments:

Post a Comment