1
#ifndef PARSER_H
2
#define PARSER_H
3
4
/* ast_expr_t */
5
6
typedef enum {
7
EXPR_STRING,
8
EXPR_BINARY,
9
EXPR_INTEGER,
10
} ast_expr_type_t;
11
12
typedef struct ast_expr {
13
ast_expr_type_t type;
14
15
union {
16
char *string;
17
struct {
18
char op;
19
struct ast_expr *a;
20
struct ast_expr *b;
21
} binary;
22
int integer;
23
};
24
25
struct ast_expr *next;
26
char nexttype;
27
} ast_expr_t;
28
29
ast_expr_t *ast_string_alloc(char const *value);
30
ast_expr_t *ast_binary_alloc(char op, ast_expr_t *a, ast_expr_t *b);
31
ast_expr_t *ast_integer_alloc(int i);
32
void ast_expr_pp(ast_expr_t *expr);
33
void ast_expr_free(ast_expr_t *expr);
34
void ast_expr_free_list(ast_expr_t *expr);
35
36
/* ast_comment_t */
37
38
typedef struct {
39
char *value;
40
int is_rem;
41
} ast_comment_t;
42
43
ast_comment_t *ast_comment_alloc(char const *value, int is_rem);
44
void ast_comment_free(ast_comment_t *comment);
45
46
/* ast_token_t */
47
48
typedef struct {
49
char *value;
50
} ast_token_t;
51
52
ast_token_t *ast_token_alloc(char const *value);
53
void ast_token_free(ast_token_t *token);
54
55
/* ast_stmt_t */
56
57
typedef enum {
58
STMT_CALL,
59
STMT_COMMENT,
60
} ast_stmt_type_t;
61
62
typedef struct ast_stmt {
63
ast_stmt_type_t type;
64
65
union {
66
struct {
67
ast_token_t *target;
68
ast_expr_t *args;
69
} call;
70
ast_comment_t *comment;
71
};
72
73
struct ast_stmt *next;
74
} ast_stmt_t;
75
76
ast_stmt_t *ast_stmt_alloc(ast_stmt_type_t type);
77
void ast_stmt_pp(ast_stmt_t *stmt);
78
void ast_stmt_free(ast_stmt_t *stmt);
79
void ast_stmt_free_list(ast_stmt_t *stmt);
80
81
/* ast_t */
82
83
typedef struct {
84
ast_stmt_t *stmts;
85
} ast_t;
86
87
ast_t *ast_alloc(void);
88
void ast_append_stmt(ast_t *ast, ast_stmt_t *stmt);
89
void ast_pp(ast_t *ast);
90
void ast_free(ast_t *ast);
91
92
/* flex/bison */
93
94
int yylex(void);
95
int yyparse(ast_t *ast);
96
int yywrap(void);
97
void yyerror(ast_t *ast, char const *s);
98
99
int parser_test(void);
100
101
/* from lang.l */
102
void begin_scan(char const *s);
103
void finish_scan();
104
105
#endif
106
107
/* vim: set sw=4 et: */
108