1 # Named references test. -*- Autotest -*-
3 # Copyright (C) 2009-2015, 2018-2020 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # FIXME: Duplication with calc.at.
19 AT_BANNER([[Named references tests.]])
21 # FIXME: large duplication with calc.at.
22 AT_SETUP([Tutorial calculator])
23 AT_BISON_OPTION_PUSHDEFS
24 AT_DATA_GRAMMAR([test.y],
32 typedef int semantic_value;
34 static semantic_value global_result = 0;
35 static int global_count = 0;
36 static int power (int base, int exponent);
46 %token CALC_EOF 0 "end of input"
47 %token <ival> NUM "number"
50 %nonassoc '=' /* comparison */
53 %precedence NEG /* negation--unary minus */
54 %right '^' /* exponentiation */
72 fprintf (stderr, "calc: error: %d != %d\n", $l, $r);
75 | exp[x] '+' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>l + $r; }
76 | exp[l] '-' exp[r] { $$ = $l - $r; }
77 | exp[l] '*' exp[r] { $$ = $l * $r; }
78 | exp[l] '/' exp[r] { $$ = $l / $r; }
79 | '-' exp %prec NEG { $$ = -$2; }
80 | exp[l] '^' exp[r] { $$ = power ($l, $r); }
81 | '(' exp[e] ')' { $$ = $e; }
82 | '(' error ')' { $$ = 1111; yyerrok; }
83 | '!' { $$ = 0; YYERROR; }
84 | '-' error { $$ = 0; YYERROR; }
88 static int get_char (void)
93 static void unget_char (int c)
98 static int read_signed_integer (void)
110 n = 10 * n + (c - '0');
121 /* Skip white space. */
122 while ((c = get_char ()) == ' ' || c == '\t') {}
124 /* process numbers */
125 if (c == '.' || isdigit (c))
128 (yylval).ival = read_signed_integer ();
132 /* Return end-of-file. */
136 /* Return single chars. */
140 static int power (int base, int exponent)
143 assert (0 <= exponent);
144 for (/* Niente */; exponent; --exponent)
149 int main (int argc, const char **argv)
151 semantic_value result = 0;
155 input = fopen (argv[1], "r");
165 assert (global_result == result); (void) global_result; (void) result;
166 assert (global_count == count); (void) global_count; (void) count;
184 AT_FULL_COMPILE([[test]])
185 AT_PARSER_CHECK([test input.txt], 0, [], [stderr])
186 AT_BISON_OPTION_POPDEFS
191 ## ------------------------------------ ##
192 ## Undefined and ambiguous references. ##
193 ## ------------------------------------ ##
196 AT_SETUP([Undefined and ambiguous references])
197 AT_BISON_OPTION_PUSHDEFS
198 AT_DATA_GRAMMAR([test.y],
201 static int power (int base, int exponent);
211 %token CALC_EOF 0 "end of input"
212 %token <ival> NUM "number"
215 %nonassoc '=' /* comparison */
218 %precedence NEG /* negation--unary minus */
219 %right '^' /* exponentiation */
237 fprintf (stderr, "calc: error: %d != %d\n", $l, $r);
240 | exp[x] '+' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>lo9 + $r; }
241 | exp[x] '-' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>exp - $r; }
242 | exp[x] '*' { $<ival>$ = $x; } [l] exp[r] { $$ = $l * $r; }
243 | exp[l] '/' exp[r] { $$ = $l / $r; }
244 | '-' exp %prec NEG { $$ = -$2; }
245 | exp[l] '^' exp[r] { $$ = power ($l, $r12); }
246 | '(' exp ')' { $$ = $expo; }
247 | '(' error ')' { $$ = 1111; yyerrok; }
248 | '!' { $$ = 0; YYERROR; }
249 | '-' error { $$ = 0; YYERROR; }
254 AT_BISON_CHECK([-fcaret -o test.c test.y], 1, [],
255 [[test.y:52.51-60: error: invalid reference: '$<ival>lo9'
256 52 | | exp[x] '+' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>lo9 + $r; }
258 test.y:52.3-68: note: symbol not found in production: lo9
259 52 | | exp[x] '+' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>lo9 + $r; }
260 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261 test.y:53.51-60: warning: misleading reference: '$<ival>exp' [-Wother]
262 53 | | exp[x] '-' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>exp - $r; }
264 test.y:44.1-3: note: refers to: $exp at $$
267 test.y:53.7: note: possibly meant: $x, hiding $exp at $1
268 53 | | exp[x] '-' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>exp - $r; }
270 test.y:53.41: note: possibly meant: $r, hiding $exp at $4
271 53 | | exp[x] '-' { $<ival>$ = $x; } [l] exp[r] { $$ = $<ival>exp - $r; }
273 test.y:54.51-52: error: $l of 'exp' has no declared type
274 54 | | exp[x] '*' { $<ival>$ = $x; } [l] exp[r] { $$ = $l * $r; }
276 test.y:57.40-43: error: invalid reference: '$r12'
277 57 | | exp[l] '^' exp[r] { $$ = power ($l, $r12); }
279 test.y:57.3-47: note: symbol not found in production: r12
280 57 | | exp[l] '^' exp[r] { $$ = power ($l, $r12); }
281 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282 test.y:58.29-33: error: invalid reference: '$expo'
283 58 | | '(' exp ')' { $$ = $expo; }
285 test.y:58.3-46: note: symbol not found in production: expo
286 58 | | '(' exp ')' { $$ = $expo; }
287 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289 AT_BISON_OPTION_POPDEFS
293 ## ----------------------- ##
294 ## Misleading references. ##
295 ## ----------------------- ##
297 AT_SETUP([Misleading references])
298 AT_BISON_OPTION_PUSHDEFS
299 AT_DATA_GRAMMAR([test.y],
302 start: foo foo.bar { $foo.bar; }
306 AT_BISON_CHECK([-o test.c test.y], 0, [],
307 [[test.y:11.22-29: warning: misleading reference: '$foo.bar' [-Wother]
308 test.y:11.8-10: note: refers to: $foo at $1
309 test.y:11.12-18: note: possibly meant: $[foo.bar] at $2
311 AT_BISON_OPTION_POPDEFS
314 #######################################################################
316 AT_SETUP([Many kinds of errors])
317 AT_BISON_OPTION_PUSHDEFS
318 AT_DATA_GRAMMAR([test.y],
333 if_stmt1: IF expr[cond] THEN stmt[then] ELSE stmt.list[else] FI
334 { $if_stmt1 = new IfStmt($cond1, $then.f1, $else); };
335 if_stmt2: IF expr[cond] THEN stmt[then] FI
336 { $if_stmt2 = new IfStmt($cond, $stmt.field, 0); };
337 if_stmt3: IF expr[cond] THEN stmt.list FI
338 { $if_stmt3 = new IfStmt($cond, $stmt.list, 0); };
339 if_stmt4: IF expr[cond] THEN stmt[xyz] ELSE stmt[xyz] FI
340 { $if_stmt4 = new IfStmt($cond, $xyz, $cond); };
341 if_stmt5: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
342 { $if_stmt5 = new IfStmt($cond, $stmt.list, $else); };
343 if_stmt6: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
344 { $if_stmt6 = new IfStmt($cond, $stmt.list.field, $else); };
345 if_stmt7: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
346 { $if_stmt7 = new IfStmt($cond, $[stmt.list].field, $else); };
347 if_stmt8: IF expr[cond] THEN stmt.list[then.1] ELSE stmt.list[else] FI
348 { $if_stmt8 = new IfStmt($cond, $then.1, $else); };
349 if_stmt9: IF expr[cond] THEN stmt.list[then.1] ELSE stmt.list[else] FI
350 { $if_stmt9 = new IfStmt($cond, $then.1.field, $else); };
351 if_stmt10: IF expr[cond] THEN stmt[stmt.x] FI
352 { $if_stmt10 = new IfStmt($cond, $stmt.x, 0); };
353 if-stmt-a: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
354 { $if-stmt-a = new IfStmt($cond, $then, $else); };
355 if-stmt-b: IF expr[cond] THEN if-stmt-a[then-a] ELSE stmt.list[else] FI
356 { $[if-stmt-b] = new IfStmt($cond, $then-a.f, $else); };
358 stmt.list: stmt ';' stmt.list { $3->insert($stmt); $$ = $3; }
359 | stmt ';' { SL = new StmtList(); SL->insert($1); $$ = SL; }
361 stmt: assign_stmt { $$ = $1; }
362 | if_stmt { $$ = $1; }
363 | if_stmt1 { $$ = $1; }
364 | while_stmt { $$ = $1; }
366 assign_stmt: IDENT ASSIGNOP expr
367 { $$ = new AssignStmt(string($1),$3); };
368 if_stmt: IF expr[cond] THEN stmt.list FI
369 { $if_stmt = new IfStmt($cond, $[stmt.list], 0); };
370 while_stmt[res]: WHILE expr DO stmt.list OD
371 { $res = new WhileStmt($[expr], $[stmt.list]); };
372 expr: expr '+' term { $$ = new Plus($1,$3); }
373 | expr '-' term { $$ = new Minus($1,$3); }
376 term: term '*' factor { $$ = new Times($1,$3); }
377 | factor { $$ = $1; }
379 factor: '(' expr ')' { $$ = $2; }
380 | NUMBER { $$ = new Number($1); }
381 | IDENT { $$ = new Ident(string($1)); }
384 AT_BISON_CHECK([-o test.c test.y], 1, [],
385 [[test.y:24.36-41: error: invalid reference: '$cond1'
386 test.y:23.11-24.62: note: symbol not found in production: cond1
387 test.y:26.43-53: error: invalid reference: '$stmt.field'
388 test.y:25.11-26.60: note: symbol not found in production: stmt
389 test.y:25.35-38: note: possibly meant: $then.field, hiding $stmt.field at $4
390 test.y:28.43-52: error: invalid reference: '$stmt.list'
391 test.y:27.11-28.59: note: symbol not found in production: stmt
392 test.y:27.30-38: note: possibly meant: $[stmt.list] at $4
393 test.y:30.43-46: error: ambiguous reference: '$xyz'
394 test.y:29.35-37: note: refers to: $xyz at $4
395 test.y:29.50-52: note: refers to: $xyz at $6
396 test.y:32.43-52: error: invalid reference: '$stmt.list'
397 test.y:31.11-32.63: note: symbol not found in production: stmt
398 test.y:31.40-43: note: possibly meant: $then, hiding $[stmt.list] at $4
399 test.y:31.61-64: note: possibly meant: $else, hiding $[stmt.list] at $6
400 test.y:34.43-58: error: invalid reference: '$stmt.list.field'
401 test.y:33.11-34.69: note: symbol not found in production: stmt
402 test.y:33.40-43: note: possibly meant: $then.field, hiding $[stmt.list].field at $4
403 test.y:33.61-64: note: possibly meant: $else.field, hiding $[stmt.list].field at $6
404 test.y:36.43-54: error: invalid reference: '$[stmt.list]'
405 test.y:35.11-36.71: note: symbol not found in production: stmt.list
406 test.y:35.40-43: note: possibly meant: $then, hiding $[stmt.list] at $4
407 test.y:35.61-64: note: possibly meant: $else, hiding $[stmt.list] at $6
408 test.y:38.43-49: error: invalid reference: '$then.1'
409 test.y:37.11-38.60: note: symbol not found in production: then
410 test.y:37.40-45: note: possibly meant: $[then.1] at $4
411 test.y:40.43-55: error: invalid reference: '$then.1.field'
412 test.y:39.11-40.66: note: symbol not found in production: then
413 test.y:39.40-45: note: possibly meant: $[then.1].field at $4
414 test.y:42.44-50: error: invalid reference: '$stmt.x'
415 test.y:41.12-42.57: note: symbol not found in production: stmt
416 test.y:41.36-41: note: possibly meant: $[stmt.x].x, hiding $stmt.x at $4
417 test.y:41.36-41: note: possibly meant: $[stmt.x] at $4
418 test.y:44.13-22: error: invalid reference: '$if-stmt-a'
419 test.y:43.12-44.59: note: symbol not found in production: if
420 test.y:43.1-9: note: possibly meant: $[if-stmt-a] at $$
421 test.y:46.46-54: error: invalid reference: '$then-a.f'
422 test.y:45.12-46.65: note: symbol not found in production: then
423 test.y:45.41-46: note: possibly meant: $[then-a].f at $4
426 AT_BISON_CHECK([-fcaret -o test.c test.y], 1, [],
427 [[test.y:24.36-41: error: invalid reference: '$cond1'
428 24 | { $if_stmt1 = new IfStmt($cond1, $then.f1, $else); };
430 test.y:23.11-24.62: note: symbol not found in production: cond1
431 23 | if_stmt1: IF expr[cond] THEN stmt[then] ELSE stmt.list[else] FI
432 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
433 test.y:26.43-53: error: invalid reference: '$stmt.field'
434 26 | { $if_stmt2 = new IfStmt($cond, $stmt.field, 0); };
436 test.y:25.11-26.60: note: symbol not found in production: stmt
437 25 | if_stmt2: IF expr[cond] THEN stmt[then] FI
438 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
439 test.y:25.35-38: note: possibly meant: $then.field, hiding $stmt.field at $4
440 25 | if_stmt2: IF expr[cond] THEN stmt[then] FI
442 test.y:28.43-52: error: invalid reference: '$stmt.list'
443 28 | { $if_stmt3 = new IfStmt($cond, $stmt.list, 0); };
445 test.y:27.11-28.59: note: symbol not found in production: stmt
446 27 | if_stmt3: IF expr[cond] THEN stmt.list FI
447 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
448 test.y:27.30-38: note: possibly meant: $[stmt.list] at $4
449 27 | if_stmt3: IF expr[cond] THEN stmt.list FI
451 test.y:30.43-46: error: ambiguous reference: '$xyz'
452 30 | { $if_stmt4 = new IfStmt($cond, $xyz, $cond); };
454 test.y:29.35-37: note: refers to: $xyz at $4
455 29 | if_stmt4: IF expr[cond] THEN stmt[xyz] ELSE stmt[xyz] FI
457 test.y:29.50-52: note: refers to: $xyz at $6
458 29 | if_stmt4: IF expr[cond] THEN stmt[xyz] ELSE stmt[xyz] FI
460 test.y:32.43-52: error: invalid reference: '$stmt.list'
461 32 | { $if_stmt5 = new IfStmt($cond, $stmt.list, $else); };
463 test.y:31.11-32.63: note: symbol not found in production: stmt
464 31 | if_stmt5: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
465 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
466 test.y:31.40-43: note: possibly meant: $then, hiding $[stmt.list] at $4
467 31 | if_stmt5: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
469 test.y:31.61-64: note: possibly meant: $else, hiding $[stmt.list] at $6
470 31 | if_stmt5: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
472 test.y:34.43-58: error: invalid reference: '$stmt.list.field'
473 34 | { $if_stmt6 = new IfStmt($cond, $stmt.list.field, $else); };
475 test.y:33.11-34.69: note: symbol not found in production: stmt
476 33 | if_stmt6: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
477 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
478 test.y:33.40-43: note: possibly meant: $then.field, hiding $[stmt.list].field at $4
479 33 | if_stmt6: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
481 test.y:33.61-64: note: possibly meant: $else.field, hiding $[stmt.list].field at $6
482 33 | if_stmt6: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
484 test.y:36.43-54: error: invalid reference: '$[stmt.list]'
485 36 | { $if_stmt7 = new IfStmt($cond, $[stmt.list].field, $else); };
487 test.y:35.11-36.71: note: symbol not found in production: stmt.list
488 35 | if_stmt7: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
489 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
490 test.y:35.40-43: note: possibly meant: $then, hiding $[stmt.list] at $4
491 35 | if_stmt7: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
493 test.y:35.61-64: note: possibly meant: $else, hiding $[stmt.list] at $6
494 35 | if_stmt7: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
496 test.y:38.43-49: error: invalid reference: '$then.1'
497 38 | { $if_stmt8 = new IfStmt($cond, $then.1, $else); };
499 test.y:37.11-38.60: note: symbol not found in production: then
500 37 | if_stmt8: IF expr[cond] THEN stmt.list[then.1] ELSE stmt.list[else] FI
501 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
502 test.y:37.40-45: note: possibly meant: $[then.1] at $4
503 37 | if_stmt8: IF expr[cond] THEN stmt.list[then.1] ELSE stmt.list[else] FI
505 test.y:40.43-55: error: invalid reference: '$then.1.field'
506 40 | { $if_stmt9 = new IfStmt($cond, $then.1.field, $else); };
508 test.y:39.11-40.66: note: symbol not found in production: then
509 39 | if_stmt9: IF expr[cond] THEN stmt.list[then.1] ELSE stmt.list[else] FI
510 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
511 test.y:39.40-45: note: possibly meant: $[then.1].field at $4
512 39 | if_stmt9: IF expr[cond] THEN stmt.list[then.1] ELSE stmt.list[else] FI
514 test.y:42.44-50: error: invalid reference: '$stmt.x'
515 42 | { $if_stmt10 = new IfStmt($cond, $stmt.x, 0); };
517 test.y:41.12-42.57: note: symbol not found in production: stmt
518 41 | if_stmt10: IF expr[cond] THEN stmt[stmt.x] FI
519 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
520 test.y:41.36-41: note: possibly meant: $[stmt.x].x, hiding $stmt.x at $4
521 41 | if_stmt10: IF expr[cond] THEN stmt[stmt.x] FI
523 test.y:41.36-41: note: possibly meant: $[stmt.x] at $4
524 41 | if_stmt10: IF expr[cond] THEN stmt[stmt.x] FI
526 test.y:44.13-22: error: invalid reference: '$if-stmt-a'
527 44 | { $if-stmt-a = new IfStmt($cond, $then, $else); };
529 test.y:43.12-44.59: note: symbol not found in production: if
530 43 | if-stmt-a: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
531 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
532 test.y:43.1-9: note: possibly meant: $[if-stmt-a] at $$
533 43 | if-stmt-a: IF expr[cond] THEN stmt.list[then] ELSE stmt.list[else] FI
535 test.y:46.46-54: error: invalid reference: '$then-a.f'
536 46 | { $[if-stmt-b] = new IfStmt($cond, $then-a.f, $else); };
538 test.y:45.12-46.65: note: symbol not found in production: then
539 45 | if-stmt-b: IF expr[cond] THEN if-stmt-a[then-a] ELSE stmt.list[else] FI
540 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
541 test.y:45.41-46: note: possibly meant: $[then-a].f at $4
542 45 | if-stmt-b: IF expr[cond] THEN if-stmt-a[then-a] ELSE stmt.list[else] FI
546 AT_BISON_OPTION_POPDEFS
549 #######################################################################
551 AT_SETUP([Missing identifiers in brackets])
552 AT_BISON_OPTION_PUSHDEFS
553 AT_DATA_GRAMMAR([test.y],
559 AT_BISON_CHECK([-o test.c test.y], 1, [],
560 [[test.y:11.12: error: an identifier expected
562 AT_BISON_OPTION_POPDEFS
565 #######################################################################
567 AT_SETUP([Redundant words in brackets])
568 AT_BISON_OPTION_PUSHDEFS
569 AT_DATA_GRAMMAR([test.y],
572 start: foo[ a d ] bar
575 AT_BISON_CHECK([-o test.c test.y], 1, [],
576 [[test.y:11.15: error: unexpected identifier in bracketed name: 'd'
578 AT_BISON_OPTION_POPDEFS
581 #######################################################################
583 AT_SETUP([Comments in brackets])
584 AT_BISON_OPTION_PUSHDEFS
585 AT_DATA_GRAMMAR([test.y],
588 start: foo[/* comment */] bar
591 AT_BISON_CHECK([-o test.c test.y], 1, [],
592 [[test.y:11.25: error: an identifier expected
594 AT_BISON_OPTION_POPDEFS
597 #######################################################################
599 AT_SETUP([Stray symbols in brackets])
600 AT_BISON_OPTION_PUSHDEFS
601 AT_DATA_GRAMMAR([test.y],
604 start: foo[ % /* aaa */ *&-.+\000\001\002\377 ] bar
607 AT_PERL_REQUIRE([[-pi -e 's/\\(\d{3})/chr(oct($1))/ge' test.y]])
608 AT_BISON_CHECK([-o test.c test.y], 1, [],
609 [[test.y:11.13: error: invalid character in bracketed name: '%'
610 test.y:11.25-27: error: invalid characters in bracketed name: '*&-'
611 test.y:11.29-30: error: invalid characters in bracketed name: '+\0\001\002\377'
613 AT_BISON_OPTION_POPDEFS
616 #######################################################################
618 AT_SETUP([Redundant words in LHS brackets])
619 AT_BISON_OPTION_PUSHDEFS
620 AT_DATA_GRAMMAR([test.y],
625 AT_BISON_CHECK([-o test.c test.y], 1, [],
626 [[test.y:11.9: error: unexpected identifier in bracketed name: 's'
628 AT_BISON_OPTION_POPDEFS
631 #######################################################################
633 # Bison used to free twice the named ref for "a", since a single copy
634 # was used in two rules.
635 AT_SETUP([Factored LHS])
636 AT_BISON_OPTION_PUSHDEFS
637 AT_DATA_GRAMMAR([test.y],
640 start[a]: "foo" | "bar";
642 AT_BISON_CHECK([-o test.c test.y])
643 AT_BISON_OPTION_POPDEFS
646 #######################################################################
648 AT_SETUP([Unresolved references])
649 AT_BISON_OPTION_PUSHDEFS
650 AT_DATA_GRAMMAR([test.y],
654 sym_a sym_b { func($sym.field); }
655 | sym_a sym_b { func($<aa>sym.field); }
656 | sym_a sym_b { func($[sym.field]); }
657 | sym_a sym_b { func($<aa>[sym.field]); }
658 | sym_a sym_b { func($sym); }
659 | sym_a sym_b { func($<aa>sym); }
660 | sym_a sym_b { func($[sym]); } sym_a sym_b { func($<aa>[sym]); }
664 sym_a sym_b { func($sym-field); }
665 | sym_a sym_b { func($<aa>sym-field); }
666 | sym_a sym_b { func($[sym-field]); }
667 | sym_a sym_b { func($<aa>[sym-field]); }
668 | sym_a sym_b { func($sym); }
669 | sym_a sym_b { func($<aa>sym); }
670 | sym_a sym_b { func($[sym]); } sym_a sym_b { func($<aa>[sym]); }
676 AT_BISON_CHECK([-o test.c test.y], 1, [],
677 [[test.y:12.22-31: error: invalid reference: '$sym.field'
678 test.y:12.3-35: note: symbol not found in production: sym
679 test.y:13.22-35: error: invalid reference: '$<aa>sym.field'
680 test.y:13.3-39: note: symbol not found in production: sym
681 test.y:14.22-33: error: invalid reference: '$[sym.field]'
682 test.y:14.3-37: note: symbol not found in production: sym.field
683 test.y:15.22-37: error: invalid reference: '$<aa>[sym.field]'
684 test.y:15.3-41: note: symbol not found in production: sym.field
685 test.y:16.22-25: error: invalid reference: '$sym'
686 test.y:16.3-29: note: symbol not found in production: sym
687 test.y:17.22-29: error: invalid reference: '$<aa>sym'
688 test.y:17.3-33: note: symbol not found in production: sym
689 test.y:18.22-27: error: invalid reference: '$[sym]'
690 test.y:18.3-65: note: symbol not found in production before $3: sym
691 test.y:18.52-61: error: invalid reference: '$<aa>[sym]'
692 test.y:18.3-65: note: symbol not found in production: sym
693 test.y:22.22-31: error: invalid reference: '$sym-field'
694 test.y:22.3-35: note: symbol not found in production: sym
695 test.y:23.22-35: error: invalid reference: '$<aa>sym-field'
696 test.y:23.3-39: note: symbol not found in production: sym
697 test.y:24.22-33: error: invalid reference: '$[sym-field]'
698 test.y:24.3-37: note: symbol not found in production: sym-field
699 test.y:25.22-37: error: invalid reference: '$<aa>[sym-field]'
700 test.y:25.3-41: note: symbol not found in production: sym-field
701 test.y:26.22-25: error: invalid reference: '$sym'
702 test.y:26.3-29: note: symbol not found in production: sym
703 test.y:27.22-29: error: invalid reference: '$<aa>sym'
704 test.y:27.3-33: note: symbol not found in production: sym
705 test.y:28.22-27: error: invalid reference: '$[sym]'
706 test.y:28.3-65: note: symbol not found in production before $3: sym
707 test.y:28.52-61: error: invalid reference: '$<aa>[sym]'
708 test.y:28.3-65: note: symbol not found in production: sym
710 AT_BISON_OPTION_POPDEFS
713 #######################################################################
715 AT_SETUP([[$ or @ followed by . or -]])
725 AT_BISON_CHECK([[test.y]], [[1]], [],
726 [[test.y:4.12-18: error: invalid reference: '$.field'
727 test.y:4.13: note: syntax error after '$', expecting integer, letter, '_', '@<:@', or '$'
728 test.y:4.3-8: note: possibly meant: $[.field] at $1
729 test.y:5.12-18: error: invalid reference: '@.field'
730 test.y:5.13: note: syntax error after '@', expecting integer, letter, '_', '@<:@', or '$'
740 AT_BISON_CHECK([[test.y]], [[0]], [],
741 [[test.y:4.9: warning: stray '$' [-Wother]
742 test.y:5.9: warning: stray '@' [-Wother]