-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrammar.txt
More file actions
155 lines (101 loc) · 4.88 KB
/
grammar.txt
File metadata and controls
155 lines (101 loc) · 4.88 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
050167
primary_expression = IDENTIFIER | CONSTANT | STRING_LITERAL | '(' expression ')' ;
postfix_expression =
primary_expression |
postfix_expression '[' expression ']' |
postfix_expression '(' [argument_expression_list] ')' |
postfix_expression ('->' | '.') IDENTIFIER |
postfix_expression ('++' | '--')
argument_expression_list = assignment_expression [',' argument_expression_list] ;
unary_expression =
postfix_expression |
('++' | '--') unary_expression |
ÕÕÕ unary_operator unary_expression |
unary_operator ( '(' type_name ')' )+ unary_expression|
SIZEOF ( unary_expression ) | ( '(' type_name ')' ) ;
unary_operator =
'&' | '*' | '+' | '-' | '~' | '!' ;
multiplicative_expression =
cast_expression [('*' | '/' | '%') multiplicative_expression] ;
additive_expression =
multiplicative_expression [('+' | '-') additive_expression] ;
shift_expression =
additive_expression [('<<' | '>>') shift_expression] ;
relational_expression = shift_expression [('<' | '>' | '<=' | '>=') relational_expression] ;
equality_expression = relational_expression [('==' | '!=') equality_expression] ;
and_expression = equality_expression ['&' and_expression] ;
exclusive_or_expression = and_expression ['^' exclusive_or_expression] ;
inclusive_or_expression = exclusive_or_expression ['|' inclusive_or_expression] ;
logical_and_expression = inclusive_or_expression ['&&' logical_and_expression] ;
logical_or_expression = logical_and_expression ['||' logical_or_expression] ;
conditional_expression = logical_or_expression ['?' expression ':' conditional_expression] ;
assignment_expression = conditional_expression | unary_expression assignment_operator assignment_expression ;
assignment_operator =
'=' | '*=' | '/=' | '%=' |
'+=' | '-=' | '<<=' | '>>=' |
'&=' | '^=' | '|=' ;
expression = assignment_expression [',' expression] ;
constant_expression = conditional_expression ;
declaration = declaration_specifiers [init_declarator_list] ';' ;
declaration_specifiers =
type_specifier |
type_specifier declaration_specifiers |
function_specifier |
function_specifier declaration_specifiers ;
init_declarator_list = init_declarator [',' init_declarator_list] ;
init_declarator = declarator ['=' initializer] ;
type_specifier =
VOID | INT | FLOAT | DOUBLE | CHAR |
STRUCT [IDENTIFIER] '{' struct_declaration_list '}' |
STRUCT IDENTIFIER ;
struct_declaration_list = struct_declaration [struct_declaration_list] ;
struct_declaration = type_specifier struct_declarator_list ';' ;
struct_declarator_list = struct_declarator [',' struct_declarator_list] ;
struct_declarator = declarator | [declarator] ':' constant_expression ;
declarator = [pointer] direct_declarator;
direct_declarator =
IDENTIFIER |
'(' declarator ')' |
direct_declarator '[' [assignment_expression] ']' |
direct_declarator '[' ['*'] ']' |
direct_declarator '(' [parameter_list | identifier_list] ')' ;
pointer = '*' [pointer] ;
parameter_list = parameter_declaration {',' parameter_list} ;
parameter_declaration = declaration_specifiers [declarator | abstract_declarator] ;
identifier_list = IDENTIFIER [',' identifier_list] ;
type_name = type_specifier [abstract_declarator] ;
abstract_declarator = pointer | [pointer] direct_abstract_declarator ;
direct_abstract_declarator =
'(' abstract_declarator ')' |
[direct_abstract_declarator] '[' ['*' | assignment_expression] ']' |
[direct_abstract_declarator] '(' [parameter_list] ')' ;
initializer = assignment_expression | '{' initializer_list '}' | '{' initializer_list ',' '}' ;
initializer_list =
initializer_list ',' [designation] initializer |
[designation] initializer ;
designation = designator_list '=' ;
designator_list = designator [designator_list] ;
designator = '[' constant_expression ']' | '.' IDENTIFIER ;
statement =
compound_statement |
expression_statement | selection_statement |
iteration_statement | jump_statement ;
compound_statement = '{' [block_item_list] '}' ;
block_item_list = block_item [block_item_list] ;
block_item = declaration | statement ;
expression_statement = [expression] ';' ;
selection_statement = IF '(' expression ')' statement [ELSE statement] ;
iteration_statement =
WHILE '(' expression ')' statement |
DO statement WHILE '(' expression ')' ';' |
FOR '(' expression_statement expression_statement ')' statement |
FOR '(' expression_statement expression_statement expression ')' statement |
FOR '(' declaration expression_statement ')' statement |
FOR '(' declaration expression_statement expression ')' statement ;
jump_statement =
[CONTINUE | BREAK | RETURN [expression]] ';' ;
translation_unit = external_declaration [translation_unit] ;
external_declaration = function_definition | declaration ;
function_definition =
declaration_specifiers declarator [declaration_list] compound_statement ;
declaration_list = declaration [declaration_list] ;