cast 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,16 +38,16 @@ statement
38
38
 
39
39
  ## Returns Statement
40
40
  labeled_statement
41
- : identifier ':' statement {val[2].labels.unshift(PlainLabel.new_at(val[0].pos, val[0].val)); result = val[2]}
42
- | 'case' constant_expression ':' statement {val[3].labels.unshift(Case .new_at(val[0].pos, val[1] )); result = val[3]}
43
- | 'default' ':' statement {val[2].labels.unshift(Default .new_at(val[0].pos )); result = val[2]}
41
+ : identifier COLON statement {val[2].labels.unshift(PlainLabel.new_at(val[0].pos, val[0].val)); result = val[2]}
42
+ | CASE constant_expression COLON statement {val[3].labels.unshift(Case .new_at(val[0].pos, val[1] )); result = val[3]}
43
+ | DEFAULT COLON statement {val[2].labels.unshift(Default .new_at(val[0].pos )); result = val[2]}
44
44
  ## type names can also be used as labels
45
- | typedef_name ':' statement {val[2].labels.unshift(PlainLabel.new_at(val[0].pos, val[0].name)); result = val[2]}
45
+ | typedef_name COLON statement {val[2].labels.unshift(PlainLabel.new_at(val[0].pos, val[0].name)); result = val[2]}
46
46
 
47
47
  ## Returns Block
48
48
  compound_statement
49
- : '{' block_item_list '}' {result = Block.new_at(val[0].pos, val[1])}
50
- | '{' '}' {result = Block.new_at(val[0].pos )}
49
+ : LBRACE block_item_list RBRACE {result = Block.new_at(val[0].pos, val[1])}
50
+ | LBRACE RBRACE {result = Block.new_at(val[0].pos )}
51
51
 
52
52
  ## Returns NodeChain[Declaration|Statement]
53
53
  block_item_list
@@ -61,48 +61,48 @@ block_item
61
61
 
62
62
  ## Returns ExpressionStatement
63
63
  expression_statement
64
- : expression ';' {result = ExpressionStatement.new_at(val[0].pos, val[0])}
65
- | ';' {result = ExpressionStatement.new_at(val[0].pos )}
64
+ : expression SEMICOLON {result = ExpressionStatement.new_at(val[0].pos, val[0])}
65
+ | SEMICOLON {result = ExpressionStatement.new_at(val[0].pos )}
66
66
 
67
67
  ## Returns Statement
68
68
  selection_statement
69
- : 'if' '(' expression ')' statement {result = If .new_at(val[0].pos, val[2], val[4] )}
70
- | 'if' '(' expression ')' statement 'else' statement {result = If .new_at(val[0].pos, val[2], val[4], val[6])}
71
- | 'switch' '(' expression ')' statement {result = Switch.new_at(val[0].pos, val[2], val[4] )}
69
+ : IF LPAREN expression RPAREN statement {result = If .new_at(val[0].pos, val[2], val[4] )}
70
+ | IF LPAREN expression RPAREN statement ELSE statement {result = If .new_at(val[0].pos, val[2], val[4], val[6])}
71
+ | SWITCH LPAREN expression RPAREN statement {result = Switch.new_at(val[0].pos, val[2], val[4] )}
72
72
 
73
73
  ## Returns Statement
74
74
  iteration_statement
75
- : 'while' '(' expression ')' statement {result = While.new_at(val[0].pos, val[2], val[4] )}
76
- | 'do' statement 'while' '(' expression ')' ';' {result = While.new_at(val[0].pos, val[4], val[1], :do => true )}
77
- | 'for' '(' expression ';' expression ';' expression ')' statement {result = For.new_at(val[0].pos, val[2], val[4], val[6], val[8])}
78
- | 'for' '(' expression ';' expression ';' ')' statement {result = For.new_at(val[0].pos, val[2], val[4], nil , val[7])}
79
- | 'for' '(' expression ';' ';' expression ')' statement {result = For.new_at(val[0].pos, val[2], nil , val[5], val[7])}
80
- | 'for' '(' expression ';' ';' ')' statement {result = For.new_at(val[0].pos, val[2], nil , nil , val[6])}
81
- | 'for' '(' ';' expression ';' expression ')' statement {result = For.new_at(val[0].pos, nil , val[3], val[5], val[7])}
82
- | 'for' '(' ';' expression ';' ')' statement {result = For.new_at(val[0].pos, nil , val[3], nil , val[6])}
83
- | 'for' '(' ';' ';' expression ')' statement {result = For.new_at(val[0].pos, nil , nil , val[4], val[6])}
84
- | 'for' '(' ';' ';' ')' statement {result = For.new_at(val[0].pos, nil , nil , nil , val[5])}
85
- | 'for' '(' declaration expression ';' expression ')' statement {result = For.new_at(val[0].pos, val[2], val[3], val[5], val[7])}
86
- | 'for' '(' declaration expression ';' ')' statement {result = For.new_at(val[0].pos, val[2], val[3], nil , val[6])}
87
- | 'for' '(' declaration ';' expression ')' statement {result = For.new_at(val[0].pos, val[2], nil , val[4], val[6])}
88
- | 'for' '(' declaration ';' ')' statement {result = For.new_at(val[0].pos, val[2], nil , nil , val[5])}
75
+ : WHILE LPAREN expression RPAREN statement {result = While.new_at(val[0].pos, val[2], val[4] )}
76
+ | DO statement WHILE LPAREN expression RPAREN SEMICOLON {result = While.new_at(val[0].pos, val[4], val[1], :do => true )}
77
+ | FOR LPAREN expression SEMICOLON expression SEMICOLON expression RPAREN statement {result = For.new_at(val[0].pos, val[2], val[4], val[6], val[8])}
78
+ | FOR LPAREN expression SEMICOLON expression SEMICOLON RPAREN statement {result = For.new_at(val[0].pos, val[2], val[4], nil , val[7])}
79
+ | FOR LPAREN expression SEMICOLON SEMICOLON expression RPAREN statement {result = For.new_at(val[0].pos, val[2], nil , val[5], val[7])}
80
+ | FOR LPAREN expression SEMICOLON SEMICOLON RPAREN statement {result = For.new_at(val[0].pos, val[2], nil , nil , val[6])}
81
+ | FOR LPAREN SEMICOLON expression SEMICOLON expression RPAREN statement {result = For.new_at(val[0].pos, nil , val[3], val[5], val[7])}
82
+ | FOR LPAREN SEMICOLON expression SEMICOLON RPAREN statement {result = For.new_at(val[0].pos, nil , val[3], nil , val[6])}
83
+ | FOR LPAREN SEMICOLON SEMICOLON expression RPAREN statement {result = For.new_at(val[0].pos, nil , nil , val[4], val[6])}
84
+ | FOR LPAREN SEMICOLON SEMICOLON RPAREN statement {result = For.new_at(val[0].pos, nil , nil , nil , val[5])}
85
+ | FOR LPAREN declaration expression SEMICOLON expression RPAREN statement {result = For.new_at(val[0].pos, val[2], val[3], val[5], val[7])}
86
+ | FOR LPAREN declaration expression SEMICOLON RPAREN statement {result = For.new_at(val[0].pos, val[2], val[3], nil , val[6])}
87
+ | FOR LPAREN declaration SEMICOLON expression RPAREN statement {result = For.new_at(val[0].pos, val[2], nil , val[4], val[6])}
88
+ | FOR LPAREN declaration SEMICOLON RPAREN statement {result = For.new_at(val[0].pos, val[2], nil , nil , val[5])}
89
89
 
90
90
  ## Returns Statement
91
91
  jump_statement
92
- : 'goto' identifier ';' {result = Goto .new_at(val[0].pos, val[1].val)}
93
- | 'continue' ';' {result = Continue.new_at(val[0].pos )}
94
- | 'break' ';' {result = Break .new_at(val[0].pos )}
95
- | 'return' expression ';' {result = Return .new_at(val[0].pos, val[1] )}
96
- | 'return' ';' {result = Return .new_at(val[0].pos )}
92
+ : GOTO identifier SEMICOLON {result = Goto .new_at(val[0].pos, val[1].val)}
93
+ | CONTINUE SEMICOLON {result = Continue.new_at(val[0].pos )}
94
+ | BREAK SEMICOLON {result = Break .new_at(val[0].pos )}
95
+ | RETURN expression SEMICOLON {result = Return .new_at(val[0].pos, val[1] )}
96
+ | RETURN SEMICOLON {result = Return .new_at(val[0].pos )}
97
97
  ## type names can also be used as labels
98
- | 'goto' typedef_name ';' {result = Goto .new_at(val[0].pos, val[1].name)}
98
+ | GOTO typedef_name SEMICOLON {result = Goto .new_at(val[0].pos, val[1].name)}
99
99
 
100
100
  ## A.2.2 Declarations
101
101
 
102
102
  ## Returns Declaration
103
103
  declaration
104
- : declaration_specifiers init_declarator_list ';' {result = make_declaration(val[0][0], val[0][1], val[1])}
105
- | declaration_specifiers ';' {result = make_declaration(val[0][0], val[0][1], NodeArray[])}
104
+ : declaration_specifiers init_declarator_list SEMICOLON {result = make_declaration(val[0][0], val[0][1], val[1])}
105
+ | declaration_specifiers SEMICOLON {result = make_declaration(val[0][0], val[0][1], NodeArray[])}
106
106
 
107
107
  ## Returns {Pos, [Symbol]}
108
108
  declaration_specifiers
@@ -117,53 +117,53 @@ declaration_specifiers
117
117
 
118
118
  ## Returns NodeArray[Declarator]
119
119
  init_declarator_list
120
- : init_declarator {result = NodeArray[val[0]]}
121
- | init_declarator_list ',' init_declarator {result = val[0] << val[2]}
120
+ : init_declarator {result = NodeArray[val[0]]}
121
+ | init_declarator_list COMMA init_declarator {result = val[0] << val[2]}
122
122
 
123
123
  ## Returns Declarator
124
124
  init_declarator
125
- : declarator {result = val[0]}
126
- | declarator '=' initializer {val[0].init = val[2]; result = val[0]}
125
+ : declarator {result = val[0]}
126
+ | declarator EQ initializer {val[0].init = val[2]; result = val[0]}
127
127
 
128
128
  ## Returns [Pos, Symbol]
129
129
  storage_class_specifier
130
- : 'typedef' {result = [val[0].pos, val[0].val]}
131
- | 'extern' {result = [val[0].pos, val[0].val]}
132
- | 'static' {result = [val[0].pos, val[0].val]}
133
- | 'auto' {result = [val[0].pos, val[0].val]}
134
- | 'register' {result = [val[0].pos, val[0].val]}
130
+ : TYPEDEF {result = [val[0].pos, :typedef ]}
131
+ | EXTERN {result = [val[0].pos, :extern ]}
132
+ | STATIC {result = [val[0].pos, :static ]}
133
+ | AUTO {result = [val[0].pos, :auto ]}
134
+ | REGISTER {result = [val[0].pos, :register]}
135
135
 
136
136
  ## Returns [Pos, Type|Symbol]
137
137
  type_specifier
138
- : 'void' {result = [val[0].pos, val[0].val]}
139
- | 'char' {result = [val[0].pos, val[0].val]}
140
- | 'short' {result = [val[0].pos, val[0].val]}
141
- | 'int' {result = [val[0].pos, val[0].val]}
142
- | 'long' {result = [val[0].pos, val[0].val]}
143
- | 'float' {result = [val[0].pos, val[0].val]}
144
- | 'double' {result = [val[0].pos, val[0].val]}
145
- | 'signed' {result = [val[0].pos, val[0].val]}
146
- | 'unsigned' {result = [val[0].pos, val[0].val]}
147
- | '_Bool' {result = [val[0].pos, val[0].val]}
148
- | '_Complex' {result = [val[0].pos, val[0].val]}
149
- | '_Imaginary' {result = [val[0].pos, val[0].val]}
138
+ : VOID {result = [val[0].pos, :void ]}
139
+ | CHAR {result = [val[0].pos, :char ]}
140
+ | SHORT {result = [val[0].pos, :short ]}
141
+ | INT {result = [val[0].pos, :int ]}
142
+ | LONG {result = [val[0].pos, :long ]}
143
+ | FLOAT {result = [val[0].pos, :float ]}
144
+ | DOUBLE {result = [val[0].pos, :double ]}
145
+ | SIGNED {result = [val[0].pos, :signed ]}
146
+ | UNSIGNED {result = [val[0].pos, :unsigned ]}
147
+ | BOOL {result = [val[0].pos, :_Bool ]}
148
+ | COMPLEX {result = [val[0].pos, :_Complex ]}
149
+ | IMAGINARY {result = [val[0].pos, :_Imaginary]}
150
150
  | struct_or_union_specifier {result = [val[0].pos, val[0] ]}
151
151
  | enum_specifier {result = [val[0].pos, val[0] ]}
152
152
  | typedef_name {result = [val[0].pos, val[0] ]}
153
153
 
154
154
  ## Returns Struct|Union
155
155
  struct_or_union_specifier
156
- : struct_or_union identifier '{' struct_declaration_list '}' {result = val[0][1].new_at(val[0][0], val[1].val, val[3])}
157
- | struct_or_union '{' struct_declaration_list '}' {result = val[0][1].new_at(val[0][0], nil , val[2])}
158
- | struct_or_union identifier {result = val[0][1].new_at(val[0][0], val[1].val, nil )}
156
+ : struct_or_union identifier LBRACE struct_declaration_list RBRACE {result = val[0][1].new_at(val[0][0], val[1].val, val[3])}
157
+ | struct_or_union LBRACE struct_declaration_list RBRACE {result = val[0][1].new_at(val[0][0], nil , val[2])}
158
+ | struct_or_union identifier {result = val[0][1].new_at(val[0][0], val[1].val, nil )}
159
159
  ## type names can also be used as struct identifiers
160
- | struct_or_union typedef_name '{' struct_declaration_list '}' {result = val[0][1].new_at(val[0][0], val[1].name, val[3])}
161
- | struct_or_union typedef_name {result = val[0][1].new_at(val[0][0], val[1].name, nil )}
160
+ | struct_or_union typedef_name LBRACE struct_declaration_list RBRACE {result = val[0][1].new_at(val[0][0], val[1].name, val[3])}
161
+ | struct_or_union typedef_name {result = val[0][1].new_at(val[0][0], val[1].name, nil )}
162
162
 
163
163
  ## Returns [Pos, Class]
164
164
  struct_or_union
165
- : 'struct' {result = [val[0].pos, Struct]}
166
- | 'union' {result = [val[0].pos, Union ]}
165
+ : STRUCT {result = [val[0].pos, Struct]}
166
+ | UNION {result = [val[0].pos, Union ]}
167
167
 
168
168
  ## Returns NodeArray[Declaration]
169
169
  struct_declaration_list
@@ -172,7 +172,7 @@ struct_declaration_list
172
172
 
173
173
  ## Returns Declaration
174
174
  struct_declaration
175
- : specifier_qualifier_list struct_declarator_list ';' {result = make_declaration(val[0][0], val[0][1], val[1])}
175
+ : specifier_qualifier_list struct_declarator_list SEMICOLON {result = make_declaration(val[0][0], val[0][1], val[1])}
176
176
 
177
177
  ## Returns {Pos, [Symbol]}
178
178
  specifier_qualifier_list
@@ -183,46 +183,46 @@ specifier_qualifier_list
183
183
 
184
184
  ## Returns NodeArray[Declarator]
185
185
  struct_declarator_list
186
- : struct_declarator {result = NodeArray[val[0]]}
187
- | struct_declarator_list ',' struct_declarator {result = val[0] << val[2]}
186
+ : struct_declarator {result = NodeArray[val[0]]}
187
+ | struct_declarator_list COMMA struct_declarator {result = val[0] << val[2]}
188
188
 
189
189
  ## Returns Declarator
190
190
  struct_declarator
191
- : declarator {result = val[0]}
192
- | declarator ':' constant_expression {result = val[0]; val[0].num_bits = val[2]}
193
- | ':' constant_expression {result = Declarator.new_at(val[0].pos, :num_bits => val[1])}
191
+ : declarator {result = val[0]}
192
+ | declarator COLON constant_expression {result = val[0]; val[0].num_bits = val[2]}
193
+ | COLON constant_expression {result = Declarator.new_at(val[0].pos, :num_bits => val[1])}
194
194
 
195
195
  ## Returns Enum
196
196
  enum_specifier
197
- : 'enum' identifier '{' enumerator_list '}' {result = Enum.new_at(val[0].pos, val[1].val, val[3])}
198
- | 'enum' '{' enumerator_list '}' {result = Enum.new_at(val[0].pos, nil , val[2])}
199
- | 'enum' identifier '{' enumerator_list ',' '}' {result = Enum.new_at(val[0].pos, val[1].val, val[3])}
200
- | 'enum' '{' enumerator_list ',' '}' {result = Enum.new_at(val[0].pos, nil , val[2])}
201
- | 'enum' identifier {result = Enum.new_at(val[0].pos, val[1].val, nil )}
197
+ : ENUM identifier LBRACE enumerator_list RBRACE {result = Enum.new_at(val[0].pos, val[1].val, val[3])}
198
+ | ENUM LBRACE enumerator_list RBRACE {result = Enum.new_at(val[0].pos, nil , val[2])}
199
+ | ENUM identifier LBRACE enumerator_list COMMA RBRACE {result = Enum.new_at(val[0].pos, val[1].val, val[3])}
200
+ | ENUM LBRACE enumerator_list COMMA RBRACE {result = Enum.new_at(val[0].pos, nil , val[2])}
201
+ | ENUM identifier {result = Enum.new_at(val[0].pos, val[1].val, nil )}
202
202
  ## type names can also be used as enum names
203
- | 'enum' typedef_name '{' enumerator_list '}' {result = Enum.new_at(val[0].pos, val[1].name, val[3])}
204
- | 'enum' typedef_name '{' enumerator_list ',' '}' {result = Enum.new_at(val[0].pos, val[1].name, val[3])}
205
- | 'enum' typedef_name {result = Enum.new_at(val[0].pos, val[1].name, nil )}
203
+ | ENUM typedef_name LBRACE enumerator_list RBRACE {result = Enum.new_at(val[0].pos, val[1].name, val[3])}
204
+ | ENUM typedef_name LBRACE enumerator_list COMMA RBRACE {result = Enum.new_at(val[0].pos, val[1].name, val[3])}
205
+ | ENUM typedef_name {result = Enum.new_at(val[0].pos, val[1].name, nil )}
206
206
 
207
207
  ## Returns NodeArray[Enumerator]
208
208
  enumerator_list
209
- : enumerator {result = NodeArray[val[0]]}
210
- | enumerator_list ',' enumerator {result = val[0] << val[2]}
209
+ : enumerator {result = NodeArray[val[0]]}
210
+ | enumerator_list COMMA enumerator {result = val[0] << val[2]}
211
211
 
212
212
  ## Returns Enumerator
213
213
  enumerator
214
- : enumeration_constant {result = Enumerator.new_at(val[0].pos, val[0].val, nil )}
215
- | enumeration_constant '=' constant_expression {result = Enumerator.new_at(val[0].pos, val[0].val, val[2])}
214
+ : enumeration_constant {result = Enumerator.new_at(val[0].pos, val[0].val, nil )}
215
+ | enumeration_constant EQ constant_expression {result = Enumerator.new_at(val[0].pos, val[0].val, val[2])}
216
216
 
217
217
  ## Returns [Pos, Symbol]
218
218
  type_qualifier
219
- : 'const' {result = [val[0].pos, val[0].val]}
220
- | 'restrict' {result = [val[0].pos, val[0].val]}
221
- | 'volatile' {result = [val[0].pos, val[0].val]}
219
+ : CONST {result = [val[0].pos, :const ]}
220
+ | RESTRICT {result = [val[0].pos, :restrict]}
221
+ | VOLATILE {result = [val[0].pos, :volatile]}
222
222
 
223
223
  ## Returns [Pos, Symbol]
224
224
  function_specifier
225
- : 'inline' {result = [val[0].pos, val[0].val]}
225
+ : INLINE {result = [val[0].pos, :inline]}
226
226
 
227
227
  ## Returns Declarator
228
228
  declarator
@@ -231,27 +231,27 @@ declarator
231
231
 
232
232
  ## Returns Declarator
233
233
  direct_declarator
234
- : identifier {result = Declarator.new_at(val[0].pos, nil, val[0].val)}
235
- | '(' declarator ')' {result = val[1]}
236
- | direct_declarator '[' type_qualifier_list assignment_expression ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
237
- | direct_declarator '[' type_qualifier_list ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
238
- | direct_declarator '[' assignment_expression ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos, nil, val[2]))}
239
- | direct_declarator '[' ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))}
240
- | direct_declarator '[' 'static' type_qualifier_list assignment_expression ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
241
- | direct_declarator '[' 'static' assignment_expression ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
242
- | direct_declarator '[' type_qualifier_list 'static' assignment_expression ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
243
- | direct_declarator '[' type_qualifier_list '*' ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
244
- | direct_declarator '[' '*' ']' {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
245
- | direct_declarator '(' parameter_type_list ')' {result = add_decl_type(val[0], Function.new_at(val[0].pos, nil, param_list(*val[2]), :var_args => val[2][1]))}
246
- | direct_declarator '(' identifier_list ')' {result = add_decl_type(val[0], Function.new_at(val[0].pos, nil, val[2]))}
247
- | direct_declarator '(' ')' {result = add_decl_type(val[0], Function.new_at(val[0].pos ))}
234
+ : identifier {result = Declarator.new_at(val[0].pos, nil, val[0].val)}
235
+ | LPAREN declarator RPAREN {result = val[1]}
236
+ | direct_declarator LBRACKET type_qualifier_list assignment_expression RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
237
+ | direct_declarator LBRACKET type_qualifier_list RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
238
+ | direct_declarator LBRACKET assignment_expression RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos, nil, val[2]))}
239
+ | direct_declarator LBRACKET RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))}
240
+ | direct_declarator LBRACKET STATIC type_qualifier_list assignment_expression RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
241
+ | direct_declarator LBRACKET STATIC assignment_expression RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
242
+ | direct_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
243
+ | direct_declarator LBRACKET type_qualifier_list MUL RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
244
+ | direct_declarator LBRACKET MUL RBRACKET {result = add_decl_type(val[0], Array.new_at(val[0].pos ))} # TODO
245
+ | direct_declarator LPAREN parameter_type_list RPAREN {result = add_decl_type(val[0], Function.new_at(val[0].pos, nil, param_list(*val[2]), :var_args => val[2][1]))}
246
+ | direct_declarator LPAREN identifier_list RPAREN {result = add_decl_type(val[0], Function.new_at(val[0].pos, nil, val[2]))}
247
+ | direct_declarator LPAREN RPAREN {result = add_decl_type(val[0], Function.new_at(val[0].pos ))}
248
248
 
249
249
  ## Returns Pointer
250
250
  pointer
251
- : '*' type_qualifier_list {result = add_type_quals(Pointer.new_at(val[0].pos), val[1][1]) }
252
- | '*' {result = Pointer.new_at(val[0].pos) }
253
- | '*' type_qualifier_list pointer {p = add_type_quals(Pointer.new_at(val[0].pos), val[1][1]); val[2].direct_type = p; result = val[2]}
254
- | '*' pointer {p = Pointer.new_at(val[0].pos) ; val[1].direct_type = p; result = val[1]}
251
+ : MUL type_qualifier_list {result = add_type_quals(Pointer.new_at(val[0].pos), val[1][1]) }
252
+ | MUL {result = Pointer.new_at(val[0].pos) }
253
+ | MUL type_qualifier_list pointer {p = add_type_quals(Pointer.new_at(val[0].pos), val[1][1]); val[2].direct_type = p; result = val[2]}
254
+ | MUL pointer {p = Pointer.new_at(val[0].pos) ; val[1].direct_type = p; result = val[1]}
255
255
 
256
256
  ## Returns {Pos, [Symbol]}
257
257
  type_qualifier_list
@@ -260,13 +260,13 @@ type_qualifier_list
260
260
 
261
261
  ## Returns [NodeArray[Parameter], var_args?]
262
262
  parameter_type_list
263
- : parameter_list {result = [val[0], false]}
264
- | parameter_list ',' '...' {result = [val[0], true ]}
263
+ : parameter_list {result = [val[0], false]}
264
+ | parameter_list COMMA ELLIPSIS {result = [val[0], true ]}
265
265
 
266
266
  ## Returns NodeArray[Parameter]
267
267
  parameter_list
268
- : parameter_declaration {result = NodeArray[val[0]]}
269
- | parameter_list ',' parameter_declaration {result = val[0] << val[2]}
268
+ : parameter_declaration {result = NodeArray[val[0]]}
269
+ | parameter_list COMMA parameter_declaration {result = val[0] << val[2]}
270
270
 
271
271
  ## Returns Parameter
272
272
  parameter_declaration
@@ -277,8 +277,8 @@ parameter_declaration
277
277
 
278
278
  ## Returns NodeArray[Parameter]
279
279
  identifier_list
280
- : identifier {result = NodeArray[Parameter.new_at(val[0].pos, nil, val[0].val)]}
281
- | identifier_list ',' identifier {result = val[0] << Parameter.new_at(val[2].pos, nil, val[2].val)}
280
+ : identifier {result = NodeArray[Parameter.new_at(val[0].pos, nil, val[0].val)]}
281
+ | identifier_list COMMA identifier {result = val[0] << Parameter.new_at(val[2].pos, nil, val[2].val)}
282
282
 
283
283
  ## Returns Type
284
284
  type_name
@@ -293,40 +293,40 @@ abstract_declarator
293
293
 
294
294
  ## Returns Type
295
295
  direct_abstract_declarator
296
- : '(' abstract_declarator ')' {result = val[1]}
297
- | direct_abstract_declarator '[' assignment_expression ']' {val[0].direct_type = Array.new_at(val[0].pos, nil, val[2]); result = val[0]}
298
- | direct_abstract_declarator '[' ']' {val[0].direct_type = Array.new_at(val[0].pos, nil, nil ); result = val[0]}
299
- | '[' assignment_expression ']' {result = Array.new_at(val[0].pos, nil, val[1])}
300
- | '[' ']' {result = Array.new_at(val[0].pos )}
301
- | direct_abstract_declarator '[' '*' ']' {val[0].direct_type = Array.new_at(val[0].pos); result = val[0]} # TODO
302
- | '[' '*' ']' {result = Array.new_at(val[0].pos)} # TODO
303
- | direct_abstract_declarator '(' parameter_type_list ')' {val[0].direct_type = Function.new_at(val[0].pos, nil, param_list(*val[2]), val[2][1]); result = val[0]}
304
- | direct_abstract_declarator '(' ')' {val[0].direct_type = Function.new_at(val[0].pos ); result = val[0]}
305
- | '(' parameter_type_list ')' {result = Function.new_at(val[0].pos, nil, param_list(*val[1]), val[1][1])}
306
- | '(' ')' {result = Function.new_at(val[0].pos )}
296
+ : LPAREN abstract_declarator RPAREN {result = val[1]}
297
+ | direct_abstract_declarator LBRACKET assignment_expression RBRACKET {val[0].direct_type = Array.new_at(val[0].pos, nil, val[2]); result = val[0]}
298
+ | direct_abstract_declarator LBRACKET RBRACKET {val[0].direct_type = Array.new_at(val[0].pos, nil, nil ); result = val[0]}
299
+ | LBRACKET assignment_expression RBRACKET {result = Array.new_at(val[0].pos, nil, val[1])}
300
+ | LBRACKET RBRACKET {result = Array.new_at(val[0].pos )}
301
+ | direct_abstract_declarator LBRACKET MUL RBRACKET {val[0].direct_type = Array.new_at(val[0].pos); result = val[0]} # TODO
302
+ | LBRACKET MUL RBRACKET {result = Array.new_at(val[0].pos)} # TODO
303
+ | direct_abstract_declarator LPAREN parameter_type_list RPAREN {val[0].direct_type = Function.new_at(val[0].pos, nil, param_list(*val[2]), val[2][1]); result = val[0]}
304
+ | direct_abstract_declarator LPAREN RPAREN {val[0].direct_type = Function.new_at(val[0].pos ); result = val[0]}
305
+ | LPAREN parameter_type_list RPAREN {result = Function.new_at(val[0].pos, nil, param_list(*val[1]), val[1][1])}
306
+ | LPAREN RPAREN {result = Function.new_at(val[0].pos )}
307
307
 
308
308
  ## Returns CustomType
309
309
  typedef_name
310
310
  #: identifier -- insufficient since we must distinguish between type
311
311
  # names and var names (otherwise we have a conflict)
312
- : TYPE_ID {result = CustomType.new_at(val[0].pos, val[0].val)}
312
+ : TYPENAME {result = CustomType.new_at(val[0].pos, val[0].val)}
313
313
 
314
314
  ## Returns Expression
315
315
  initializer
316
- : assignment_expression {result = val[0]}
317
- | '{' initializer_list '}' {result = CompoundLiteral.new_at(val[0].pos, nil, val[1])}
318
- | '{' initializer_list ',' '}' {result = CompoundLiteral.new_at(val[0].pos, nil, val[1])}
316
+ : assignment_expression {result = val[0]}
317
+ | LBRACE initializer_list RBRACE {result = CompoundLiteral.new_at(val[0].pos, nil, val[1])}
318
+ | LBRACE initializer_list COMMA RBRACE {result = CompoundLiteral.new_at(val[0].pos, nil, val[1])}
319
319
 
320
320
  ## Returns NodeArray[MemberInit]
321
321
  initializer_list
322
- : designation initializer {result = NodeArray[MemberInit.new_at(val[0][0] , val[0][1], val[1])]}
323
- | initializer {result = NodeArray[MemberInit.new_at(val[0].pos, nil , val[0])]}
324
- | initializer_list ',' designation initializer {result = val[0] << MemberInit.new_at(val[2][0] , val[2][1], val[3])}
325
- | initializer_list ',' initializer {result = val[0] << MemberInit.new_at(val[2].pos, nil , val[2])}
322
+ : designation initializer {result = NodeArray[MemberInit.new_at(val[0][0] , val[0][1], val[1])]}
323
+ | initializer {result = NodeArray[MemberInit.new_at(val[0].pos, nil , val[0])]}
324
+ | initializer_list COMMA designation initializer {result = val[0] << MemberInit.new_at(val[2][0] , val[2][1], val[3])}
325
+ | initializer_list COMMA initializer {result = val[0] << MemberInit.new_at(val[2].pos, nil , val[2])}
326
326
 
327
327
  ## Returns {Pos, NodeArray[Expression|Token]}
328
328
  designation
329
- : designator_list '=' {result = val[0]}
329
+ : designator_list EQ {result = val[0]}
330
330
 
331
331
  ## Returns {Pos, NodeArray[Expression|Token]}
332
332
  designator_list
@@ -335,121 +335,126 @@ designator_list
335
335
 
336
336
  ## Returns {Pos, Expression|Member}
337
337
  designator
338
- : '[' constant_expression ']' {result = [val[1].pos, val[1] ]}
339
- | '.' identifier {result = [val[1].pos, Member.new_at(val[1].pos, val[1].val)]}
338
+ : LBRACKET constant_expression RBRACKET {result = [val[1].pos, val[1] ]}
339
+ | DOT identifier {result = [val[1].pos, Member.new_at(val[1].pos, val[1].val)]}
340
340
 
341
341
  ### A.2.1 Expressions
342
342
 
343
343
  ## Returns Expression
344
344
  primary_expression
345
- : identifier {result = Variable.new_at(val[0].pos, val[0].val)}
346
- | constant {result = val[0]}
347
- | string_literal {result = val[0]}
348
- | '(' expression ')' {result = val[1]}
345
+ : identifier {result = Variable.new_at(val[0].pos, val[0].val)}
346
+ | constant {result = val[0]}
347
+ | string_literal {result = val[0]}
348
+ | LPAREN expression RPAREN {result = val[1]}
349
349
 
350
350
  ## Returns Expression
351
351
  postfix_expression
352
- : primary_expression {result = val[0]}
353
- | postfix_expression '[' expression ']' {result = Index .new_at(val[0].pos, val[0], val[2])}
354
- | postfix_expression '(' argument_expression_list ')' {result = Call .new_at(val[0].pos, val[0], val[2] )}
355
- | postfix_expression '(' ')' {result = Call .new_at(val[0].pos, val[0], NodeArray[])}
356
- | postfix_expression '.' identifier {result = Dot .new_at(val[0].pos, val[0], Member.new(val[2].val))}
357
- | postfix_expression '->' identifier {result = Arrow .new_at(val[0].pos, val[0], Member.new(val[2].val))}
358
- | postfix_expression '++' {result = PostInc .new_at(val[0].pos, val[0] )}
359
- | postfix_expression '--' {result = PostDec .new_at(val[0].pos, val[0] )}
360
- | '(' type_name ')' '{' initializer_list '}' {result = CompoundLiteral.new_at(val[0].pos, val[1], val[4])}
361
- | '(' type_name ')' '{' initializer_list ',' '}' {result = CompoundLiteral.new_at(val[0].pos, val[1], val[4])}
362
-
363
- ## Returns [Expression]
352
+ : primary_expression {result = val[0]}
353
+ | postfix_expression LBRACKET expression RBRACKET {result = Index .new_at(val[0].pos, val[0], val[2])}
354
+ | postfix_expression LPAREN argument_expression_list RPAREN {result = Call .new_at(val[0].pos, val[0], val[2] )}
355
+ | postfix_expression LPAREN RPAREN {result = Call .new_at(val[0].pos, val[0], NodeArray[])}
356
+ | postfix_expression DOT identifier {result = Dot .new_at(val[0].pos, val[0], Member.new(val[2].val))}
357
+ | postfix_expression ARROW identifier {result = Arrow .new_at(val[0].pos, val[0], Member.new(val[2].val))}
358
+ | postfix_expression INC {result = PostInc .new_at(val[0].pos, val[0] )}
359
+ | postfix_expression DEC {result = PostDec .new_at(val[0].pos, val[0] )}
360
+ | LPAREN type_name RPAREN LBRACE initializer_list RBRACE {result = CompoundLiteral.new_at(val[0].pos, val[1], val[4])}
361
+ | LPAREN type_name RPAREN LBRACE initializer_list COMMA RBRACE {result = CompoundLiteral.new_at(val[0].pos, val[1], val[4])}
362
+
363
+ ## Returns [Expression|Type] -- allow type names here too -- TODO: add an option to disallow this
364
364
  argument_expression_list
365
- : assignment_expression {result = NodeArray[val[0]]}
366
- | argument_expression_list ',' assignment_expression {result = val[0] << val[2]}
365
+ : argument_expression {result = NodeArray[val[0]]}
366
+ | argument_expression_list COMMA argument_expression {result = val[0] << val[2]}
367
+
368
+ ## Returns Expression|Type
369
+ argument_expression
370
+ : assignment_expression {result = val[0]}
371
+ | type_name {result = val[0]}
367
372
 
368
373
  ## Returns Expression
369
374
  unary_expression
370
375
  : postfix_expression {result = val[0]}
371
- | '++' unary_expression {result = PreInc.new_at(val[0].pos, val[1])}
372
- | '--' unary_expression {result = PreDec.new_at(val[0].pos, val[1])}
376
+ | INC unary_expression {result = PreInc.new_at(val[0].pos, val[1])}
377
+ | DEC unary_expression {result = PreDec.new_at(val[0].pos, val[1])}
373
378
  | unary_operator cast_expression {result = val[0][0].new_at(val[0][1], val[1])}
374
- | 'sizeof' unary_expression {result = Sizeof.new_at(val[0].pos, val[1])}
375
- | 'sizeof' '(' type_name ')' {result = Sizeof.new_at(val[0].pos, val[2])}
379
+ | SIZEOF unary_expression {result = Sizeof.new_at(val[0].pos, val[1])}
380
+ | SIZEOF LPAREN type_name RPAREN {result = Sizeof.new_at(val[0].pos, val[2])}
376
381
 
377
382
  ## Returns [Class, Pos]
378
383
  unary_operator
379
- : '&' {result = [Address , val[0].pos]}
380
- | '*' {result = [Dereference, val[0].pos]}
381
- | '+' {result = [Positive , val[0].pos]}
382
- | '-' {result = [Negative , val[0].pos]}
383
- | '~' {result = [BitNot , val[0].pos]}
384
- | '!' {result = [Not , val[0].pos]}
384
+ : AND {result = [Address , val[0].pos]}
385
+ | MUL {result = [Dereference, val[0].pos]}
386
+ | ADD {result = [Positive , val[0].pos]}
387
+ | SUB {result = [Negative , val[0].pos]}
388
+ | NOT {result = [BitNot , val[0].pos]}
389
+ | BANG {result = [Not , val[0].pos]}
385
390
 
386
391
  ## Returns Expression
387
392
  cast_expression
388
- : unary_expression {result = val[0]}
389
- | '(' type_name ')' cast_expression {result = Cast.new_at(val[0].pos, val[1], val[3])}
393
+ : unary_expression {result = val[0]}
394
+ | LPAREN type_name RPAREN cast_expression {result = Cast.new_at(val[0].pos, val[1], val[3])}
390
395
 
391
396
  ## Returns Expression
392
397
  multiplicative_expression
393
398
  : cast_expression {result = val[0]}
394
- | multiplicative_expression '*' cast_expression {result = Multiply.new_at(val[0].pos, val[0], val[2])}
395
- | multiplicative_expression '/' cast_expression {result = Divide .new_at(val[0].pos, val[0], val[2])}
396
- | multiplicative_expression '%' cast_expression {result = Mod .new_at(val[0].pos, val[0], val[2])}
399
+ | multiplicative_expression MUL cast_expression {result = Multiply.new_at(val[0].pos, val[0], val[2])}
400
+ | multiplicative_expression DIV cast_expression {result = Divide .new_at(val[0].pos, val[0], val[2])}
401
+ | multiplicative_expression MOD cast_expression {result = Mod .new_at(val[0].pos, val[0], val[2])}
397
402
 
398
403
  ## Returns Expression
399
404
  additive_expression
400
405
  : multiplicative_expression {result = val[0]}
401
- | additive_expression '+' multiplicative_expression {result = Add .new_at(val[0].pos, val[0], val[2])}
402
- | additive_expression '-' multiplicative_expression {result = Subtract.new_at(val[0].pos, val[0], val[2])}
406
+ | additive_expression ADD multiplicative_expression {result = Add .new_at(val[0].pos, val[0], val[2])}
407
+ | additive_expression SUB multiplicative_expression {result = Subtract.new_at(val[0].pos, val[0], val[2])}
403
408
 
404
409
  ## Returns Expression
405
410
  shift_expression
406
- : additive_expression {result = val[0]}
407
- | shift_expression '<<' additive_expression {result = ShiftLeft .new_at(val[0].pos, val[0], val[2])}
408
- | shift_expression '>>' additive_expression {result = ShiftRight.new_at(val[0].pos, val[0], val[2])}
411
+ : additive_expression {result = val[0]}
412
+ | shift_expression LSHIFT additive_expression {result = ShiftLeft .new_at(val[0].pos, val[0], val[2])}
413
+ | shift_expression RSHIFT additive_expression {result = ShiftRight.new_at(val[0].pos, val[0], val[2])}
409
414
 
410
415
  ## Returns Expression
411
416
  relational_expression
412
- : shift_expression {result = val[0]}
413
- | relational_expression '<' shift_expression {result = Less.new_at(val[0].pos, val[0], val[2])}
414
- | relational_expression '>' shift_expression {result = More.new_at(val[0].pos, val[0], val[2])}
415
- | relational_expression '<=' shift_expression {result = LessOrEqual.new_at(val[0].pos, val[0], val[2])}
416
- | relational_expression '>=' shift_expression {result = MoreOrEqual.new_at(val[0].pos, val[0], val[2])}
417
+ : shift_expression {result = val[0]}
418
+ | relational_expression LT shift_expression {result = Less.new_at(val[0].pos, val[0], val[2])}
419
+ | relational_expression GT shift_expression {result = More.new_at(val[0].pos, val[0], val[2])}
420
+ | relational_expression LEQ shift_expression {result = LessOrEqual.new_at(val[0].pos, val[0], val[2])}
421
+ | relational_expression GEQ shift_expression {result = MoreOrEqual.new_at(val[0].pos, val[0], val[2])}
417
422
 
418
423
  ## Returns Expression
419
424
  equality_expression
420
- : relational_expression {result = val[0]}
421
- | equality_expression '==' relational_expression {result = Equal .new_at(val[0].pos, val[0], val[2])}
422
- | equality_expression '!=' relational_expression {result = NotEqual.new_at(val[0].pos, val[0], val[2])}
425
+ : relational_expression {result = val[0]}
426
+ | equality_expression EQEQ relational_expression {result = Equal .new_at(val[0].pos, val[0], val[2])}
427
+ | equality_expression NEQ relational_expression {result = NotEqual.new_at(val[0].pos, val[0], val[2])}
423
428
 
424
429
  ## Returns Expression
425
430
  and_expression
426
431
  : equality_expression {result = val[0]}
427
- | and_expression '&' equality_expression {result = BitAnd.new_at(val[0].pos, val[0], val[2])}
432
+ | and_expression AND equality_expression {result = BitAnd.new_at(val[0].pos, val[0], val[2])}
428
433
 
429
434
  ## Returns Expression
430
435
  exclusive_or_expression
431
436
  : and_expression {result = val[0]}
432
- | exclusive_or_expression '^' and_expression {result = BitXor.new_at(val[0].pos, val[0], val[2])}
437
+ | exclusive_or_expression XOR and_expression {result = BitXor.new_at(val[0].pos, val[0], val[2])}
433
438
 
434
439
  ## Returns Expression
435
440
  inclusive_or_expression
436
- : exclusive_or_expression {result = val[0]}
437
- | inclusive_or_expression '|' exclusive_or_expression {result = BitOr.new_at(val[0].pos, val[0], val[2])}
441
+ : exclusive_or_expression {result = val[0]}
442
+ | inclusive_or_expression OR exclusive_or_expression {result = BitOr.new_at(val[0].pos, val[0], val[2])}
438
443
 
439
444
  ## Returns Expression
440
445
  logical_and_expression
441
- : inclusive_or_expression {result = val[0]}
442
- | logical_and_expression '&&' inclusive_or_expression {result = And.new_at(val[0].pos, val[0], val[2])}
446
+ : inclusive_or_expression {result = val[0]}
447
+ | logical_and_expression ANDAND inclusive_or_expression {result = And.new_at(val[0].pos, val[0], val[2])}
443
448
 
444
449
  ## Returns Expression
445
450
  logical_or_expression
446
451
  : logical_and_expression {result = val[0]}
447
- | logical_or_expression '||' logical_and_expression {result = Or.new_at(val[0].pos, val[0], val[2])}
452
+ | logical_or_expression OROR logical_and_expression {result = Or.new_at(val[0].pos, val[0], val[2])}
448
453
 
449
454
  ## Returns Expression
450
455
  conditional_expression
451
- : logical_or_expression {result = val[0]}
452
- | logical_or_expression '?' expression ':' conditional_expression {result = Conditional.new_at(val[0].pos, val[0], val[2], val[4])}
456
+ : logical_or_expression {result = val[0]}
457
+ | logical_or_expression QUESTION expression COLON conditional_expression {result = Conditional.new_at(val[0].pos, val[0], val[2], val[4])}
453
458
 
454
459
  ## Returns Expression
455
460
  assignment_expression
@@ -458,22 +463,22 @@ assignment_expression
458
463
 
459
464
  ## Returns Class
460
465
  assignment_operator
461
- : '=' {result = Assign}
462
- | '*=' {result = MultiplyAssign}
463
- | '/=' {result = DivideAssign}
464
- | '%=' {result = ModAssign}
465
- | '+=' {result = AddAssign}
466
- | '-=' {result = SubtractAssign}
467
- | '<<=' {result = ShiftLeftAssign}
468
- | '>>=' {result = ShiftRightAssign}
469
- | '&=' {result = BitAndAssign}
470
- | '^=' {result = BitXorAssign}
471
- | '|=' {result = BitOrAssign}
466
+ : EQ {result = Assign}
467
+ | MULEQ {result = MultiplyAssign}
468
+ | DIVEQ {result = DivideAssign}
469
+ | MODEQ {result = ModAssign}
470
+ | ADDEQ {result = AddAssign}
471
+ | SUBEQ {result = SubtractAssign}
472
+ | LSHIFTEQ {result = ShiftLeftAssign}
473
+ | RSHIFTEQ {result = ShiftRightAssign}
474
+ | ANDEQ {result = BitAndAssign}
475
+ | XOREQ {result = BitXorAssign}
476
+ | OREQ {result = BitOrAssign}
472
477
 
473
478
  ## Returns Expression
474
479
  expression
475
- : assignment_expression {result = val[0]}
476
- | expression ',' assignment_expression {
480
+ : assignment_expression {result = val[0]}
481
+ | expression COMMA assignment_expression {
477
482
  if val[0].is_a? Comma
478
483
  if val[2].is_a? Comma
479
484
  val[0].exprs.push(*val[2].exprs)
@@ -513,11 +518,11 @@ identifier
513
518
 
514
519
  ## Returns Literal
515
520
  constant
516
- : INT {result = IntLiteral.new_at(val[0].pos, val[0].val)}
517
- | FLOAT {result = FloatLiteral.new_at(val[0].pos, val[0].val)}
521
+ : ICON {result = val[0].val; result.pos = val[0].pos}
522
+ | FCON {result = val[0].val; result.pos = val[0].pos}
518
523
  #| enumeration_constant -- these are parsed as identifiers at all
519
524
  # places the `constant' nonterminal appears
520
- | CHAR {result = CharLiteral.new_at(val[0].pos, val[0].val)}
525
+ | CCON {result = val[0].val; result.pos = val[0].pos}
521
526
 
522
527
  ## Returns Token
523
528
  enumeration_constant
@@ -525,7 +530,7 @@ enumeration_constant
525
530
 
526
531
  ## Returns StringLiteral
527
532
  string_literal
528
- : STRING {result = StringLiteral.new_at(val[0].pos, val[0].val)}
533
+ : SCON {result = val[0].val; result.pos = val[0].pos}
529
534
 
530
535
  ---- inner
531
536
  ## A.1.9 -- Preprocessing numbers -- skip
@@ -581,6 +586,7 @@ restrict return short signed sizeof static struct switch typedef union
581
586
  end
582
587
  @str = str
583
588
  begin
589
+ prepare_lexer(str)
584
590
  return do_parse
585
591
  rescue ParseError => e
586
592
  e.set_backtrace(caller)
@@ -588,13 +594,15 @@ restrict return short signed sizeof static struct switch typedef union
588
594
  end
589
595
  end
590
596
 
591
- ### Obsolete? Todo? What was I thinking?
597
+ ###
598
+ ### Error handler, as used by racc.
599
+ ###
592
600
  def on_error error_token_id, error_value, value_stack
593
601
  if error_value == '$'
594
602
  parse_error @pos, "unexpected EOF"
595
603
  else
596
604
  parse_error(error_value.pos,
597
- "parse error on #{error_value.val.inspect}")
605
+ "parse error on #{error_token_id.inspect}")
598
606
  end
599
607
  end
600
608
 
@@ -616,72 +624,6 @@ restrict return short signed sizeof static struct switch typedef union
616
624
  @pos.col_num = lines[-1].length
617
625
  end
618
626
  end
619
- def next_token
620
- return nil if @str == ''
621
- case @str
622
- when %r'\A\s+'
623
- ## whitespace
624
- eat $&
625
- @str[0...$&.length] = ''
626
- return next_token
627
- when %r'\A/\*.*?\*/'m
628
- ## comment
629
- eat $&
630
- @str[0...$&.length] = ''
631
- return next_token
632
- when %r'\A#{@@keywords}\b'
633
- ## keyword
634
- ret = [$&, $&.to_sym]
635
- when %r'\A#{@@enumeration_constant}'
636
- ## identifier, enumeration_constant, or typedef_name
637
- case
638
- when @type_names.include?($&)
639
- ret = [:TYPE_ID, $&]
640
- else
641
- ret = [:ID, $&]
642
- end
643
- when %r'\A#{@@floating_constant}'
644
- ## floating-constant
645
- ret = [:FLOAT, $&.to_f]
646
- when %r'\A#{@@integer_constant}'
647
- ## integer-constant
648
- ret = [:INT, $&.to_i]
649
- when %r'\A#{@@character_constant}'
650
- ## character constant
651
- ret = [:CHAR, $&[1...-1]]
652
- when %r'\A#{@@string_literal}'
653
- ## string-literal
654
- ret = [:STRING, $&[1...-1]]
655
- when %r'\A#{@@punctuators}'
656
- ## punctuator
657
- ret = [$&, $&]
658
- when %r'\A#{@@digraphs}'
659
- ## digraph
660
- case $&
661
- when '<:'
662
- ret = ['[', '[']
663
- when ':>'
664
- ret = [']', ']']
665
- when '<%'
666
- ret = ['{', '{']
667
- when '%>'
668
- ret = ['}', '}']
669
- else
670
- raise 'bug'
671
- end
672
- else
673
- if @str.length > 40
674
- s = @str[0...37] << '...'
675
- else
676
- s = @str
677
- end
678
- raise ParseError, "#{@pos}: invalid token: #{s.inspect}"
679
- end
680
- ret[1] = Token.new(@pos.dup, ret[1])
681
- eat $&
682
- @str[0...$&.length] = ''
683
- return ret
684
- end
685
627
 
686
628
  private
687
629
 
@@ -775,7 +717,7 @@ restrict return short signed sizeof static struct switch typedef union
775
717
  ## 6.7.1p2: at most, one storage-class specifier may be given in
776
718
  ## the declaration specifiers in a declaration
777
719
  storage_classes.length <= 1 or
778
- "multiple or duplicate storage classes given for `#{declarator.name}'"
720
+ "multiple or duplicate storage classes given for `#{func_declarator.name}'"
779
721
  fd.storage = storage_classes[0] if storage_classes[0]
780
722
 
781
723
  ## set function specifiers