| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #ifndef _PLY_NODE_H
- #define _PLY_NODE_H
- #include <stdint.h>
- #include <stdio.h>
- #include "type.h"
- typedef struct node node_t;
- typedef enum keyword {
- KW_SUBSCRIPT = '[',
- KW_ASSIGN = '=',
- } keyword_t;
- typedef enum ntype {
- N_LIST,
- N_KEYWORD,
- N_IDENT,
- N_NUM,
- N_STRING,
- } ntype_t;
- struct node {
- node_t *next, *prev;
- ntype_t ntype;
- union {
- node_t *list;
- keyword_t keyword;
- char *ident;
- int64_t num;
- char *string;
- };
- type_t *type;
- };
- /* debug */
- void node_print(node_t *n, FILE *fp);
- void node_dump (node_t *n, FILE *fp);
- typedef int (*walk_fn)(node_t *, void *);
- int node_walk(node_t *n, walk_fn pre, walk_fn post, void *ctx);
- /* constructors */
- node_t *node_list (node_t *head);
- node_t *node_vlist (node_t *head, ...);
- node_t *node_keyword(keyword_t keyword);
- node_t *node_ident (char *name);
- node_t *node_num (int64_t num);
- node_t *node_string (char *string);
- static inline node_t *node_head(node_t *n)
- {
- if (!n)
- return NULL;
- for (; n->prev; n = n->prev);
- return n;
- }
- static inline node_t *node_prev(node_t *n)
- {
- return n ? n->prev : NULL;
- }
- static inline node_t *node_next(node_t *n)
- {
- return n ? n->next : NULL;
- }
- #endif /* _PLY_NODE_H */
|