lrama 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yaml +19 -0
  3. data/.gitignore +2 -0
  4. data/Gemfile +6 -3
  5. data/NEWS.md +220 -0
  6. data/README.md +41 -4
  7. data/Rakefile +2 -0
  8. data/Steepfile +6 -17
  9. data/exe/lrama +1 -0
  10. data/lib/lrama/bitmap.rb +2 -0
  11. data/lib/lrama/command.rb +8 -14
  12. data/lib/lrama/context.rb +8 -6
  13. data/lib/lrama/counterexamples/derivation.rb +2 -0
  14. data/lib/lrama/counterexamples/example.rb +2 -0
  15. data/lib/lrama/counterexamples/path.rb +2 -0
  16. data/lib/lrama/counterexamples/production_path.rb +2 -0
  17. data/lib/lrama/counterexamples/start_path.rb +2 -0
  18. data/lib/lrama/counterexamples/state_item.rb +2 -0
  19. data/lib/lrama/counterexamples/transition_path.rb +2 -0
  20. data/lib/lrama/counterexamples/triple.rb +2 -0
  21. data/lib/lrama/counterexamples.rb +17 -15
  22. data/lib/lrama/diagnostics.rb +36 -0
  23. data/lib/lrama/digraph.rb +2 -0
  24. data/lib/lrama/grammar/auxiliary.rb +2 -0
  25. data/lib/lrama/grammar/binding.rb +12 -1
  26. data/lib/lrama/grammar/code/destructor_code.rb +2 -0
  27. data/lib/lrama/grammar/code/initial_action_code.rb +2 -0
  28. data/lib/lrama/grammar/code/no_reference_code.rb +2 -0
  29. data/lib/lrama/grammar/code/printer_code.rb +2 -0
  30. data/lib/lrama/grammar/code/rule_action.rb +7 -3
  31. data/lib/lrama/grammar/code.rb +7 -5
  32. data/lib/lrama/grammar/counter.rb +2 -0
  33. data/lib/lrama/grammar/destructor.rb +2 -0
  34. data/lib/lrama/grammar/error_token.rb +2 -0
  35. data/lib/lrama/grammar/parameterizing_rule/resolver.rb +7 -1
  36. data/lib/lrama/grammar/parameterizing_rule/rhs.rb +5 -2
  37. data/lib/lrama/grammar/parameterizing_rule/rule.rb +6 -0
  38. data/lib/lrama/grammar/parameterizing_rule.rb +2 -0
  39. data/lib/lrama/grammar/percent_code.rb +2 -0
  40. data/lib/lrama/grammar/precedence.rb +2 -0
  41. data/lib/lrama/grammar/printer.rb +2 -0
  42. data/lib/lrama/grammar/reference.rb +2 -0
  43. data/lib/lrama/grammar/rule.rb +10 -3
  44. data/lib/lrama/grammar/rule_builder.rb +64 -65
  45. data/lib/lrama/grammar/symbol.rb +2 -0
  46. data/lib/lrama/grammar/symbols/resolver.rb +5 -1
  47. data/lib/lrama/grammar/symbols.rb +2 -0
  48. data/lib/lrama/grammar/type.rb +2 -0
  49. data/lib/lrama/grammar/union.rb +2 -0
  50. data/lib/lrama/grammar.rb +51 -30
  51. data/lib/lrama/grammar_validator.rb +37 -0
  52. data/lib/lrama/lexer/grammar_file.rb +2 -0
  53. data/lib/lrama/lexer/location.rb +2 -0
  54. data/lib/lrama/lexer/token/char.rb +2 -0
  55. data/lib/lrama/lexer/token/ident.rb +2 -0
  56. data/lib/lrama/lexer/token/instantiate_rule.rb +2 -0
  57. data/lib/lrama/lexer/token/tag.rb +2 -0
  58. data/lib/lrama/lexer/token/user_code.rb +3 -1
  59. data/lib/lrama/lexer/token.rb +7 -5
  60. data/lib/lrama/lexer.rb +11 -8
  61. data/lib/lrama/{warning.rb → logger.rb} +5 -13
  62. data/lib/lrama/option_parser.rb +58 -33
  63. data/lib/lrama/options.rb +5 -2
  64. data/lib/lrama/output.rb +38 -69
  65. data/lib/lrama/parser.rb +650 -779
  66. data/lib/lrama/report/duration.rb +2 -0
  67. data/lib/lrama/report/profile.rb +2 -0
  68. data/lib/lrama/report.rb +4 -2
  69. data/lib/lrama/state/reduce.rb +3 -0
  70. data/lib/lrama/state/reduce_reduce_conflict.rb +2 -0
  71. data/lib/lrama/state/resolved_conflict.rb +3 -1
  72. data/lib/lrama/state/shift.rb +2 -0
  73. data/lib/lrama/state/shift_reduce_conflict.rb +2 -0
  74. data/lib/lrama/state.rb +7 -5
  75. data/lib/lrama/states/item.rb +5 -3
  76. data/lib/lrama/states.rb +18 -46
  77. data/lib/lrama/states_reporter.rb +60 -19
  78. data/lib/lrama/trace_reporter.rb +30 -0
  79. data/lib/lrama/version.rb +3 -1
  80. data/lib/lrama.rb +22 -17
  81. data/lrama.gemspec +3 -1
  82. data/parser.y +110 -229
  83. data/sig/lrama/grammar/auxiliary.rbs +10 -0
  84. data/sig/lrama/grammar/binding.rbs +4 -0
  85. data/sig/lrama/grammar/code/destructor_code.rbs +3 -4
  86. data/sig/lrama/grammar/code/initial_action_code.rbs +15 -0
  87. data/sig/lrama/grammar/code/no_reference_code.rbs +15 -0
  88. data/sig/lrama/grammar/code/printer_code.rbs +3 -4
  89. data/sig/lrama/grammar/code/rule_action.rbs +19 -0
  90. data/sig/lrama/grammar/code.rbs +3 -3
  91. data/sig/lrama/grammar/destructor.rbs +3 -1
  92. data/sig/lrama/grammar/error_token.rbs +4 -2
  93. data/sig/lrama/grammar/parameterizing_rule/resolver.rbs +2 -1
  94. data/sig/lrama/grammar/parameterizing_rule/rhs.rbs +1 -1
  95. data/sig/lrama/grammar/precedence.rbs +3 -1
  96. data/sig/lrama/grammar/printer.rbs +3 -1
  97. data/sig/lrama/grammar/rule.rbs +35 -3
  98. data/sig/lrama/grammar/rule_builder.rbs +10 -9
  99. data/sig/lrama/grammar/symbol.rbs +6 -6
  100. data/sig/lrama/grammar/symbols/resolver.rbs +22 -3
  101. data/sig/lrama/grammar/type.rbs +2 -2
  102. data/sig/lrama/grammar/union.rbs +12 -0
  103. data/sig/lrama/grammar.rbs +91 -1
  104. data/sig/lrama/options.rbs +3 -2
  105. data/sig/lrama/state/reduce.rbs +20 -0
  106. data/sig/lrama/state/reduce_reduce_conflict.rbs +13 -0
  107. data/sig/lrama/state/resolved_conflict.rbs +14 -0
  108. data/sig/lrama/state/shift.rbs +14 -0
  109. data/sig/lrama/state/shift_reduce_conflict.rbs +13 -0
  110. data/sig/lrama/states/item.rbs +30 -0
  111. data/template/bison/yacc.c +24 -19
  112. metadata +17 -6
  113. data/sample/calc.output +0 -263
  114. data/sample/calc.y +0 -101
  115. data/sample/parse.y +0 -59
data/sample/calc.output DELETED
@@ -1,263 +0,0 @@
1
- Grammar
2
-
3
- 0 $accept: list "end of file"
4
-
5
- 1 list: ε
6
- 2 | list LF
7
- 3 | list expr LF
8
-
9
- 4 expr: NUM
10
- 5 | expr '+' expr
11
- 6 | expr '-' expr
12
- 7 | expr '*' expr
13
- 8 | expr '/' expr
14
- 9 | '(' expr ')'
15
-
16
-
17
- State 0
18
-
19
- 0 $accept: • list "end of file"
20
- 1 list: ε •
21
- 2 | • list LF
22
- 3 | • list expr LF
23
-
24
- $default reduce using rule 1 (list)
25
-
26
- list go to state 1
27
-
28
-
29
- State 1
30
-
31
- 0 $accept: list • "end of file"
32
- 2 list: list • LF
33
- 3 | list • expr LF
34
- 4 expr: • NUM
35
- 5 | • expr '+' expr
36
- 6 | • expr '-' expr
37
- 7 | • expr '*' expr
38
- 8 | • expr '/' expr
39
- 9 | • '(' expr ')'
40
-
41
- "end of file" shift, and go to state 2
42
- LF shift, and go to state 3
43
- NUM shift, and go to state 4
44
- '(' shift, and go to state 5
45
-
46
- expr go to state 6
47
-
48
-
49
- State 2
50
-
51
- 0 $accept: list "end of file" •
52
-
53
- $default accept
54
-
55
-
56
- State 3
57
-
58
- 2 list: list LF •
59
-
60
- $default reduce using rule 2 (list)
61
-
62
-
63
- State 4
64
-
65
- 4 expr: NUM •
66
-
67
- $default reduce using rule 4 (expr)
68
-
69
-
70
- State 5
71
-
72
- 4 expr: • NUM
73
- 5 | • expr '+' expr
74
- 6 | • expr '-' expr
75
- 7 | • expr '*' expr
76
- 8 | • expr '/' expr
77
- 9 | • '(' expr ')'
78
- 9 | '(' • expr ')'
79
-
80
- NUM shift, and go to state 4
81
- '(' shift, and go to state 5
82
-
83
- expr go to state 7
84
-
85
-
86
- State 6
87
-
88
- 3 list: list expr • LF
89
- 5 expr: expr • '+' expr
90
- 6 | expr • '-' expr
91
- 7 | expr • '*' expr
92
- 8 | expr • '/' expr
93
-
94
- LF shift, and go to state 8
95
- '+' shift, and go to state 9
96
- '-' shift, and go to state 10
97
- '*' shift, and go to state 11
98
- '/' shift, and go to state 12
99
-
100
-
101
- State 7
102
-
103
- 5 expr: expr • '+' expr
104
- 6 | expr • '-' expr
105
- 7 | expr • '*' expr
106
- 8 | expr • '/' expr
107
- 9 | '(' expr • ')'
108
-
109
- '+' shift, and go to state 9
110
- '-' shift, and go to state 10
111
- '*' shift, and go to state 11
112
- '/' shift, and go to state 12
113
- ')' shift, and go to state 13
114
-
115
-
116
- State 8
117
-
118
- 3 list: list expr LF •
119
-
120
- $default reduce using rule 3 (list)
121
-
122
-
123
- State 9
124
-
125
- 4 expr: • NUM
126
- 5 | • expr '+' expr
127
- 5 | expr '+' • expr
128
- 6 | • expr '-' expr
129
- 7 | • expr '*' expr
130
- 8 | • expr '/' expr
131
- 9 | • '(' expr ')'
132
-
133
- NUM shift, and go to state 4
134
- '(' shift, and go to state 5
135
-
136
- expr go to state 14
137
-
138
-
139
- State 10
140
-
141
- 4 expr: • NUM
142
- 5 | • expr '+' expr
143
- 6 | • expr '-' expr
144
- 6 | expr '-' • expr
145
- 7 | • expr '*' expr
146
- 8 | • expr '/' expr
147
- 9 | • '(' expr ')'
148
-
149
- NUM shift, and go to state 4
150
- '(' shift, and go to state 5
151
-
152
- expr go to state 15
153
-
154
-
155
- State 11
156
-
157
- 4 expr: • NUM
158
- 5 | • expr '+' expr
159
- 6 | • expr '-' expr
160
- 7 | • expr '*' expr
161
- 7 | expr '*' • expr
162
- 8 | • expr '/' expr
163
- 9 | • '(' expr ')'
164
-
165
- NUM shift, and go to state 4
166
- '(' shift, and go to state 5
167
-
168
- expr go to state 16
169
-
170
-
171
- State 12
172
-
173
- 4 expr: • NUM
174
- 5 | • expr '+' expr
175
- 6 | • expr '-' expr
176
- 7 | • expr '*' expr
177
- 8 | • expr '/' expr
178
- 8 | expr '/' • expr
179
- 9 | • '(' expr ')'
180
-
181
- NUM shift, and go to state 4
182
- '(' shift, and go to state 5
183
-
184
- expr go to state 17
185
-
186
-
187
- State 13
188
-
189
- 9 expr: '(' expr ')' •
190
-
191
- $default reduce using rule 9 (expr)
192
-
193
-
194
- State 14
195
-
196
- 5 expr: expr • '+' expr
197
- 5 | expr '+' expr • [LF, '+', '-', ')']
198
- 6 | expr • '-' expr
199
- 7 | expr • '*' expr
200
- 8 | expr • '/' expr
201
-
202
- '*' shift, and go to state 11
203
- '/' shift, and go to state 12
204
-
205
- $default reduce using rule 5 (expr)
206
-
207
- Conflict between rule 5 and token '+' resolved as reduce (%left '+').
208
- Conflict between rule 5 and token '-' resolved as reduce (%left '-').
209
- Conflict between rule 5 and token '*' resolved as shift ('+' < '*').
210
- Conflict between rule 5 and token '/' resolved as shift ('+' < '/').
211
-
212
-
213
- State 15
214
-
215
- 5 expr: expr • '+' expr
216
- 6 | expr • '-' expr
217
- 6 | expr '-' expr • [LF, '+', '-', ')']
218
- 7 | expr • '*' expr
219
- 8 | expr • '/' expr
220
-
221
- '*' shift, and go to state 11
222
- '/' shift, and go to state 12
223
-
224
- $default reduce using rule 6 (expr)
225
-
226
- Conflict between rule 6 and token '+' resolved as reduce (%left '+').
227
- Conflict between rule 6 and token '-' resolved as reduce (%left '-').
228
- Conflict between rule 6 and token '*' resolved as shift ('-' < '*').
229
- Conflict between rule 6 and token '/' resolved as shift ('-' < '/').
230
-
231
-
232
- State 16
233
-
234
- 5 expr: expr • '+' expr
235
- 6 | expr • '-' expr
236
- 7 | expr • '*' expr
237
- 7 | expr '*' expr • [LF, '+', '-', '*', '/', ')']
238
- 8 | expr • '/' expr
239
-
240
- $default reduce using rule 7 (expr)
241
-
242
- Conflict between rule 7 and token '+' resolved as reduce ('+' < '*').
243
- Conflict between rule 7 and token '-' resolved as reduce ('-' < '*').
244
- Conflict between rule 7 and token '*' resolved as reduce (%left '*').
245
- Conflict between rule 7 and token '/' resolved as reduce (%left '/').
246
-
247
-
248
- State 17
249
-
250
- 5 expr: expr • '+' expr
251
- 6 | expr • '-' expr
252
- 7 | expr • '*' expr
253
- 8 | expr • '/' expr
254
- 8 | expr '/' expr • [LF, '+', '-', '*', '/', ')']
255
-
256
- $default reduce using rule 8 (expr)
257
-
258
- Conflict between rule 8 and token '+' resolved as reduce ('+' < '/').
259
- Conflict between rule 8 and token '-' resolved as reduce ('-' < '/').
260
- Conflict between rule 8 and token '*' resolved as reduce (%left '*').
261
- Conflict between rule 8 and token '/' resolved as reduce (%left '/').
262
-
263
-
data/sample/calc.y DELETED
@@ -1,101 +0,0 @@
1
- /*
2
- * How to build and run:
3
- *
4
- * $ lrama -d calc.y -o calc.c && gcc -Wall calc.c -o calc && ./calc
5
- * 1
6
- * => 1
7
- * 1+2*3
8
- * => 7
9
- * (1+2)*3
10
- * => 9
11
- *
12
- */
13
-
14
- %{
15
- #include <stdio.h>
16
- #include <stdlib.h>
17
- #include <ctype.h>
18
- %}
19
-
20
- %code provides {
21
- static int yylex(YYSTYPE *val, YYLTYPE *loc);
22
- static int yyerror(YYLTYPE *loc, const char *str);
23
- }
24
-
25
- %union {
26
- int val;
27
- }
28
- %token LF
29
- %token <val> NUM
30
- %type <val> expr
31
- %left '+' '-'
32
- %left '*' '/'
33
-
34
- %rule %inline op : '+' { + }
35
- | '-' { - }
36
- | '*' { * }
37
- | '/' { / }
38
- ;
39
-
40
- %%
41
-
42
- list : /* empty */
43
- | list LF
44
- | list expr LF { printf("=> %d\n", $2); }
45
- ;
46
- expr : NUM
47
- | expr op expr { $$ = $1 $2 $3; }
48
- | '(' expr ')' { $$ = $2; }
49
- ;
50
-
51
- %%
52
-
53
- static int yylex(YYSTYPE *yylval, YYLTYPE *loc) {
54
- int c = getchar();
55
- int val;
56
-
57
- switch (c) {
58
- case ' ': case '\t':
59
- return yylex(yylval, loc);
60
-
61
- case '0': case '1': case '2': case '3': case '4':
62
- case '5': case '6': case '7': case '8': case '9':
63
- val = c - '0';
64
- while (1) {
65
- c = getchar();
66
- if (isdigit(c)) {
67
- val = val * 10 + (c - '0');
68
- }
69
- else {
70
- ungetc(c, stdin);
71
- break;
72
- }
73
- }
74
- yylval->val = val;
75
- return NUM;
76
-
77
- case '\n':
78
- return LF;
79
-
80
- case '+': case '-': case '*': case '/': case '(': case ')':
81
- return c;
82
-
83
- case EOF:
84
- exit(0);
85
-
86
- default:
87
- fprintf(stderr, "unknown character: %c\n", c);
88
- exit(1);
89
- }
90
- }
91
-
92
- static int yyerror(YYLTYPE *loc, const char *str) {
93
- fprintf(stderr, "parse error: %s\n", str);
94
- return 0;
95
- }
96
-
97
- int main() {
98
- printf("Enter the formula:\n");
99
- yyparse();
100
- return 0;
101
- }
data/sample/parse.y DELETED
@@ -1,59 +0,0 @@
1
- /*
2
- * This is comment for this file.
3
- */
4
-
5
- %{
6
- // Prologue
7
- %}
8
-
9
- %code provides {
10
-
11
- static enum yytokentype yylex(YYSTYPE *lval, YYLTYPE *yylloc);
12
- static void yyerror(YYLTYPE *yylloc, const char *msg);
13
-
14
- }
15
-
16
- %expect 0
17
- %define api.pure
18
- %define parse.error verbose
19
-
20
- %union {
21
- int i;
22
- }
23
-
24
- %token <i> number
25
-
26
- %%
27
-
28
- program : expr
29
- ;
30
-
31
- expr : term '+' expr
32
- | term
33
- ;
34
-
35
- term : factor '*' term
36
- | factor
37
- ;
38
-
39
- factor : number
40
- ;
41
-
42
- %%
43
-
44
- // Epilogue
45
-
46
- static enum yytokentype
47
- yylex(YYSTYPE *lval, YYLTYPE *yylloc)
48
- {
49
- return 0;
50
- }
51
-
52
- static void yyerror(YYLTYPE *yylloc, const char *msg)
53
- {
54
- (void) msg;
55
- }
56
-
57
- int main(int argc, char *argv[])
58
- {
59
- }