| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #ifndef _PLY_NODE_H
- #define _PLY_NODE_H
- #include <stdint.h>
- #include <stdio.h>
- struct sym;
- /* symbol information is defined externally */
- enum ntype {
- N_EXPR,
- N_IDENT,
- N_NUM,
- N_STRING,
- };
- struct node {
- struct node *next, *prev, *up;
- enum ntype ntype;
- union {
- struct {
- char *func;
- struct node *args;
- } expr;
- struct {
- char *name;
- } ident;
- struct {
- int64_t num;
- } num;
- struct {
- char *data;
- } string;
- };
- };
- /* debug */
- void node_print(struct node *n, FILE *fp);
- void node_dump (struct node *n, FILE *fp);
- typedef int (*nwalk_fn)(struct node *, void *);
- int node_walk(struct node *n, nwalk_fn pre, nwalk_fn post, void *ctx);
- int node_replace(struct node *n, struct node *new);
- /* constructors */
- struct node *node_string(char *data);
- struct node *node_num (int64_t num);
- struct node *node_ident (char *name);
- struct node *node_append(struct node *n, struct node *arg);
- struct node *node_expr (char *func, ...);
- /* helpers */
- static inline int node_is_block(struct node *n)
- {
- if (!n || (n->ntype != N_EXPR))
- return 0;
- return n->expr.func[0] == '\0';
- }
- #define node_expr_foreach(_expr, _arg) \
- for ((_arg) = (_expr)->expr.args; (_arg); (_arg) = (_arg)->next)
- #endif /* _PLY_NODE_H */
|