1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#ifndef PARSE_H
#define PARSE_H
/*
* Basic parsing data structures. Statements and symbols.
*
* Copyright (C) 2003 Linus Torvalds, all rights reserved.
*/
#include "symbol.h"
enum expression_type {
EXPR_CONSTANT,
EXPR_SYMBOL,
EXPR_BINOP,
EXPR_DEREF,
EXPR_PREOP,
EXPR_POSTOP,
EXPR_CAST,
EXPR_SIZEOF,
EXPR_CONDITIONAL,
EXPR_STATEMENT,
};
struct expression {
int type, op;
struct token *token;
union {
struct expression *unop;
struct statement *statement;
struct symbol *symbol;
struct binop_arg {
struct expression *left, *right;
};
struct deref_arg {
struct expression *deref;
struct token *member;
};
struct cast_arg {
struct symbol *cast_type;
struct expression *cast_expression;
};
struct conditional_expr {
struct expression *conditional, *cond_true, *cond_false;
};
struct statement_struct {
struct symbol_list *syms;
struct statement_list *stmts;
};
};
};
enum statement_type {
STMT_NONE,
STMT_EXPRESSION,
STMT_COMPOUND,
STMT_IF,
STMT_RETURN,
STMT_BREAK,
STMT_CONTINUE,
STMT_CASE,
STMT_SWITCH,
STMT_FOR,
STMT_WHILE,
STMT_DO,
STMT_LABEL,
STMT_GOTO,
STMT_ASM,
};
struct statement {
int type;
struct token *token;
struct statement *next;
union {
struct label_arg {
struct token *label;
struct statement *label_statement;
};
struct expression *expression;
struct if_statement {
struct expression *if_conditional;
struct statement *if_true;
struct statement *if_false;
};
struct compound_struct {
struct symbol_list *syms;
struct statement_list *stmts;
};
struct labeled_struct {
struct token *label_identifier;
struct statement *label_statement;
};
struct case_struct {
struct expression *case_expression;
struct expression *case_to;
struct statement *case_statement;
};
struct switch_struct {
struct expression *switch_expression;
struct statement *switch_statement;
};
struct iteration_struct {
struct expression *e1, *e2, *e3;
struct statement *iterate;
};
struct goto_struct {
struct token *goto_label;
struct expression *goto_expression;
};
};
};
extern struct token *parse_expression(struct token *, struct expression **);
extern struct token *statement_list(struct token *, struct statement_list **);
extern void show_statement(struct statement *);
extern void show_statement_list(struct statement_list *, const char *);
extern void show_expression(struct expression *);
extern void translation_unit(struct token *, struct symbol_list **);
#endif /* PARSE_H */
|