-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimplifiedCplusplusAmbiguity.pm
435 lines (387 loc) · 8.09 KB
/
SimplifiedCplusplusAmbiguity.pm
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
########################################################################################
#
# This file was generated using Parse::Eyapp version 1.178.
#
# (c) Parse::Yapp Copyright 1998-2001 Francois Desarmenien.
# (c) Parse::Eyapp Copyright 2006-2008 Casiano Rodriguez-Leon. Universidad de La Laguna.
# Don't edit this file, use source file 'SimplifiedCplusplusAmbiguity.eyp' instead.
#
# ANY CHANGE MADE HERE WILL BE LOST !
#
########################################################################################
package SimplifiedCplusplusAmbiguity;
use strict;
push @SimplifiedCplusplusAmbiguity::ISA, 'Parse::Eyapp::Driver';
BEGIN {
# This strange way to load the modules is to guarantee compatibility when
# using several standalone and non-standalone Eyapp parsers
require Parse::Eyapp::Driver unless Parse::Eyapp::Driver->can('YYParse');
require Parse::Eyapp::Node unless Parse::Eyapp::Node->can('hnew');
}
sub unexpendedInput { defined($_) ? substr($_, (defined(pos $_) ? pos $_ : 0)) : '' }
# Default lexical analyzer
our $LEX = sub {
my $self = shift;
for (${$self->input}) {
m{\G(\s+)}gc and $self->tokenline($1 =~ tr{\n}{});
m{\G(\(|\+|\;|\)|\=)}gc and return ($1, $1);
/\G(ID)/gc and return ($1, $1);
/\G(NUM)/gc and return ($1, $1);
/\G(INT)/gc and return ($1, $1);
return ('', undef) if ($_ eq '') || (defined(pos($_)) && (pos($_) >= length($_)));
/\G\s*(\S+)/;
my $near = substr($1,0,10);
return($near, $near);
# die( "Error inside the lexical analyzer near '". $near
# ."'. Line: ".$self->line()
# .". File: '".$self->YYFilename()."'. No match found.\n");
}
}
;
#line 63 ./SimplifiedCplusplusAmbiguity.pm
my $warnmessage =<< "EOFWARN";
Warning!: Did you changed the \@SimplifiedCplusplusAmbiguity::ISA variable inside the header section of the eyapp program?
EOFWARN
sub new {
my($class)=shift;
ref($class) and $class=ref($class);
warn $warnmessage unless __PACKAGE__->isa('Parse::Eyapp::Driver');
my($self)=$class->SUPER::new(
yyversion => '1.178',
yyGRAMMAR =>
[#[productionNameAndLabel => lhs, [ rhs], bypass]]
[ '_SUPERSTART' => '$start', [ 'prog', '$end' ], 0 ],
[ 'prog_1' => 'prog', [ ], 0 ],
[ 'prog_2' => 'prog', [ 'prog', 'stmt' ], 0 ],
[ 'stmt_3' => 'stmt', [ 'expr', ';' ], 0 ],
[ 'stmt_4' => 'stmt', [ 'decl' ], 0 ],
[ 'expr_5' => 'expr', [ 'ID' ], 0 ],
[ 'expr_6' => 'expr', [ 'NUM' ], 0 ],
[ 'expr_7' => 'expr', [ 'INT', '(', 'expr', ')' ], 0 ],
[ 'expr_8' => 'expr', [ 'expr', '+', 'expr' ], 0 ],
[ 'expr_9' => 'expr', [ 'expr', '=', 'expr' ], 0 ],
[ 'decl_10' => 'decl', [ 'INT', 'declarator', ';' ], 0 ],
[ 'decl_11' => 'decl', [ 'INT', 'declarator', '=', 'expr', ';' ], 0 ],
[ 'declarator_12' => 'declarator', [ 'ID' ], 0 ],
[ 'declarator_13' => 'declarator', [ '(', 'declarator', ')' ], 0 ],
],
yyLABELS =>
{
'_SUPERSTART' => 0,
'prog_1' => 1,
'prog_2' => 2,
'stmt_3' => 3,
'stmt_4' => 4,
'expr_5' => 5,
'expr_6' => 6,
'expr_7' => 7,
'expr_8' => 8,
'expr_9' => 9,
'decl_10' => 10,
'decl_11' => 11,
'declarator_12' => 12,
'declarator_13' => 13,
},
yyTERMS =>
{ '' => { ISSEMANTIC => 0 },
'(' => { ISSEMANTIC => 0 },
')' => { ISSEMANTIC => 0 },
'+' => { ISSEMANTIC => 0 },
';' => { ISSEMANTIC => 0 },
'=' => { ISSEMANTIC => 0 },
ID => { ISSEMANTIC => 1 },
INT => { ISSEMANTIC => 1 },
NUM => { ISSEMANTIC => 1 },
error => { ISSEMANTIC => 0 },
},
yyFILENAME => 'SimplifiedCplusplusAmbiguity.eyp',
yystates =>
[
{#State 0
DEFAULT => -1,
GOTOS => {
'prog' => 1
}
},
{#State 1
ACTIONS => {
'' => 5,
'ID' => 3,
'NUM' => 2,
'INT' => 8
},
GOTOS => {
'stmt' => 4,
'expr' => 7,
'decl' => 6
}
},
{#State 2
DEFAULT => -6
},
{#State 3
DEFAULT => -5
},
{#State 4
DEFAULT => -2
},
{#State 5
DEFAULT => 0
},
{#State 6
DEFAULT => -4
},
{#State 7
ACTIONS => {
";" => 10,
"+" => 9,
"=" => 11
}
},
{#State 8
ACTIONS => {
'ID' => 12,
"(" => 13
},
GOTOS => {
'declarator' => 14
}
},
{#State 9
ACTIONS => {
'ID' => 3,
'NUM' => 2,
'INT' => 16
},
GOTOS => {
'expr' => 15
}
},
{#State 10
DEFAULT => -3
},
{#State 11
ACTIONS => {
'ID' => 3,
'NUM' => 2,
'INT' => 16
},
GOTOS => {
'expr' => 17
}
},
{#State 12
DEFAULT => -12
},
{#State 13
ACTIONS => {
'ID' => 18,
'NUM' => 2,
"(" => 19,
'INT' => 16
},
GOTOS => {
'expr' => 20,
'declarator' => 21
}
},
{#State 14
ACTIONS => {
";" => 22,
"=" => 23
}
},
{#State 15
ACTIONS => {
";" => -8,
"+" => -8,
")" => -8,
"=" => -8
}
},
{#State 16
ACTIONS => {
"(" => 24
}
},
{#State 17
ACTIONS => {
";" => -9,
"+" => 9,
")" => -9,
"=" => 11
}
},
{#State 18
ACTIONS => {
"+" => -5,
")" => -5,
"=" => -5
}
},
{#State 19
ACTIONS => {
'ID' => 12,
"(" => 19
},
GOTOS => {
'declarator' => 21
}
},
{#State 20
ACTIONS => {
"+" => 9,
")" => 25,
"=" => 11
}
},
{#State 21
ACTIONS => {
")" => 26
}
},
{#State 22
DEFAULT => -10
},
{#State 23
ACTIONS => {
'ID' => 3,
'NUM' => 2,
'INT' => 16
},
GOTOS => {
'expr' => 27
}
},
{#State 24
ACTIONS => {
'ID' => 3,
'NUM' => 2,
'INT' => 16
},
GOTOS => {
'expr' => 20
}
},
{#State 25
DEFAULT => -7
},
{#State 26
DEFAULT => -13
},
{#State 27
ACTIONS => {
";" => 28,
"+" => 9,
"=" => 11
}
},
{#State 28
DEFAULT => -11
}
],
yyrules =>
[
[#Rule _SUPERSTART
'$start', 2, undef
#line 312 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule prog_1
'prog', 0, undef
#line 316 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule prog_2
'prog', 2, undef
#line 320 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule stmt_3
'stmt', 2, undef
#line 324 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule stmt_4
'stmt', 1, undef
#line 328 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule expr_5
'expr', 1, undef
#line 332 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule expr_6
'expr', 1, undef
#line 336 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule expr_7
'expr', 4, undef
#line 340 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule expr_8
'expr', 3, undef
#line 344 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule expr_9
'expr', 3, undef
#line 348 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule decl_10
'decl', 3, undef
#line 352 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule decl_11
'decl', 5, undef
#line 356 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule declarator_12
'declarator', 1, undef
#line 360 ./SimplifiedCplusplusAmbiguity.pm
],
[#Rule declarator_13
'declarator', 3, undef
#line 364 ./SimplifiedCplusplusAmbiguity.pm
]
],
#line 367 ./SimplifiedCplusplusAmbiguity.pm
yybypass => 0,
yybuildingtree => 0,
yyprefix => '',
yyaccessors => {
},
yyconflicthandlers => {}
,
yystateconflict => { },
@_,
);
bless($self,$class);
$self->make_node_classes('TERMINAL', '_OPTIONAL', '_STAR_LIST', '_PLUS_LIST',
'_SUPERSTART',
'prog_1',
'prog_2',
'stmt_3',
'stmt_4',
'expr_5',
'expr_6',
'expr_7',
'expr_8',
'expr_9',
'decl_10',
'decl_11',
'declarator_12',
'declarator_13', );
$self;
}
#line 36 "SimplifiedCplusplusAmbiguity.eyp"
=head1 C++ Ambiguities
This grammar models a problematic part of the C++ grammar — the ambiguity between certain
declarations and statements. For example,
int (x) = y+z;
parses as either an expr or a stmt.
=head1 SEE ALSO
=over 2
=item * L<http://www.gnu.org/software/bison/manual/html_mono/bison.html#GLR-Parsers>
=item * L<http://en.wikipedia.org/wiki/Significantly_Prettier_and_Easier_C%2B%2B_Syntax>
=item * L<http://www.csse.monash.edu.au/~damian/papers/PS/ModestProposal.ps>
=item * L<http://www.nobugs.org/developer/parsingcpp/>
=item * Edward Willink's "Meta-Compilation for C++" PhD thesis at L<http://www.computing.surrey.ac.uk/Research/CSRG/fog/FogThesis.pdf>
=back
=cut
#line 431 ./SimplifiedCplusplusAmbiguity.pm
1;