[prev] [index] [next]

Unions (cont)

One possible representation for the above:

typedef enum { Opr, Val, Var } NodeKindT;

typedef enum { add, sub, mul, div } OperatorT;

typedef struct ExprNode {
	NodeKindT ntype;  // e.g. Opr, Val, Var
        OperatorT opr;    // e.g. add, sub
        char      var[8]; // e.g. "x", "y"
        int       val;    // e.g. 5, -20
	struct ExprNode *left;  // subtree
	struct ExprNode *right; // subtree
} ExprNodeT;