Click here to Skip to main content
15,909,530 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HELP!!
I'm currently working on an interpreter (with C++).
to store variables i use arrays of a structure type.
eg. in case of an integer,
C++
typedef struct 
{
char name[10];
int value;
}myInt;
myInt intArray[1000];
int myInt_index=0;
//and when the interpreter reads that an integer is being defined, the following is //executed:
{
intArray[myInt_index].name= *name_specified_by_user*;
intArray[myInt_index].value=(int)*some_value*;
myInt_index++;
}

but this process is not memory efficient and i know there is some better way to do this and i wanna know what it is. Your help will be appreciated. Thanks in advance.
Regards
Ratul

What I have tried:

i tried finding helpon google.... but google is probably not getting what i mean.
Posted
Updated 29-Jun-16 12:51pm
Comments
Sergey Alexandrovich Kryukov 29-Jun-16 12:20pm    
This is too much related to the general design of your product. I suggest that the variables should be stored in some data structure representing contexts of execution. Representing context and scope, and also thread context, for stack variable, is the major design problem, and storing the variables themselves if a secondary one. Its important to understand that the same variable name can be used in the different contexts, so they should be not messed up, kept as separate objects.
—SA
Philippe Mori 30-Jun-16 15:40pm    
Logo might be your kids language... Logo (programming language).
Philippe Mori 30-Jun-16 15:43pm    
You might also download this PDF: Basics of Compiler Design. Once you have read that book or other book on compiler design, you will have an idea on how to do it.

1 solution

Can you make clear what is the language of the interpreter program and what is the interpreted language ? is it C++ for both ?

Quote:
but this process is not memory efficient
Memory efficiency is certainly not the worst problem.
intArray takes only a few kilo bytes when your PC holds a few Giga bytes of of RAM.

As Sergey commented, storing language variables needs much more features than what a simple flat list can offer. Not only this, but the details of the interpreter matters too.

to make an interpreter, you need to use a number of techniques including a compiler. Storing the variables is just one piece of the puzzle.
Compilers: Principles, Techniques, and Tools - Wikipedia, the free encyclopedia[^]

[Update]
Quote:
the language is my own ..lol yeah i'm making a new language for kids with simple syntax.

Your toy language characteristics imply the variables behavior and thus the needed organization to handle variables.
Quote:
Quote:
Only interpreted .. i don't think I'm going to make a compiler. Please suggest the stuff i need to learn.

An interpreter is mainly made of 2 parts
- The first part is in charge of reading kids source code and translate to another form often called Pcode or Intermediate code. This part is a compiler.
- The second part is the one that run the intermediate code.
 
Share this answer
 
v4
Comments
Ratul Thakur 30-Jun-16 9:08am    
the language is my own ..lol yeah i'm making a new language for kids with simple syntax. Only interpreted .. i dont think i'm going to make a compiler. Please suggest the stuff i need to learn.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900