-## ---------------- ##
-## Invalid inputs. ##
-## ---------------- ##
-
-
-AT_SETUP([Invalid inputs])
-
-AT_DATA([input.y],
-[[%%
-?
-default: 'a' }
-%&
-%a-does-not-exist
-%-
-%{
-]])
-
-AT_BISON_CHECK([input.y], [1], [],
-[[input.y:2.1: invalid character: '?'
-input.y:3.14: invalid character: '}'
-input.y:4.1: invalid character: '%'
-input.y:4.2: invalid character: '&'
-input.y:5.1-17: invalid directive: '%a-does-not-exist'
-input.y:6.1: invalid character: '%'
-input.y:6.2: invalid character: '-'
-input.y:7.1-8.0: missing '%}' at end of file
-input.y:7.1-8.0: syntax error, unexpected %{...%}
-]])
-
-AT_CLEANUP
-
-
-AT_SETUP([Invalid inputs with {}])
-
-AT_DATA([input.y],
-[[
-%destructor
-%initial-action
-%lex-param
-%parse-param
-%printer
-%union
-]])
-
-AT_BISON_CHECK([input.y], [1], [],
-[[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
-]])
-
-AT_CLEANUP
-
-
-
## ------------------- ##
## Token definitions. ##
## ------------------- ##
exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
%%
]AT_YYERROR_DEFINE[
-
-int
-yylex (void)
-{
- static int called;
- if (called++)
- abort ();
- return SPECIAL;
-}
+]AT_YYLEX_DEFINE([{ SPECIAL }])[
int
main (void)
# so that possible bound checking compilers could check all the skeletons.
m4_define([_AT_DATA_DANCER_Y],
[AT_DATA_GRAMMAR([dancer.y],
-[%{
-static int yylex (AT_LALR1_CC_IF([int *], [void]));
-AT_LALR1_CC_IF([],
-[#include <stdlib.h>
-#include <stdio.h>
-]AT_YYERROR_DECLARE[])
-%}
+[[%code provides
+{
+ ]AT_YYERROR_DECLARE[
+ ]AT_YYLEX_DECLARE[
+}
$1
%token ARROW INVALID NUMBER STRING DATA
%defines
| INVALID
;
%%
-AT_YYERROR_DEFINE[
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE([":"])[
]AT_LALR1_CC_IF(
[int
yyparse ()
#endif
return parser.parse ();
}
-])
-
-#include <assert.h>
-static int
-yylex (AT_LALR1_CC_IF([int *lval], [void]))
-[{
- static int const tokens[] =
- {
- ':', -1
- };
- static size_t toknum;
- ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
- assert (toknum < sizeof tokens / sizeof *tokens);
- return tokens[toknum++];
-}]
+])[
int
main (void)
{
return yyparse ();
}
-])
+]])
])# _AT_DATA_DANCER_Y
[AT_SETUP([Dancer $1])
AT_BISON_OPTION_PUSHDEFS([$1])
_AT_DATA_DANCER_Y([$1])
-AT_BISON_CHECK([-o dancer.c dancer.y])
AT_FULL_COMPILE([dancer])
AT_PARSER_CHECK([./dancer], 1, [],
[syntax error, unexpected ':'
[AT_SETUP([Expecting two tokens $1])
AT_BISON_OPTION_PUSHDEFS([$1])
_AT_DATA_EXPECT2_Y([$1])
-AT_BISON_CHECK([-o expect2.c expect2.y])
AT_FULL_COMPILE([expect2])
AT_PARSER_CHECK([./expect2], 1, [],
[syntax error, unexpected '+', expecting A or B
%printer { fprintf (yyoutput, "PRINTER"); } 'a';
%%
-
]AT_YYERROR_DEFINE[
-static int
-yylex (void)
-{
- return 'a';
-}
+]AT_YYLEX_DEFINE(["a"])[
int
main (void)
%%
]AT_YYERROR_DEFINE[
-int
-yylex (void)
-{
- static int const input[] = { 1, 2, 3, 0 };
- static int const *inputp = input;
- return *inputp++;
-}
+]AT_YYLEX_DEFINE([{ 1, 2, 3, 0 }])[
int
main (void)
# Check number of default reductions in inconsistent states to be sure
# syntax error is detected before unnecessary reductions are performed.
-AT_CHECK([[perl -0777 -ne 'print s/inconsistent default reduction//g;' \
+AT_CHECK([[$PERL -0777 -ne 'print s/inconsistent default reduction//g;' \
< stdout.txt || exit 77]], [[0]], [[14]])
# Check number of default reductions in consistent states to be sure
# it is performed before the syntax error is detected.
-AT_CHECK([[perl -0777 -ne 'print s/\bconsistent default reduction//g;' \
+AT_CHECK([[$PERL -0777 -ne 'print s/\bconsistent default reduction//g;' \
< stdout.txt || exit 77]], [[0]], [[2]])
# Check number of reallocs to be sure reallocated memory isn't somehow
# lost between LAC invocations.
-AT_CHECK([[perl -0777 -ne 'print s/\(realloc//g;' < stderr.txt \
+AT_CHECK([[$PERL -0777 -ne 'print s/\(realloc//g;' < stderr.txt \
|| exit 77]], [[0]], [[3]])
AT_BISON_OPTION_POPDEFS
m4_popdef([AT_LAC_CHECK])
AT_CLEANUP
+
+
+## ---------------------- ##
+## Lex and parse params. ##
+## ---------------------- ##
+
+# AT_TEST(SKELETON)
+# -----------------
+# Check that the identifier of the params is properly fetched
+# even when there are trailing blanks.
+
+m4_pushdef([AT_TEST],
+[AT_SETUP([[Lex and parse params: $1]])
+
+AT_BISON_OPTION_PUSHDEFS([%locations %skeleton $1])
+
+## FIXME: Improve parsing of parse-param and use the generated
+## yyerror.
+AT_DATA_GRAMMAR([input.y],
+[[%defines
+%locations
+%skeleton $1
+%union { int ival; }
+%parse-param { int x }
+// Spaces, tabs, and new lines.
+%parse-param { @&t@
+ int y @&t@
+ @&t@
+ @&t@
+}
+
+%{
+#include <stdio.h>
+#include <stdlib.h>
+
+]AT_SKEL_CC_IF([], [[
+static
+void
+yyerror (int x, int y, const char *msg)
+{
+ fprintf (stderr, "x: %d, y: %d, %s\n", x, y, msg);
+}]])[
+
+ ]AT_YYLEX_DECLARE[
+%}
+
+%%
+exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); };
+%%
+]AT_YYLEX_DEFINE(["a"])[
+
+]AT_SKEL_CC_IF(
+[AT_YYERROR_DEFINE
+
+int
+yyparse (int x, int y)
+{
+ yy::parser parser(x, y);
+ return parser.parse ();
+}
+])[
+
+int
+main (void)
+{
+ return !!yyparse(1, 2);
+}
+]])
+
+AT_FULL_COMPILE([input])
+AT_CHECK([./input], 0, [[x: 1, y: 2
+]])
+AT_BISON_OPTION_POPDEFS
+
+AT_CLEANUP
+])
+
+## FIXME: test Java, and iterate over skeletons.
+AT_TEST("yacc.c")
+AT_TEST("glr.c")
+AT_TEST("lalr1.cc")
+AT_TEST("glr.cc")
+
+m4_popdef([AT_TEST])