3 # Build a grammar whose LALR(1) parser has a given number of states.
4 # Useful to test edge cases (e.g., 256 and 257 states, etc.).
6 # Copyright (C) 2020-2021 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 # Written by Akim Demaille.
24 def initialize(states
)
26 @cols = Math
.sqrt(@states).to_i
27 @lines = @states / @cols
28 @rest = @states % @cols
30 @n = @lines * (@cols - 1) + (@rest == 0 ? 1 : @rest == 1 ? 2 : @rest)
34 last
= @lines + ([0, 1].include?(@rest) ? 0 : 1)
35 (0...last
).map
{ |i
| "t#{i}" }.join(' ')
39 res
= (0...@lines).map
{ |i
| "t#{i}:#{' N' * (@cols - 1)}" }.join("\n")
46 res
+= "\nt#{@lines}:#{" N
" * @rest}"
63 static int
yylex (void
);
64 static void
yyerror (const char
*msg
);
68 %define api
.value
.type union
69 %define parse
.lac full
70 %define parse
.error verbose
71 %printer
{ fprintf (yyo
, "%ld", $$
); } <long
>
85 static long count
= 0;
96 void
yyerror (const char
*msg
)
98 fprintf (stderr, "%s\\n", msg
);
104 yydebug
= !!getenv ("YYDEBUG");
111 puts Linear
.new(ARGV[0].to_i
).to_s