37 lines
519 B
C
37 lines
519 B
C
#ifndef VISITOR_H
|
|
#define VISITOR_H
|
|
|
|
enum node_type
|
|
{
|
|
// 0 operand
|
|
NUM,
|
|
|
|
// 1 operand
|
|
POS,
|
|
NEG,
|
|
|
|
// 2 operands
|
|
ADD,
|
|
SUB,
|
|
MUL,
|
|
DIV,
|
|
MOD,
|
|
};
|
|
|
|
struct ast_node
|
|
{
|
|
int value;
|
|
enum node_type type;
|
|
struct ast_node *children;
|
|
};
|
|
|
|
typedef void(*visitor)(struct ast_node *);
|
|
|
|
void visit(struct ast_node *node, visitor v);
|
|
|
|
void print_prefix(struct ast_node *node);
|
|
void print_infix(struct ast_node *node);
|
|
void print_suffix(struct ast_node *node);
|
|
|
|
#endif /* ! VISITOR_H */
|