Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 700869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:32:47+00:00 2026-05-14T03:32:47+00:00

I’m programming an interpreter for an experimental programming language (educational, fun,…) So far, everything

  • 0

I’m programming an interpreter for an experimental programming language (educational, fun,…)
So far, everything went well (Tokenizer & Parser), but I’m getting a huge problem with some of the data structures in the part that actually runs the tokenized and parsed code.

My programming language basically has only two types, int and string, and they are represented as C++ strings (std class) and ints

Here is a short version of the data structure that I use to pass values around:

enum DataType
{
  Null,
  Int,
  String
}

class Symbol
{
public:
 string identifier;

 DataType type;
 string stringValue;
 int intValue;
}

I can’t use union because string doesn’t allow me to.

This structure above is beginning to give me a headache.

I have to scatter code like this everywhere in order to make it work, it is beginning to grow unmaintainable:

if( mySymbol.type == Int )
{
  mySymbol.intValue = 1234;
} else {
  mySymbol.stringValue = "abcde";
}

I use the Symbol data structure for variables, return values for functions and general representation of values in the programming language.

  • Is there any better way to solve this? I hope so!
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:32:47+00:00Added an answer on May 14, 2026 at 3:32 am

    The problem comes from the fact, that your symbol class is a type that contains two different types that you are trying to identify through the single type of the class Symbol.

    It would be better to polymorphically create the symbols:

    class Symbol
    {
    public:
        virtual Symbol& operator = (int val) = 0; // Pure virtual
        virtual Symbol& operator = (string val) = 0; // Pure virtual
    private:
        string identifier;
    };
    
    class IntSymbol : public Symbol
    {
    public:
        virtual Symbol& operator = (int val)
        {
            this->val = val;
            return *this; // to make multiple assignments possible
        }
        virtual Symbol& operator = (string val)
        {
            throw new exception("Programm error");
            return *this; // to make it compile
        }
    private:
        int val;
    };
    

    You do the same for the StringSymbol

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 451k
  • Answers 451k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Each method of each class has an implementation. A category… May 15, 2026 at 8:44 pm
  • Editorial Team
    Editorial Team added an answer from http://tomcat.apache.org/tomcat-6.0-doc/logging.html, it would seem that you can manipulate the… May 15, 2026 at 8:44 pm
  • Editorial Team
    Editorial Team added an answer You should specify what "does not work" means. It's important… May 15, 2026 at 8:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.