Lisp Value
There are several ways to deal with errors in C, but in this context my preferred method is to make errors a possible result of evaluating an expression. Then we can say that, in Lispy, an expression will evaluate to either a number, or an error. For example + 1 2
will evaluate to a number, but / 10 0
will evaluate to an error.
For this we need a data structure that can act as either one thing or anything. For simplicity sake we are just going to use a struct
with fields specific to each thing that can be represented, and a special field type
to tell us exactly what fields are meaningful to access.
This we are going to call an lval
, which stands for Lisp Value.
/* Declare New lval Struct */
typedef struct {
int type;
long num;
int err;
} lval;
当前内容版权归 orangeduck 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 orangeduck .