Interpreter introducing in C

I am developing an interpreter, and I have some questions for it.

I recently saw a small C interpreter that used a very simple structure, as shown below for all of its objects / values ​​in the language:

struct Object
{
    ubyte type;
    ubyte value;
};

This structure can contain strings, integers, bools and lists (I think) used in the language the interpreter works with.

  • How can you get this Object structure to hold all of these types?
+3
source share
2 answers

How can you make this object structure hold all of these types?

It does not indicate a value, it simply contains identifiers / references to values ​​that are stored somewhere else.

+2

, sbi, :

struct Object
{
    ubyte type;
    void* value;
};

- , , ubyte type. object.type , , :

useObjectAsString(Object toUse) 
{
    char* data = (char*)toUse.value;
}

, , union.

+1

Source: https://habr.com/ru/post/1747653/


All Articles