lrama 0.5.3 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1220,26 +1220,30 @@ yydestruct (const char *yymsg,
1220
1220
 
1221
1221
  <%- if output.error_recovery -%>
1222
1222
  #ifndef YYMAXREPAIR
1223
- # define YYMAXREPAIR 3
1223
+ # define YYMAXREPAIR(<%= output.parse_param_name %>) (3)
1224
1224
  #endif
1225
1225
 
1226
- enum repair_type {
1226
+ #ifndef YYERROR_RECOVERY_ENABLED
1227
+ # define YYERROR_RECOVERY_ENABLED(<%= output.parse_param_name %>) (1)
1228
+ #endif
1229
+
1230
+ enum yy_repair_type {
1227
1231
  insert,
1228
1232
  delete,
1229
1233
  shift,
1230
1234
  };
1231
1235
 
1232
- struct repair {
1233
- enum repair_type type;
1236
+ struct yy_repair {
1237
+ enum yy_repair_type type;
1234
1238
  yysymbol_kind_t term;
1235
1239
  };
1236
- typedef struct repair repair;
1240
+ typedef struct yy_repair yy_repair;
1237
1241
 
1238
- struct repairs {
1242
+ struct yy_repairs {
1239
1243
  /* For debug */
1240
1244
  int id;
1241
1245
  /* For breadth-first traversing */
1242
- struct repairs *next;
1246
+ struct yy_repairs *next;
1243
1247
  YYPTRDIFF_T stack_length;
1244
1248
  /* Bottom of states */
1245
1249
  yy_state_t *states;
@@ -1248,10 +1252,10 @@ struct repairs {
1248
1252
  /* repair length */
1249
1253
  int repair_length;
1250
1254
  /* */
1251
- struct repairs *prev_repair;
1252
- struct repair repair;
1255
+ struct yy_repairs *prev_repair;
1256
+ struct yy_repair repair;
1253
1257
  };
1254
- typedef struct repairs repairs;
1258
+ typedef struct yy_repairs yy_repairs;
1255
1259
 
1256
1260
  struct yy_term {
1257
1261
  yysymbol_kind_t kind;
@@ -1260,12 +1264,12 @@ struct yy_term {
1260
1264
  };
1261
1265
  typedef struct yy_term yy_term;
1262
1266
 
1263
- struct repair_terms {
1267
+ struct yy_repair_terms {
1264
1268
  int id;
1265
1269
  int length;
1266
1270
  yy_term terms[];
1267
1271
  };
1268
- typedef struct repair_terms repair_terms;
1272
+ typedef struct yy_repair_terms yy_repair_terms;
1269
1273
 
1270
1274
  static void
1271
1275
  yy_error_token_initialize (yysymbol_kind_t yykind, YYSTYPE * const yyvaluep, YYLTYPE * const yylocationp<%= output.user_formals %>)
@@ -1280,11 +1284,11 @@ switch (yykind)
1280
1284
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1281
1285
  }
1282
1286
 
1283
- static repair_terms *
1284
- yy_create_repair_terms(repairs *reps)
1287
+ static yy_repair_terms *
1288
+ yy_create_repair_terms(yy_repairs *reps<%= output.user_formals %>)
1285
1289
  {
1286
- repairs *r = reps;
1287
- repair_terms *rep_terms;
1290
+ yy_repairs *r = reps;
1291
+ yy_repair_terms *rep_terms;
1288
1292
  int count = 0;
1289
1293
 
1290
1294
  while (r->prev_repair)
@@ -1293,7 +1297,7 @@ yy_create_repair_terms(repairs *reps)
1293
1297
  r = r->prev_repair;
1294
1298
  }
1295
1299
 
1296
- rep_terms = (repair_terms *) malloc (sizeof (repair_terms) + sizeof (yy_term) * count);
1300
+ rep_terms = (yy_repair_terms *) YYMALLOC (sizeof (yy_repair_terms) + sizeof (yy_term) * count);
1297
1301
  rep_terms->id = reps->id;
1298
1302
  rep_terms->length = count;
1299
1303
 
@@ -1309,46 +1313,46 @@ yy_create_repair_terms(repairs *reps)
1309
1313
  }
1310
1314
 
1311
1315
  static void
1312
- yy_print_repairs(repairs *reps)
1316
+ yy_print_repairs(yy_repairs *reps<%= output.user_formals %>)
1313
1317
  {
1314
- repairs *r = reps;
1318
+ yy_repairs *r = reps;
1315
1319
 
1316
- fprintf (stderr,
1320
+ YYDPRINTF ((stderr,
1317
1321
  "id: %d, repair_length: %d, repair_state: %d, prev_repair_id: %d\n",
1318
- reps->id, reps->repair_length, *reps->state, reps->prev_repair->id);
1322
+ reps->id, reps->repair_length, *reps->state, reps->prev_repair->id));
1319
1323
 
1320
1324
  while (r->prev_repair)
1321
1325
  {
1322
- fprintf (stderr, "%s ", yysymbol_name (r->repair.term));
1326
+ YYDPRINTF ((stderr, "%s ", yysymbol_name (r->repair.term)));
1323
1327
  r = r->prev_repair;
1324
1328
  }
1325
1329
 
1326
- fprintf (stderr, "\n");
1330
+ YYDPRINTF ((stderr, "\n"));
1327
1331
  }
1328
1332
 
1329
1333
  static void
1330
- yy_print_repair_terms(repair_terms *rep_terms)
1334
+ yy_print_repair_terms(yy_repair_terms *rep_terms<%= output.user_formals %>)
1331
1335
  {
1332
1336
  for (int i = 0; i < rep_terms->length; i++)
1333
- fprintf (stderr, "%s ", yysymbol_name (rep_terms->terms[i].kind));
1337
+ YYDPRINTF ((stderr, "%s ", yysymbol_name (rep_terms->terms[i].kind)));
1334
1338
 
1335
- fprintf (stderr, "\n");
1339
+ YYDPRINTF ((stderr, "\n"));
1336
1340
  }
1337
1341
 
1338
1342
  static void
1339
- yy_free_repairs(repairs *reps)
1343
+ yy_free_repairs(yy_repairs *reps<%= output.user_formals %>)
1340
1344
  {
1341
1345
  while (reps)
1342
1346
  {
1343
- repairs *r = reps;
1347
+ yy_repairs *r = reps;
1344
1348
  reps = reps->next;
1345
- free (r->states);
1346
- free (r);
1349
+ YYFREE (r->states);
1350
+ YYFREE (r);
1347
1351
  }
1348
1352
  }
1349
1353
 
1350
1354
  static int
1351
- yy_process_repairs(repairs *reps, yysymbol_kind_t token)
1355
+ yy_process_repairs(yy_repairs *reps, yysymbol_kind_t token)
1352
1356
  {
1353
1357
  int yyn;
1354
1358
  int yystate = *reps->state;
@@ -1417,22 +1421,22 @@ yyrecover_errlab:
1417
1421
  return 0;
1418
1422
  }
1419
1423
 
1420
- static repair_terms *
1421
- yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar)
1424
+ static yy_repair_terms *
1425
+ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar<%= output.user_formals %>)
1422
1426
  {
1423
1427
  yysymbol_kind_t yytoken = YYTRANSLATE (yychar);
1424
- repair_terms *rep_terms = YY_NULLPTR;
1428
+ yy_repair_terms *rep_terms = YY_NULLPTR;
1425
1429
  int count = 0;
1426
1430
 
1427
- repairs *head = (repairs *) malloc (sizeof (repairs));
1428
- repairs *current = head;
1429
- repairs *tail = head;
1431
+ yy_repairs *head = (yy_repairs *) YYMALLOC (sizeof (yy_repairs));
1432
+ yy_repairs *current = head;
1433
+ yy_repairs *tail = head;
1430
1434
  YYPTRDIFF_T stack_length = yyssp - yyss + 1;
1431
1435
 
1432
1436
  head->id = count;
1433
1437
  head->next = 0;
1434
1438
  head->stack_length = stack_length;
1435
- head->states = (yy_state_t *) malloc (sizeof (yy_state_t) * (stack_length));
1439
+ head->states = (yy_state_t *) YYMALLOC (sizeof (yy_state_t) * (stack_length));
1436
1440
  head->state = head->states + (yyssp - yyss);
1437
1441
  YYCOPY (head->states, yyss, stack_length);
1438
1442
  head->repair_length = 0;
@@ -1456,14 +1460,14 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar)
1456
1460
  {
1457
1461
  if (yyx != YYSYMBOL_YYerror)
1458
1462
  {
1459
- if (current->repair_length + 1 > YYMAXREPAIR)
1463
+ if (current->repair_length + 1 > YYMAXREPAIR(<%= output.parse_param_name %>))
1460
1464
  continue;
1461
1465
 
1462
- repairs *new = (repairs *) malloc (sizeof (repairs));
1466
+ yy_repairs *new = (yy_repairs *) YYMALLOC (sizeof (yy_repairs));
1463
1467
  new->id = count;
1464
1468
  new->next = 0;
1465
1469
  new->stack_length = stack_length;
1466
- new->states = (yy_state_t *) malloc (sizeof (yy_state_t) * (stack_length));
1470
+ new->states = (yy_state_t *) YYMALLOC (sizeof (yy_state_t) * (stack_length));
1467
1471
  new->state = new->states + (current->state - current->states);
1468
1472
  YYCOPY (new->states, current->states, current->state - current->states + 1);
1469
1473
  new->repair_length = current->repair_length + 1;
@@ -1474,7 +1478,7 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar)
1474
1478
  /* Process PDA assuming next token is yyx */
1475
1479
  if (! yy_process_repairs (new, yyx))
1476
1480
  {
1477
- free (new);
1481
+ YYFREE (new);
1478
1482
  continue;
1479
1483
  }
1480
1484
 
@@ -1484,18 +1488,18 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar)
1484
1488
 
1485
1489
  if (yyx == yytoken)
1486
1490
  {
1487
- rep_terms = yy_create_repair_terms (current);
1488
- fprintf (stderr, "repair_terms found. id: %d, length: %d\n", rep_terms->id, rep_terms->length);
1489
- yy_print_repairs (current);
1490
- yy_print_repair_terms (rep_terms);
1491
+ rep_terms = yy_create_repair_terms (current<%= output.user_args %>);
1492
+ YYDPRINTF ((stderr, "repair_terms found. id: %d, length: %d\n", rep_terms->id, rep_terms->length));
1493
+ yy_print_repairs (current<%= output.user_args %>);
1494
+ yy_print_repair_terms (rep_terms<%= output.user_args %>);
1491
1495
 
1492
1496
  goto done;
1493
1497
  }
1494
1498
 
1495
- fprintf (stderr,
1499
+ YYDPRINTF ((stderr,
1496
1500
  "New repairs is enqueued. count: %d, yystate: %d, yyx: %d\n",
1497
- count, yystate, yyx);
1498
- yy_print_repairs (new);
1501
+ count, yystate, yyx));
1502
+ yy_print_repairs (new<%= output.user_args %>);
1499
1503
  }
1500
1504
  }
1501
1505
  }
@@ -1505,11 +1509,11 @@ yyrecover(yy_state_t *yyss, yy_state_t *yyssp, int yychar)
1505
1509
 
1506
1510
  done:
1507
1511
 
1508
- yy_free_repairs(head);
1512
+ yy_free_repairs(head<%= output.user_args %>);
1509
1513
 
1510
1514
  if (!rep_terms)
1511
1515
  {
1512
- fprintf (stderr, "repair_terms not found\n");
1516
+ YYDPRINTF ((stderr, "repair_terms not found\n"));
1513
1517
  }
1514
1518
 
1515
1519
  return rep_terms;
@@ -1586,7 +1590,7 @@ YYLTYPE yylloc = yyloc_default;
1586
1590
  /* The locations where the error started and ended. */
1587
1591
  YYLTYPE yyerror_range[3];
1588
1592
  <%- if output.error_recovery -%>
1589
- repair_terms *rep_terms = 0;
1593
+ yy_repair_terms *rep_terms = 0;
1590
1594
  yy_term term_backup;
1591
1595
  int rep_terms_index;
1592
1596
  int yychar_backup;
@@ -1726,32 +1730,35 @@ yybackup:
1726
1730
  /* Not known => get a lookahead token if don't already have one. */
1727
1731
 
1728
1732
  <%- if output.error_recovery -%>
1729
- if (yychar == YYEMPTY && rep_terms)
1733
+ if (YYERROR_RECOVERY_ENABLED(<%= output.parse_param_name %>))
1730
1734
  {
1731
-
1732
- if (rep_terms_index < rep_terms->length)
1733
- {
1734
- YYDPRINTF ((stderr, "An error recovery token is used\n"));
1735
- yy_term term = rep_terms->terms[rep_terms_index];
1736
- yytoken = term.kind;
1737
- yylval = term.value;
1738
- yylloc = term.location;
1739
- yychar = yytranslate_inverted[yytoken];
1740
- YY_SYMBOL_PRINT ("Next error recovery token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
1741
- rep_terms_index++;
1742
- }
1743
- else
1735
+ if (yychar == YYEMPTY && rep_terms)
1744
1736
  {
1745
- YYDPRINTF ((stderr, "Error recovery is completed\n"));
1746
- yytoken = term_backup.kind;
1747
- yylval = term_backup.value;
1748
- yylloc = term_backup.location;
1749
- yychar = yychar_backup;
1750
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
1751
-
1752
- free (rep_terms);
1753
- rep_terms = 0;
1754
- yychar_backup = 0;
1737
+
1738
+ if (rep_terms_index < rep_terms->length)
1739
+ {
1740
+ YYDPRINTF ((stderr, "An error recovery token is used\n"));
1741
+ yy_term term = rep_terms->terms[rep_terms_index];
1742
+ yytoken = term.kind;
1743
+ yylval = term.value;
1744
+ yylloc = term.location;
1745
+ yychar = yytranslate_inverted[yytoken];
1746
+ YY_SYMBOL_PRINT ("Next error recovery token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
1747
+ rep_terms_index++;
1748
+ }
1749
+ else
1750
+ {
1751
+ YYDPRINTF ((stderr, "Error recovery is completed\n"));
1752
+ yytoken = term_backup.kind;
1753
+ yylval = term_backup.value;
1754
+ yylloc = term_backup.location;
1755
+ yychar = yychar_backup;
1756
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc<%= output.user_args %>);
1757
+
1758
+ YYFREE (rep_terms);
1759
+ rep_terms = 0;
1760
+ yychar_backup = 0;
1761
+ }
1755
1762
  }
1756
1763
  }
1757
1764
  <%- end -%>
@@ -1980,27 +1987,28 @@ yyerrorlab:
1980
1987
  `-------------------------------------------------------------*/
1981
1988
  yyerrlab1:
1982
1989
  <%- if output.error_recovery -%>
1983
- {
1984
- rep_terms = yyrecover (yyss, yyssp, yychar);
1985
- if (rep_terms)
1986
- {
1987
- for (int i = 0; i < rep_terms->length; i++)
1988
- {
1989
- yy_term *term = &rep_terms->terms[i];
1990
- yy_error_token_initialize (term->kind, &term->value, &term->location<%= output.user_args %>);
1991
- }
1990
+ if (YYERROR_RECOVERY_ENABLED(<%= output.parse_param_name %>))
1991
+ {
1992
+ rep_terms = yyrecover (yyss, yyssp, yychar<%= output.user_args %>);
1993
+ if (rep_terms)
1994
+ {
1995
+ for (int i = 0; i < rep_terms->length; i++)
1996
+ {
1997
+ yy_term *term = &rep_terms->terms[i];
1998
+ yy_error_token_initialize (term->kind, &term->value, &term->location<%= output.user_args %>);
1999
+ }
1992
2000
 
1993
- yychar_backup = yychar;
1994
- /* Can be packed into (the tail of) rep_terms? */
1995
- term_backup.kind = yytoken;
1996
- term_backup.value = yylval;
1997
- term_backup.location = yylloc;
1998
- rep_terms_index = 0;
1999
- yychar = YYEMPTY;
2001
+ yychar_backup = yychar;
2002
+ /* Can be packed into (the tail of) rep_terms? */
2003
+ term_backup.kind = yytoken;
2004
+ term_backup.value = yylval;
2005
+ term_backup.location = yylloc;
2006
+ rep_terms_index = 0;
2007
+ yychar = YYEMPTY;
2000
2008
 
2001
- goto yybackup;
2002
- }
2003
- }
2009
+ goto yybackup;
2010
+ }
2011
+ }
2004
2012
  <%- end -%>
2005
2013
  yyerrstatus = 3; /* Each real token shifted decrements this. */
2006
2014
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lrama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichiro Kaneko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-05 00:00:00.000000000 Z
11
+ date: 2023-08-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LALR (1) parser generator written by Ruby
14
14
  email:
@@ -34,8 +34,15 @@ files:
34
34
  - lib/lrama/bitmap.rb
35
35
  - lib/lrama/command.rb
36
36
  - lib/lrama/context.rb
37
+ - lib/lrama/counterexamples.rb
38
+ - lib/lrama/counterexamples/derivation.rb
39
+ - lib/lrama/counterexamples/example.rb
40
+ - lib/lrama/counterexamples/path.rb
41
+ - lib/lrama/counterexamples/state_item.rb
42
+ - lib/lrama/counterexamples/triple.rb
37
43
  - lib/lrama/digraph.rb
38
44
  - lib/lrama/grammar.rb
45
+ - lib/lrama/grammar/auxiliary.rb
39
46
  - lib/lrama/grammar/code.rb
40
47
  - lib/lrama/grammar/error_token.rb
41
48
  - lib/lrama/grammar/precedence.rb
@@ -46,6 +53,7 @@ files:
46
53
  - lib/lrama/grammar/union.rb
47
54
  - lib/lrama/lexer.rb
48
55
  - lib/lrama/lexer/token.rb
56
+ - lib/lrama/lexer/token/type.rb
49
57
  - lib/lrama/output.rb
50
58
  - lib/lrama/parser.rb
51
59
  - lib/lrama/parser/token_scanner.rb
@@ -54,11 +62,14 @@ files:
54
62
  - lib/lrama/report/profile.rb
55
63
  - lib/lrama/state.rb
56
64
  - lib/lrama/state/reduce.rb
65
+ - lib/lrama/state/reduce_reduce_conflict.rb
57
66
  - lib/lrama/state/resolved_conflict.rb
58
67
  - lib/lrama/state/shift.rb
68
+ - lib/lrama/state/shift_reduce_conflict.rb
59
69
  - lib/lrama/states.rb
60
70
  - lib/lrama/states/item.rb
61
71
  - lib/lrama/states_reporter.rb
72
+ - lib/lrama/type.rb
62
73
  - lib/lrama/version.rb
63
74
  - lib/lrama/warning.rb
64
75
  - lrama.gemspec