Stuck at symbol translation using C++

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Stuck at symbol translation using C++

onie
Greetings!

I have successfully implemented an assembler without symbol handling capability.
Now, how can I create a symbol table? If I make it an array, then 'R2', 'ARG' will have the same index of '2'. Even a jump may be to this place.
So, should symbol table be a string array? I had dynamically allocated an array of 32768 (32K) elements but I could go no further.

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at symbol translation using C++

cadet1620
Administrator
onie wrote
I have successfully implemented an assembler without symbol handling capability.
Now, how can I create a symbol table? If I make it an array, then 'R2', 'ARG' will have the same index of '2'. Even a jump may be to this place.
You can use a std::map<std::string, int> container.  This container maps strings to integers.  You can visualise it as an array that has std:string's as its indexes and integers as its values.

Here is a tutorial on std::map http://thispointer.com/stdmap-tutorial-part-1-usage-detail-with-examples/

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at symbol translation using C++

onie
Dear Mark Sir,

Thank you for your quick and relevant replies to all my queries. I have completed the part-1 of this course.

By the way, I used a mix of normal and vector strings to complete the project.

Again, sincere thanks. I learned a lot.
Reply | Threaded
Open this post in threaded view
|

Re: Stuck at symbol translation using C++

cadet1620
Administrator
  Congratulations on part 1!


I enjoy helping eager students.  I hope you planning on doing part 2.

--Mark