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.).
9 @cols = Math
.sqrt(@states).to_i
10 @lines = @states / @cols
11 @rest = @states % @cols
13 @n = @lines * (@cols - 1) + (@rest == 0 ? 1 : @rest == 1 ? 2 : @rest)
17 last
= @lines + ([0, 1].include?(@rest) ? 0 : 1)
18 (0...last
).map
{ |i
| "t#{i}" }.join(' ')
22 res
= (0...@lines).map
{ |i
| "t#{i}:#{' N' * (@cols - 1)}" }.join("\n")
29 res
+= "\nt#{@lines}:#{" N
" * @rest}"
46 static int
yylex (void
);
47 static void
yyerror (const char
*msg
);
51 %define api
.value
.type union
52 %define parse
.lac full
53 %define parse
.error verbose
54 %printer
{ fprintf (yyo
, "%ld", $$
); } <long
>
68 static long count
= 0;
79 void
yyerror (const char
*msg
)
81 fprintf (stderr, "%s\\n", msg
);
87 yydebug
= !!getenv ("YYDEBUG");
94 puts Linear
.new(ARGV[0].to_i
).to_s