Whats wrong with this program?

I am trying to make an interpreter. This stack function is supposed to represent the scope of the program, meaning scope of the variables. The START represents a new scope, and FINISH represents the current scope closing. I am trying to do a recursive function in which the stack is updated with each recursive call, which represent a new scope for each call.

Here's whats wrong:

After i enter a new scope and the scope ends, my program prematurely terminates. What do you think is wrong?

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
void stack(ifstream& file,Hash& Table)
{
	string line;

	getline(file,line);

	int i=0;

	for(i=0;isspace(line.at(i))&&i<line.length();i++)
	{}

	while(line.substr(i,6)!="FINISH")
	{
		if(line.substr(i,5)=="START")
		{
			stack(file,Table);
		}

		if(line.substr(i,3)=="VAR")
		{
			int j=i+4;

			for(j=i+4;line.at(j)!='=';j++)
			{}

			int number=stoi(line.substr(j+1,line.length()));

			Table.add(line.substr(i+4,j-(i+4)),number);
		}

		getline(file,line);

		int i=0;

		for(i=0;isspace(line.at(i))&&i<line.length();i++)
		{}
	}
}


Heres my source program i am trying to interpret:

COM HERE IS OUR FIRST BORG PROGRAM
COM WHAT A ROBUST LANGUAGE IT IS
START
VAR BORAMIR=25
VAR LEGOLAS=101
PRINT BORAMIR
BORAMIR++
PRINT LEGOLAS
PRINT GANDALF
PRINT BORAMIR*2
COM
COM NESTED BLOCK
COM
START
VAR GANDALF=49
PRINT GANDALF
PRINT BORAMIR
FINISH
PRINT GANDALF
START
LEGOLAS=1000
PRINT LEGOLAS
FINISH
PRINT LEGOLAS
LEGOLAS--
PRINT LEGOLAS
FINISH
Last edited on
Does line 33 shadow line 7?
hmm maybe thats the problem haha
Topic archived. No new replies allowed.