X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/72e727f2ec4e9f95c2ba63a4af358bc31c9e9338..7254f6a84048d56da7b004c2934613f7f9de391a:/tests/reduce.at diff --git a/tests/reduce.at b/tests/reduce.at index 5fe650a8..058d7c0d 100644 --- a/tests/reduce.at +++ b/tests/reduce.at @@ -1,5 +1,6 @@ # Exercising Bison Grammar Reduction. -*- Autotest -*- -# Copyright (C) 2001, 2002, 2007, 2008 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2007, 2008, 2009 Free Software Foundation, +# Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -355,3 +356,147 @@ input.y:3.1-3: fatal error: start symbol exp does not derive any sentence ]]) AT_CLEANUP + + + +## -------------------------- ## +## %define lr.default_rules. ## +## -------------------------- ## + +# AT_TEST_LR_DEFAULT_RULES(GRAMMAR, INPUT, TABLES) +# ------------------------------------------------ +m4_define([AT_TEST_LR_DEFAULT_RULES], +[ +AT_TEST_TABLES_AND_PARSE([[no %define lr.default_rules]], + [[all]], [[]], + [[]], + [$1], [$2], [[]], [$3]) +AT_TEST_TABLES_AND_PARSE([[%define lr.default_rules "all"]], + [[all]], [[]], + [[%define lr.default_rules "all"]], + [$1], [$2], [[]], [$3]) +AT_TEST_TABLES_AND_PARSE([[%define lr.default_rules "consistent"]], + [[consistent]], [[]], + [[%define lr.default_rules "consistent"]], + [$1], [$2], [[]], [$3]) +AT_TEST_TABLES_AND_PARSE([[%define lr.default_rules "accepting"]], + [[accepting]], [[]], + [[%define lr.default_rules "accepting"]], + [$1], [$2], [[]], [$3]) +]) + +AT_TEST_LR_DEFAULT_RULES([[ +/* The start state is consistent and has a shift on 'a' and no reductions. + After pushing the b below, enter an inconsistent state that has a shift and + one reduction with one lookahead. */ +start: + a b + | a b 'a' + | a c 'b' + ; + +/* After shifting this 'a', enter a consistent state that has no shift and 1 + reduction with multiple lookaheads. */ +a: 'a' ; + +/* After the previous reduction, enter an inconsistent state that has no shift + and multiple reductions. The first reduction has more lookaheads than the + second, so the first should always be preferred as the default rule if + enabled. The second reduction has one lookahead. */ +b: ; +c: ; +]], +dnl Visit each state mentioned above. +[['a', 'a']], +[[state 0 + + 0 $accept: . start $end + 1 start: . a b + 2 | . a b 'a' + 3 | . a c 'b' + 4 a: . 'a' + + 'a' shift, and go to state 1 + + start go to state 2 + a go to state 3 + + +state 1 + + 4 a: 'a' .]AT_COND_CASE([[accepting]], [[ [$end, 'a', 'b'] + + $end reduce using rule 4 (a) + 'a' reduce using rule 4 (a) + 'b' reduce using rule 4 (a)]], [[ + + $default reduce using rule 4 (a)]])[ + + +state 2 + + 0 $accept: start . $end + + $end shift, and go to state 4 + + +state 3 + + 1 start: a . b + 2 | a . b 'a' + 3 | a . c 'b' + 5 b: . [$end, 'a'] + 6 c: . ['b']]AT_COND_CASE([[all]], [[ + + 'b' reduce using rule 6 (c) + $default reduce using rule 5 (b)]], [[ + + $end reduce using rule 5 (b) + 'a' reduce using rule 5 (b) + 'b' reduce using rule 6 (c)]])[ + + b go to state 5 + c go to state 6 + + +state 4 + + 0 $accept: start $end . + + $default accept + + +state 5 + + 1 start: a b . [$end] + 2 | a b . 'a' + + 'a' shift, and go to state 7 + + ]AT_COND_CASE([[all]], [[$default]], [[$end]])[ reduce using rule 1 (start) + + +state 6 + + 3 start: a c . 'b' + + 'b' shift, and go to state 8 + + +state 7 + + 2 start: a b 'a' .]AT_COND_CASE([[accepting]], [[ [$end] + + $end reduce using rule 2 (start)]], [[ + + $default reduce using rule 2 (start)]])[ + + +state 8 + + 3 start: a c 'b' .]AT_COND_CASE([[accepting]], [[ [$end] + + $end reduce using rule 3 (start)]], [[ + + $default reduce using rule 3 (start)]])[ +]])