# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# FIXME: Duplication with calc.at.
AT_BANNER([[Named references tests.]])
AT_SETUP([Tutorial calculator])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([test.y],
[[
%{
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static semantic_value global_result = 0;
static int global_count = 0;
static int power (int base, int exponent);
-static void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
%union
| '-' error { $$ = 0; YYERROR; }
;
%%
-
-static void yyerror (const char *s)
-{
- fprintf (stderr, "%s\n", s);
-}
-
+]AT_YYERROR_DEFINE[
static int get_char (void)
{
int res = getc (input);
return sign * n;
}
-int yylex (void)
+static int
+yylex (void)
{
int c;
/* Skip white space. */
static int power (int base, int exponent)
{
int res = 1;
- if (exponent < 0)
- exit (3);
+ assert (0 <= exponent);
for (/* Niente */; exponent; --exponent)
res *= base;
return res;
}
status = yyparse ();
fclose (input);
- if (global_result != result)
- abort ();
- if (global_count != count)
- abort ();
+ assert (global_result == result);
+ assert (global_count == count);
return status;
}
]])
AT_BISON_CHECK([-o test.c test.y])
AT_COMPILE([[test]])
AT_PARSER_CHECK([./test input.txt], 0, [], [stderr])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
AT_SETUP([Undefined and ambiguous references])
-
+AT_BISON_OPTION_PUSHDEFS
AT_DATA_GRAMMAR([test.y],
[[
%{
static int power (int base, int exponent);
-static void yyerror (const char *s);
-int yylex (void);
+]AT_YYERROR_DECLARE[
+]AT_YYLEX_DECLARE[
%}
%union
test.y:56.29-33: invalid reference: '$expo'
test.y:56.3-46: symbol not found in production: expo
]])
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
#######################################################################
AT_DATA_GRAMMAR([test.y],
[[
%%
-start: foo[ /* aaa */ *&-.+ ] bar
+start: foo[ /* aaa */ *&-.+\000\001\002\377 ] bar
{ s = $foo; }
]])
+AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' test.y || exit 77]])
AT_BISON_CHECK([-o test.c test.y], 1, [],
[[test.y:11.23: invalid character in bracketed name: '*'
test.y:11.24: invalid character in bracketed name: '&'
test.y:11.25: invalid character in bracketed name: '-'
test.y:11.27: invalid character in bracketed name: '+'
+test.y:11.28: invalid character in bracketed name: '\0'
+test.y:11.28: invalid character in bracketed name: '\001'
+test.y:11.28: invalid character in bracketed name: '\002'
+test.y:11.28: invalid character in bracketed name: '\377'
]])
AT_CLEANUP